/**
  * Lazy-loads config with values set from controller. Allows us to test config API.
  * @return Wikia\Search\Config
  */
 public function getConfig()
 {
     if ($this->config === null) {
         $this->config = new Wikia\Search\Config();
         $this->config->setLimit($this->getLimit())->setStart($this->getStart())->setNamespaces([NS_FILE])->setRank($this->getRank());
         $this->config->setFilterQueryByCode(Wikia\Search\Config::FILTER_VIDEO);
         if ($this->getSearchType() == 'premium') {
             $this->config->setWikiId(Wikia\Search\QueryService\Select\Dismax\Video::VIDEO_WIKI_ID);
         }
     }
     return $this->config;
 }
 /**
  * Called in WikiaSearchController and Oasis SearchController index action. 
  * Sets the SearchConfigs namespaces based on MW-core NS request style.
  * @see    WikiSearchControllerTest::testSetNamespacesFromRequest
  * @param  Wikia\Search\Config $searchConfig
  * @param  User $user
  * @return boolean true
  */
 protected function setNamespacesFromRequest($searchConfig, User $user)
 {
     $searchEngine = new SearchEngine();
     $searchableNamespaces = $searchEngine->searchableNamespaces();
     $namespaces = array();
     foreach ($searchableNamespaces as $i => $name) {
         if ($this->getVal('ns' . $i, false)) {
             $namespaces[] = $i;
         }
     }
     if (empty($namespaces)) {
         if ($user->getGlobalPreference('searchAllNamespaces')) {
             $namespaces = array_keys($searchableNamespaces);
         } else {
             $profiles = $searchConfig->getSearchProfiles();
             // this is mostly needed for unit testing
             $defaultProfile = !empty($this->wg->DefaultSearchProfile) ? $this->wg->DefaultSearchProfile : 'default';
             $namespaces = $profiles[$defaultProfile]['namespaces'];
         }
     }
     $searchConfig->setNamespaces($namespaces);
     return true;
 }
 /**
  * Handles accessing paginated results via AJAX.
  */
 public function getNextResults()
 {
     wfProfileIn(__METHOD__);
     $this->response->setVal('status', true);
     $query = urldecode($this->request->getVal('query', $this->request->getVal('search')));
     $page = $this->request->getVal('page', 1);
     $rank = $this->request->getVal('rank', 'default');
     $crossWikia = $this->request->getBool('crossWikia');
     $hub = false;
     $isCorporateWiki = !empty($this->wg->EnableWikiaHomePageExt);
     $isInterWiki = $crossWikia ? true : $isCorporateWiki;
     $cityId = $isInterWiki ? 0 : $this->wg->CityId;
     $resultsPerPage = $isInterWiki ? WikiaSearchController::INTERWIKI_RESULTS_PER_PAGE : WikiaSearchController::RESULTS_PER_PAGE;
     $resultsPerPage = empty($this->wg->SearchResultsPerPage) ? $resultsPerPage : $this->wg->SearchResultsPerPage;
     $params = array('page' => $page, 'limit' => $resultsPerPage, 'cityId' => $cityId, 'rank' => $rank, 'hub' => $hub);
     $config = new Wikia\Search\Config($params);
     $config->setInterWiki($isInterWiki)->setQuery($query);
     $results = (new QueryService\Factory())->getFromConfig($config)->search();
     $text = $this->app->getView('WikiaSearch', 'WikiaMobileResultList', array('currentPage' => $page, 'isInterWiki' => $isInterWiki, 'relevancyFunctionId' => 6, 'results' => $results, 'resultsPerPage' => $resultsPerPage, 'query' => $config->getQuery()->getQueryForHtml()))->render();
     $this->response->setVal('text', $text);
     $resultsFound = $config->getResultsFound();
     $this->response->setVal('counter', wfMessage('wikiamobile-wikiasearch2-count-of-results')->numParams($resultsPerPage * $page - $resultsPerPage + 1, $page == $config->getNumPages() ? $resultsFound : $resultsPerPage * $page, $resultsFound)->text());
     wfProfileOut(__METHOD__);
 }
 /**
  * Perform a search query against NS_MAIN given a term and total limit
  * @param string $term
  * @param int $limit
  */
 public function getResultSet($term, $totalLimit)
 {
     $wikiaSearchConfig = new Wikia\Search\Config();
     $wikiaSearchConfig->setNamespaces(array(NS_MAIN))->setQuery($term)->setLimit($totalLimit);
     $wikiaSearch = (new Wikia\Search\QueryService\Factory())->getFromConfig($wikiaSearchConfig);
     return $wikiaSearch->search($wikiaSearchConfig);
 }
 /**
  * Lazy-loads Wikia\Search\Config
  * @return Wikia\Search\Config
  */
 protected function getConfig()
 {
     if ($this->config === null) {
         $config = new Wikia\Search\Config();
         $config->setLimit(1);
         if ($this->getCrossWiki()) {
             $config->setCrossWikiLuceneQuery(true);
         } else {
             $config->setDirectLuceneQuery(true);
         }
         $this->config = $config;
     }
     return $this->config;
 }
Example #6
0
/**
 * Uses our search backend via the SimpleSearch module to find reasonable matches
 * for the search string. These aren't perfect at exact matches, etc. and is more
 * designed as a fallback to use when exact matches can't be found.
 *
 * @param searchString - the text string to search for using SimpleSearch.
 * @return an array of strings which are the textForm of the page title (eg: "Cake:Dime").
 */
function lw_getSearchResults($searchString, $maxResults = 25)
{
    global $wgCityId;
    $titles = array();
    try {
        $wikiaSearchConfig = new Wikia\Search\Config();
        $wikiaSearchConfig->setNamespaces(array(NS_MAIN))->setQuery($searchString)->setLimit($maxResults);
        $wikiaSearch = (new Wikia\Search\QueryService\Factory())->getFromConfig($wikiaSearchConfig);
        $resultSet = $wikiaSearch->search();
        $found = $resultSet->getResultsFound();
        if (!empty($found)) {
            foreach ($resultSet as $result) {
                $titles[] = $result->getTitle();
            }
        }
    } catch (WikiaException $e) {
        // TODO: Add logging of some sort.  For now, just return empty results and don't handle the error.
    }
    return $titles;
}
 /**
  * Sets the page title during index method.
  * @param Wikia\Search\Config $searchConfig
  */
 protected function setPageTitle(Wikia\Search\Config $searchConfig)
 {
     if ($searchConfig->getQuery()->hasTerms()) {
         $this->wg->Out->setPageTitle(wfMsg('wikiasearch2-page-title-with-query', array(ucwords($searchConfig->getQuery()->getSanitizedQuery()), $this->wg->Sitename)));
     } else {
         if ($searchConfig->getInterWiki()) {
             $this->wg->Out->setPageTitle(wfMsg('wikiasearch2-page-title-no-query-interwiki'));
         } else {
             $this->wg->Out->setPageTitle(wfMsg('wikiasearch2-page-title-no-query-intrawiki', array($this->wg->Sitename)));
         }
     }
 }
 /**
  * Configures and invokes search methods, returning the API-style response array
  * @return array
  */
 protected function getSearchResponse()
 {
     $config = new Wikia\Search\Config();
     $config->setDirectLuceneQuery(true)->setRequestedFields(['pageid', 'infoboxes_txt'])->setQuery(implode(' OR ', $this->getIdQueries()));
     return (new Wikia\Search\QueryService\Factory())->getFromConfig($config)->searchAsApi(['pageid', 'infoboxes_txt'], true);
 }