Пример #1
0
 /**
  * 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;
 }
Пример #2
0
 /**
  * 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);
 }
Пример #3
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;
}