/**
  * Delivers a JSON response with similar pages to a stream or URL.
  * @throws Exception
  */
 public function getSimilarPagesExternal()
 {
     $searchConfig = F::build('WikiaSearchConfig');
     $query = $this->getVal('q', null);
     $url = $this->getVal('url', null);
     $contents = $this->getVal('contents', null);
     if ($query !== null) {
         $searchConfig->setQuery($query);
     } else {
         if ($url !== null) {
             $searchConfig->setStreamUrl($url);
         } else {
             if ($contents !== null) {
                 $searchConfig->setStreamBody($contents);
             } else {
                 throw new Exception('Please provide a query, url or stream contents');
             }
         }
     }
     $this->response->setData($this->wikiaSearch->getSimilarPages($searchConfig));
     $this->response->setFormat('json');
 }