Passed
Pull Request — master (#5)
by Gordon
08:50
created

Indexer::index()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 8
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 11
rs 10
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->getFieldsToIndex($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
            $manticoreIndex = new \Manticoresearch\Index($client, $indexName);
24
            $manticoreIndex->replaceDocument($indexPayload, $dataObject->ID);
25
        }
26
    }
27
}
28