Indexer::index()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 11
c 0
b 0
f 0
nc 3
nop 1
dl 0
loc 20
rs 9.9
1
<?php declare(strict_types = 1);
2
3
/**
4
 * Created by PhpStorm.
5
 * User: gordon
6
 * Date: 24/3/2561
7
 * Time: 21:14 น.
8
 */
9
10
namespace Suilven\ManticoreSearch\Service;
11
12
class Indexer extends \Suilven\FreeTextSearch\Base\Indexer
13
{
14
    public function index(\SilverStripe\ORM\DataObject $dataObject): void
15
    {
16
        $payload = $this->getIndexablePayload($dataObject);
17
        $coreClient = new Client();
18
        $client = $coreClient->getConnection();
19
20
        $indexNames = \array_keys($payload);
21
        foreach ($indexNames as $indexName) {
22
            $indexPayload = $payload[$indexName];
23
24
            // skip empty payloads
25
            if ($indexPayload === []) {
26
                continue;
27
            }
28
29
            // @todo fix parent id indexing
30
            unset($indexPayload['ParentID']);
31
32
            $manticoreIndex = new \Manticoresearch\Index($client, $indexName);
33
            $manticoreIndex->replaceDocument($indexPayload, $dataObject->ID);
34
        }
35
    }
36
}
37