Suggester   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 16
c 2
b 0
f 0
dl 0
loc 32
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A suggest() 0 21 1
1
<?php declare(strict_types = 1);
2
3
/**
4
 * Created by PhpStorm.
5
 * User: gordon
6
 * Date: 25/3/2561
7
 * Time: 1:35 น.
8
 */
9
10
namespace Suilven\ManticoreSearch\Service;
11
12
use Suilven\FreeTextSearch\Container\SuggesterResults;
13
14
class Suggester extends \Suilven\FreeTextSearch\Base\Suggester implements \Suilven\FreeTextSearch\Interfaces\Suggester
15
{
16
    /** @var \Suilven\ManticoreSearch\Service\Client */
17
    private $client;
18
19
    public function __construct()
20
    {
21
        $this->client = new Client();
22
    }
23
24
25
    public function suggest(string $q, int $limit = 5): SuggesterResults
26
    {
27
        $params = [
28
            'index' => $this->index,
29
            'body' => [
30
                'query'=>$q,
31
                'options' => [
32
                    'limit' => $limit,
33
                ],
34
            ],
35
        ];
36
37
        $response = $this->client->getConnection()->suggest($params);
38
39
        $results = new SuggesterResults();
40
        $results->setResults(\array_keys($response));
41
        $results->setIndex($this->index);
42
        $results->setQuery($q);
43
        $results->setLimit($limit);
44
45
        return $results;
46
    }
47
}
48