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 SilverStripe\ORM\DataObject; |
||
13 | use Suilven\FreeTextSearch\Helper\IndexingHelper; |
||
14 | |||
15 | // @phpcs:disable SlevomatCodingStandard.Functions.UnusedParameter.UnusedParameter |
||
16 | class BulkIndexer implements \Suilven\FreeTextSearch\Interfaces\BulkIndexer |
||
17 | { |
||
18 | |||
19 | /** @var string */ |
||
20 | private static $indexName; |
||
21 | |||
22 | /** @var array<string, (string|int|float|bool)>|null */ |
||
23 | private static $payload = []; |
||
24 | |||
25 | |||
26 | public function addDataObject(DataObject $dataObject): void |
||
27 | { |
||
28 | $helper = new IndexingHelper(); |
||
29 | |||
30 | $payload = $helper->getFieldsToIndex($dataObject); |
||
31 | |||
32 | // as we are not indexing against a real free text search engine, add the ID into the payload for testing |
||
33 | $payload['ID'] = $dataObject->ID; |
||
34 | self::$payload[] = $payload; |
||
35 | } |
||
36 | |||
37 | |||
38 | public function indexDataObjects(): int |
||
39 | { |
||
40 | return \count(\array_keys(self::$payload)); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
41 | } |
||
42 | |||
43 | |||
44 | public function setIndex(string $newIndex): void |
||
45 | { |
||
46 | self::$indexName = $newIndex; |
||
47 | } |
||
48 | |||
49 | |||
50 | public static function getIndexName(): string |
||
51 | { |
||
52 | return self::$indexName; |
||
53 | } |
||
54 | |||
55 | |||
56 | /** @return array<string, (string|int|float|bool)>|null */ |
||
57 | public static function getIndexedPayload(): ?array |
||
58 | { |
||
59 | return self::$payload; |
||
60 | } |
||
61 | |||
62 | |||
63 | public static function resetIndexedPayload(): void |
||
64 | { |
||
65 | self::$payload = []; |
||
66 | } |
||
67 | } |
||
68 |