1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* FullTextSearch - Full text search framework for Nextcloud |
4
|
|
|
* |
5
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
6
|
|
|
* later. See the COPYING file. |
7
|
|
|
* |
8
|
|
|
* @author Maxence Lange <[email protected]> |
9
|
|
|
* @copyright 2018 |
10
|
|
|
* @license GNU AGPL version 3 or any later version |
11
|
|
|
* |
12
|
|
|
* This program is free software: you can redistribute it and/or modify |
13
|
|
|
* it under the terms of the GNU Affero General Public License as |
14
|
|
|
* published by the Free Software Foundation, either version 3 of the |
15
|
|
|
* License, or (at your option) any later version. |
16
|
|
|
* |
17
|
|
|
* This program is distributed in the hope that it will be useful, |
18
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
19
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
20
|
|
|
* GNU Affero General Public License for more details. |
21
|
|
|
* |
22
|
|
|
* You should have received a copy of the GNU Affero General Public License |
23
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
24
|
|
|
* |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
namespace OCA\FullTextSearch\Model; |
28
|
|
|
|
29
|
|
|
use OCA\FullTextSearch\IFullTextSearchPlatform; |
30
|
|
|
use OCA\FullTextSearch\IFullTextSearchProvider; |
31
|
|
|
|
32
|
|
|
class SearchResult implements \JsonSerializable { |
33
|
|
|
|
34
|
|
|
/** @var IndexDocument[] */ |
35
|
|
|
private $documents = []; |
36
|
|
|
|
37
|
|
|
/** @var string */ |
38
|
|
|
private $rawResult; |
39
|
|
|
|
40
|
|
|
/** @var IFullTextSearchProvider */ |
41
|
|
|
private $provider; |
42
|
|
|
|
43
|
|
|
/** @var IFullTextSearchPlatform */ |
44
|
|
|
private $platform; |
45
|
|
|
|
46
|
|
|
/** @var int */ |
47
|
|
|
private $total; |
48
|
|
|
|
49
|
|
|
/** @var int */ |
50
|
|
|
private $maxScore; |
51
|
|
|
|
52
|
|
|
/** @var int */ |
53
|
|
|
private $time; |
54
|
|
|
|
55
|
|
|
/** @var boolean */ |
56
|
|
|
private $timedOut; |
57
|
|
|
|
58
|
|
|
/** @var SearchRequest */ |
59
|
|
|
private $request; |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
public function __construct() { |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param IndexDocument[] $documents |
68
|
|
|
* |
69
|
|
|
* @return $this |
70
|
|
|
*/ |
71
|
|
|
public function setDocuments($documents) { |
72
|
|
|
$this->documents = $documents; |
73
|
|
|
|
74
|
|
|
return $this; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return IndexDocument[] |
79
|
|
|
*/ |
80
|
|
|
public function getDocuments() { |
81
|
|
|
return $this->documents; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param IndexDocument $document |
86
|
|
|
* |
87
|
|
|
* @return $this |
88
|
|
|
*/ |
89
|
|
|
public function addDocument(IndexDocument $document) { |
90
|
|
|
$this->documents[] = $document; |
91
|
|
|
|
92
|
|
|
return $this; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return int |
97
|
|
|
*/ |
98
|
|
|
public function getCount() { |
99
|
|
|
return count($this->documents); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @param string $result |
105
|
|
|
*/ |
106
|
|
|
public function setRawResult($result) { |
107
|
|
|
$this->rawResult = $result; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @return string |
112
|
|
|
*/ |
113
|
|
|
public function getRawResult() { |
114
|
|
|
return $this->rawResult; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @param IFullTextSearchProvider $provider |
120
|
|
|
*/ |
121
|
|
|
public function setProvider(IFullTextSearchProvider $provider) { |
122
|
|
|
$this->provider = $provider; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @return IFullTextSearchProvider |
127
|
|
|
*/ |
128
|
|
|
public function getProvider() { |
129
|
|
|
return $this->provider; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @return IFullTextSearchPlatform |
135
|
|
|
*/ |
136
|
|
|
public function getPlatform() { |
137
|
|
|
return $this->platform; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @param IFullTextSearchPlatform $platform |
142
|
|
|
*/ |
143
|
|
|
public function setPlatform($platform) { |
144
|
|
|
$this->platform = $platform; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @return int |
150
|
|
|
*/ |
151
|
|
|
public function getTotal() { |
152
|
|
|
return $this->total; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @param int $total |
157
|
|
|
*/ |
158
|
|
|
public function setTotal($total) { |
159
|
|
|
$this->total = $total; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @return int |
165
|
|
|
*/ |
166
|
|
|
public function getMaxScore() { |
167
|
|
|
return $this->maxScore; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @param int $maxScore |
172
|
|
|
*/ |
173
|
|
|
public function setMaxScore($maxScore) { |
174
|
|
|
$this->maxScore = $maxScore; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @return int |
180
|
|
|
*/ |
181
|
|
|
public function getTime() { |
182
|
|
|
return $this->time; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @param int $time |
187
|
|
|
*/ |
188
|
|
|
public function setTime($time) { |
189
|
|
|
$this->time = $time; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* @return bool |
195
|
|
|
*/ |
196
|
|
|
public function isTimedOut() { |
197
|
|
|
return $this->timedOut; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @param bool $timedOut |
202
|
|
|
*/ |
203
|
|
|
public function setTimedOut($timedOut) { |
204
|
|
|
$this->timedOut = $timedOut; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* @return SearchRequest |
210
|
|
|
*/ |
211
|
|
|
public function getRequest() { |
212
|
|
|
return $this->request; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @param SearchRequest $request |
217
|
|
|
*/ |
218
|
|
|
public function setRequest($request) { |
219
|
|
|
$this->request = $request; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* @return array<string,array<string,string>|IndexDocument[]|integer> |
|
|
|
|
225
|
|
|
*/ |
226
|
|
|
public function jsonSerialize() { |
227
|
|
|
|
228
|
|
|
$provider = $this->getProvider(); |
229
|
|
|
$platform = $this->getPlatform(); |
230
|
|
|
|
231
|
|
|
return [ |
232
|
|
|
'provider' => [ |
233
|
|
|
'id' => $provider->getId(), |
234
|
|
|
'name' => $provider->getName(), |
235
|
|
|
'version' => $provider->getVersion() |
236
|
|
|
], |
237
|
|
|
'platform' => [ |
238
|
|
|
'id' => $platform->getId(), |
239
|
|
|
'name' => $platform->getName(), |
240
|
|
|
'version' => $platform->getVersion() |
241
|
|
|
], |
242
|
|
|
'documents' => $this->getDocuments(), |
243
|
|
|
'meta' => |
244
|
|
|
[ |
245
|
|
|
'timedOut' => $this->isTimedOut(), |
246
|
|
|
'time' => $this->getTime(), |
247
|
|
|
'count' => $this->getCount(), |
248
|
|
|
'total' => $this->getTotal(), |
249
|
|
|
'maxScore' => $this->getMaxScore() |
250
|
|
|
] |
251
|
|
|
]; |
252
|
|
|
} |
253
|
|
|
} |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.