Esempio n. 1
0
 public function execute()
 {
     $params = $this->extractRequestParams();
     $search = $params['search'];
     $limit = $params['limit'];
     $namespaces = $params['namespace'];
     $suggest = $params['suggest'];
     // Some script that was loaded regardless of wgEnableOpenSearchSuggest, likely cached.
     if ($suggest && !$this->getConfig()->get('EnableOpenSearchSuggest')) {
         $searches = array();
     } else {
         // Open search results may be stored for a very long time
         $this->getMain()->setCacheMaxAge($this->getConfig()->get('SearchSuggestCacheExpiry'));
         $this->getMain()->setCacheMode('public');
         $searcher = new StringPrefixSearch();
         $searches = $searcher->searchWithVariants($search, $limit, $namespaces);
     }
     // Set top level elements
     $result = $this->getResult();
     $result->addValue(null, 0, $search);
     $result->addValue(null, 1, $searches);
 }
 /**
  * Return an array of subpages beginning with $search that this special page will accept.
  *
  * @param string $search Prefix to search for
  * @param int $limit Maximum number of results to return (usually 10)
  * @param int $offset Number of results to skip (usually 0)
  * @return string[] Matching subpages
  */
 public function prefixSearchSubpages($search, $limit, $offset)
 {
     $title = Title::newFromText($search);
     if (!$title || !$title->canExist()) {
         // No prefix suggestion in special and media namespace
         return array();
     }
     // Autocomplete subpage the same as a normal search
     $prefixSearcher = new StringPrefixSearch();
     $result = $prefixSearcher->search($search, $limit, array(), $offset);
     return $result;
 }
Esempio n. 3
0
 /**
  * Do a prefix search of titles and return a list of matching page names.
  * @deprecated Since 1.23, use TitlePrefixSearch or StringPrefixSearch classes
  *
  * @param string $search
  * @param int $limit
  * @param array $namespaces Used if query is not explicitly prefixed
  * @param int $offset How many results to offset from the beginning
  * @return array Array of strings
  */
 public static function titleSearch($search, $limit, $namespaces = array(), $offset = 0)
 {
     $prefixSearch = new StringPrefixSearch();
     return $prefixSearch->search($search, $limit, $namespaces, $offset);
 }
 /**
  * Return an array of subpages beginning with $search that this special page will accept.
  *
  * @param string $search Prefix to search for
  * @param int $limit Maximum number of results to return (usually 10)
  * @param int $offset Number of results to skip (usually 0)
  * @return string[] Matching subpages
  */
 public function prefixSearchSubpages($search, $limit, $offset)
 {
     if ($search === '') {
         return array();
     }
     // Autocomplete subpage the same as a normal search
     $prefixSearcher = new StringPrefixSearch();
     $result = $prefixSearcher->search($search, $limit, array(), $offset);
     return $result;
 }
Esempio n. 5
0
 /**
  * Do a prefix search of titles and return a list of matching page names.
  * @deprecated: Since 1.23, use TitlePrefixSearch or StringPrefixSearch classes
  *
  * @param $search String
  * @param $limit Integer
  * @param array $namespaces used if query is not explicitly prefixed
  * @return Array of strings
  */
 public static function titleSearch($search, $limit, $namespaces = array())
 {
     $search = new StringPrefixSearch();
     return $search->search($search, $limit, $namespaces);
 }
 /**
  * @dataProvider provideSearchBackend
  * @covers PrefixSearch::searchBackend
  */
 public function testSearchBackend(array $case)
 {
     $this->searchProvision($case['provision']);
     $searcher = new StringPrefixSearch();
     $results = $searcher->search($case['query'], 3);
     $this->assertEquals($case['results'], $results, $case[0]);
 }