コード例 #1
0
 public function testShrink()
 {
     $set = SearchSuggestionSet::emptySuggestionSet();
     for ($i = 0; $i < 100; $i++) {
         $set->append(new SearchSuggestion(0));
     }
     $set->shrink(10);
     $this->assertEquals(10, $set->getSize());
     $set->shrink(0);
     $this->assertEquals(0, $set->getSize());
 }
コード例 #2
0
ファイル: SearchEngine.php プロジェクト: paladox/mediawiki
 /**
  * Perform a completion search with variants.
  * @param string $search
  * @return SearchSuggestionSet
  */
 public function completionSearchWithVariants($search)
 {
     if (trim($search) === '') {
         return SearchSuggestionSet::emptySuggestionSet();
         // Return empty result
     }
     $search = $this->normalizeNamespaces($search);
     $results = $this->completionSearchBackend($search);
     $fallbackLimit = $this->limit - $results->getSize();
     if ($fallbackLimit > 0) {
         global $wgContLang;
         $fallbackSearches = $wgContLang->autoConvertToAllVariants($search);
         $fallbackSearches = array_diff(array_unique($fallbackSearches), [$search]);
         foreach ($fallbackSearches as $fbs) {
             $this->setLimitOffset($fallbackLimit);
             $fallbackSearchResult = $this->completionSearch($fbs);
             $results->appendAll($fallbackSearchResult);
             $fallbackLimit -= count($fallbackSearchResult);
             if ($fallbackLimit <= 0) {
                 break;
             }
         }
     }
     return $this->processCompletionResults($search, $results);
 }