Suggester::suggest()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 13
c 2
b 0
f 0
nc 1
nop 2
dl 0
loc 21
rs 9.8333
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