/** * @dataProvider provideSearchBackend * @covers PrefixSearch::searchBackend */ public function testSearchBackend(array $case) { $search = $stub = $this->getMockBuilder('SearchEngine')->setMethods(['completionSearchBackend'])->getMock(); $return = SearchSuggestionSet::fromStrings($case['provision']); $search->expects($this->any())->method('completionSearchBackend')->will($this->returnValue($return)); $search->setLimitOffset(3); $results = $search->completionSearch($case['query']); $results = $results->map(function (SearchSuggestion $s) { return $s->getText(); }); $this->assertEquals($case['results'], $results, $case[0]); }
/** * Perform a completion search. * Does not resolve namespaces and does not check variants. * Search engine implementations may want to override this function. * @param string $search * @return SearchSuggestionSet */ protected function completionSearchBackend($search) { $results = []; $search = trim($search); if (!in_array(NS_SPECIAL, $this->namespaces) && !Hooks::run('PrefixSearchBackend', [$this->namespaces, $search, $this->limit, &$results, $this->offset])) { // False means hook worked. // FIXME: Yes, the API is weird. That's why it is going to be deprecated. return SearchSuggestionSet::fromStrings($results); } else { // Hook did not do the job, use default simple search $results = $this->simplePrefixSearch($search); return SearchSuggestionSet::fromTitles($results); } }