gordonbanderson /
freetextsearch
| 1 | <?php declare(strict_types = 1); |
||
| 2 | |||
| 3 | /** |
||
| 4 | * Created by PhpStorm. |
||
| 5 | * User: gordon |
||
| 6 | * Date: 24/3/2561 |
||
| 7 | * Time: 20:36 น. |
||
| 8 | */ |
||
| 9 | |||
| 10 | namespace Suilven\FreeTextSearch\Tests\Mock; |
||
| 11 | |||
| 12 | use Suilven\FreeTextSearch\Container\SuggesterResults; |
||
| 13 | |||
| 14 | class Suggester extends \Suilven\FreeTextSearch\Base\Suggester implements \Suilven\FreeTextSearch\Interfaces\Suggester |
||
| 15 | { |
||
| 16 | /** @return array<string> */ |
||
| 17 | public function suggest(string $q, int $limit = 5): SuggesterResults |
||
| 18 | { |
||
| 19 | $result = new SuggesterResults(); |
||
| 20 | switch ($q) { |
||
| 21 | case 'webmister': |
||
| 22 | $result->setResults(['webmaster']); |
||
| 23 | |||
| 24 | break; |
||
| 25 | } |
||
| 26 | |||
| 27 | $suggestions = $result->getResults(); |
||
| 28 | if (\sizeof($suggestions) > $limit) { |
||
| 29 | $suggestions = \array_slice($result, 0, $limit); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 30 | $result->setResults($suggestions); |
||
| 31 | } |
||
| 32 | |||
| 33 | $result->setQuery($q); |
||
| 34 | $result->setLimit($limit); |
||
| 35 | $result->setIndex('unit_test_index'); |
||
| 36 | |||
| 37 | return $result; |
||
|
0 ignored issues
–
show
|
|||
| 38 | } |
||
| 39 | } |
||
| 40 |