/**
  * Subroutine for optionally prepending article match to result array. 
  * @return WikiaSearchResultSet provides fluent interface
  */
 public function prependArticleMatchIfExists()
 {
     wfProfileIn(__METHOD__);
     if (!($this->searchConfig->hasArticleMatch() && $this->resultsStart == 0)) {
         return $this;
     }
     $articleMatch = $this->searchConfig->getArticleMatch();
     $article = $articleMatch->getCanonicalArticle();
     $title = $article->getTitle();
     $articleId = $article->getID();
     if (!in_array($title->getNamespace(), $this->searchConfig->getNamespaces())) {
         // we had an article match by name, but not in our desired namespaces
         return $this;
     }
     $articleMatchId = sprintf('%s_%s', $this->wg->CityId, $articleId);
     $articleService = F::build('ArticleService', array($articleId));
     $firstRev = $title->getFirstRevision();
     $created = $firstRev ? wfTimestamp(TS_ISO_8601, $firstRev->getTimestamp()) : '';
     $lastRev = Revision::newFromId($title->getLatestRevID());
     $touched = $lastRev ? wfTimeStamp(TS_ISO_8601, $lastRev->getTimestamp()) : '';
     $fieldsArray = array('wid' => $this->wg->CityId, 'title' => $article->mTitle, 'url' => urldecode($title->getFullUrl()), 'score' => 'PTT', 'isArticleMatch' => true, 'ns' => $title->getNamespace(), 'pageId' => $article->getID(), 'created' => $created, 'touched' => $touched);
     //@TODO: we could put categories ^^ here but we aren't really using them yet
     $result = F::build('WikiaSearchResult', array($fieldsArray));
     $snippet = $articleService->getTextSnippet(250);
     $result->setText($snippet);
     if ($articleMatch->hasRedirect()) {
         $result->setVar('redirectTitle', $articleMatch->getArticle()->getTitle());
     }
     $result->setVar('id', $articleMatchId);
     $this->addResult($result);
     $this->resultsFound++;
     wfProfileOut(__METHOD__);
     return $this;
 }
 /**
  * Called in index action. Sets the SearchConfigs namespaces based on MW-core NS request style.
  * @see    WikiSearchControllerTest::testSetNamespacesFromRequest
  * @param  WikiaSearchConfig $searchConfig
  * @return boolean true
  */
 private function setNamespacesFromRequest(WikiaSearchConfig $searchConfig, User $user)
 {
     $searchEngine = F::build('SearchEngine');
     $searchableNamespaces = $searchEngine->searchableNamespaces();
     $namespaces = array();
     foreach ($searchableNamespaces as $i => $name) {
         if ($this->getVal('ns' . $i, false)) {
             $namespaces[] = $i;
         }
     }
     if (empty($namespaces) && $user->getOption('searchAllNamespaces')) {
         $namespaces = array_keys($searchableNamespaces);
     }
     $searchConfig->setNamespaces($namespaces);
     return true;
 }
 /**
  * Utilizes Solr's MoreLikeThis component to return similar pages
  * @see    WikiaSearchTest::testMoreLikeThis
  * @param  WikiaSearchConfig $searchConfig
  * @return WikiaSearchResultSet
  */
 private function moreLikeThis(WikiaSearchConfig $searchConfig)
 {
     $query = $searchConfig->getQuery(WikiaSearchConfig::QUERY_RAW);
     $streamBody = $searchConfig->getStreamBody();
     $streamUrl = $searchConfig->getStreamUrl();
     if (!($query || $streamBody || $streamUrl)) {
         throw new Exception("A query, url, or stream is required.");
     }
     $mlt = $this->client->createMoreLikeThis();
     $mlt->setMltFields(implode(',', $searchConfig->getMltFields()))->setFields($searchConfig->getRequestedFields())->addParam('mlt.match.include', 'false')->setStart($searchConfig->getStart())->setRows($searchConfig->getRows())->setDocumentClass('WikiaSearchResult');
     if ($searchConfig->getInterestingTerms() == 'list') {
         $mlt->setInterestingTerms('list');
     }
     if ($searchConfig->getMltFilterQuery()) {
         $mlt->addFilterQuery(array('query' => $searchConfig->getMltFilterQuery(), 'key' => 'mltfilterquery'));
     }
     if ($query !== null) {
         $mlt->setQuery($query);
     } else {
         if ($streamBody) {
             $mlt->addParam('stream.body', $streamBody);
         } else {
             if ($streamUrl) {
                 $mlt->addParam('stream.url', $streamUrl);
             }
         }
     }
     try {
         $mltResult = $this->client->moreLikeThis($mlt);
     } catch (Exception $e) {
         $mltResult = F::build('Solarium_Result_Select_Empty');
         Wikia::Log(__METHOD__, '', $e);
     }
     $results = F::build('WikiaSearchResultSet', array($mltResult, $searchConfig));
     return $results;
 }