Completed
Push — master ( ec539d...346131 )
by Adrian
02:33 queued 11s
created

Index::status()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 6
rs 10
1
<?php
2
3
4
namespace Manticoresearch;
5
6
7
class Index
8
{
9
    protected $_client;
10
    protected $_index;
11
12
    public function __construct(Client $client, $index = null)
13
    {
14
        $this->_client = $client;
15
16
        $this->_index = $index;
17
    }
18
19
    public function search($string, $fields = null): Search
20
    {
21
        $search = new Search($this->_client);
22
        $search->setIndex($this->_index);
23
        return $search->search($string, $fields);
0 ignored issues
show
Unused Code introduced by
The call to Manticoresearch\Search::search() has too many arguments starting with $fields. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

23
        return $search->/** @scrutinizer ignore-call */ search($string, $fields);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
24
    }
25
26
    public function getDocumentById($id)
27
    {
28
        $params = [
29
            'body' => [
30
                'index' => $this->_index,
31
                'query' => [
32
                    'equals' => ['id' => $id]
33
                ]
34
            ]
35
        ];
36
        return $this->_client->search($params);
37
    }
38
39
    public function addDocument($data, $id = null)
40
    {
41
        $params = [
42
            'body' => [
43
                'index' => $this->_index,
44
                'id' => $id,
45
                'doc' => $data
46
            ]
47
        ];
48
        return $this->_client->insert($params);
49
    }
50
51
    public function deleteDocument($id)
52
    {
53
        $params = [
54
            'body' => [
55
                'index' => $this->_index,
56
                'id' => $id
57
            ]
58
        ];
59
        return $this->_client->delete($params);
60
    }
61
62
    public function deleteDocuments($query)
63
    {
64
        $params = [
65
            'body' => [
66
                'index' => $this->_index,
67
                'query' => $query
68
            ]
69
        ];
70
        return $this->_client->delete($params);
71
    }
72
73
    public function updateDocument($data, $id)
74
    {
75
        $params = [
76
            'body' => [
77
                'index' => $this->_index,
78
                'id' => $id,
79
                'doc' => $data
80
            ]
81
        ];
82
        return $this->_client->update($params);
83
    }
84
85
    public function updateDocuments($data, $query)
86
    {
87
        $params = [
88
            'body' => [
89
                'index' => $this->_index,
90
                'query' => $query,
91
                'doc' => $data
92
            ]
93
        ];
94
        return $this->_client->update($params);
95
    }
96
97
    public function replaceDocument($data, $id)
98
    {
99
        $params = [
100
            'body' => [
101
                'index' => $this->_index,
102
                'id' => $id,
103
                'doc' => $data
104
            ]
105
        ];
106
        return $this->_client->replace($params);
107
    }
108
109
    public function create($fields, $settings)
110
    {
111
        $params = [
112
            'index' => $this->_index,
113
            'body' => [
114
                'columns' => $fields,
115
                'settings' => $settings
116
            ]
117
        ];
118
        return $this->_client->indices()->create($params);
119
    }
120
121
    public function drop($silent=false)
122
    {
123
        $params = [
124
            'index' => $this->_index,
125
        ];
126
        if($silent===true) {
127
            $params['body'] = ['silent'=>true];
128
        }
129
        return $this->_client->indices()->drop($params);
130
    }
131
    public function describe()
132
    {
133
        $params = [
134
            'index' => $this->_index,
135
        ];
136
        return $this->_client->indices()->describe($params);
137
    }
138
    public function status()
139
    {
140
        $params = [
141
            'index' => $this->_index,
142
        ];
143
        return $this->_client->indices()->status($params);
144
    }
145
    public function truncate()
146
    {
147
        $params = [
148
            'index' => $this->_index,
149
        ];
150
        return $this->_client->indices()->truncate($params);
151
    }
152
    public function getClient():Client
153
    {
154
        return $this->_client;
155
    }
156
157
    public function getName():string
158
    {
159
        return $this->_index;
160
    }
161
162
    public function setName($index):self
163
    {
164
        $this->_index = $index;
165
        return $this;
166
    }
167
}