Indexer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 22
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A index() 0 20 3
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