Suggest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 2
Metric Value
eloc 14
c 2
b 1
f 2
dl 0
loc 33
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getIndex() 0 3 1
A setIndex() 0 3 1
A setBody() 0 14 4
1
<?php
2
3
4
namespace Manticoresearch\Endpoints;
5
6
use Manticoresearch\Exceptions\RuntimeException;
7
use Manticoresearch\Utils;
8
9
class Suggest extends EmulateBySql
10
{
11
    use Utils;
12
    protected $index;
13
    public function setBody($params = null)
14
    {
15
        if (isset($this->index)) {
16
            $binds =[];
17
            $binds[] = "'" . static::escape($params['query']) . "'";
18
            $binds[] = "'" . $this->index . "'";
19
            if (count($params['options']) > 0) {
20
                foreach ($params['options'] as $name => $value) {
21
                    $binds[] = "$value AS $name";
22
                }
23
            }
24
            return parent::setBody(['query' => "CALL SUGGEST(" . implode(",", $binds) . ")"]);
25
        }
26
        throw new RuntimeException('Index name is missing.');
27
    }
28
    /**
29
     * @return mixed
30
     */
31
    public function getIndex()
32
    {
33
        return $this->index;
34
    }
35
36
    /**
37
     * @param mixed $index
38
     */
39
    public function setIndex($index)
40
    {
41
        $this->index = $index;
42
    }
43
}
44