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 | // @phpcs:disable SlevomatCodingStandard.Functions.UnusedParameter.UnusedParameter |
||
13 | |||
14 | use SilverStripe\ORM\ArrayList; |
||
15 | use SilverStripe\ORM\DataObject; |
||
16 | use Suilven\FreeTextSearch\Container\SearchResults; |
||
17 | |||
18 | class Searcher extends \Suilven\FreeTextSearch\Base\Searcher |
||
19 | { |
||
20 | /** @return array<string,array<string,string>> */ |
||
21 | public function search(?string $q): SearchResults |
||
22 | { |
||
23 | $result = new SearchResults(); |
||
24 | switch ($q) { |
||
25 | case 'Fish': |
||
26 | $records = [ |
||
27 | [ |
||
28 | 'Title' => 'Fishing in New Zealand', |
||
29 | ], |
||
30 | ]; |
||
31 | $recordsList = new ArrayList($records); |
||
32 | $result->setRecords($recordsList); |
||
33 | |||
34 | $result->setTime(0.017); |
||
35 | |||
36 | $result->setPageSize(10); |
||
37 | $result->setPage(1); |
||
38 | |||
39 | $result->setIndex('unit_test_index'); |
||
40 | $result->setSuggestions(['fush']); |
||
41 | |||
42 | |||
43 | $highlights = ['Title' => [ |
||
44 | '<b>Fish</b>ing in New Zealand', |
||
45 | ], |
||
46 | ]; |
||
47 | |||
48 | $result->Highlights = $highlights; |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
49 | } |
||
50 | |||
51 | return $result; |
||
0 ignored issues
–
show
|
|||
52 | } |
||
53 | |||
54 | |||
55 | /** @param \SilverStripe\ORM\DataObject $dataObject a dataObject relevant to the index */ |
||
56 | public function searchForSimilar(DataObject $dataObject): SearchResults |
||
57 | { |
||
58 | return $this->search('Fish'); |
||
59 | } |
||
60 | } |
||
61 |