|
1
|
|
|
<?php |
|
2
|
|
|
namespace ApacheSolrForTypo3\Solr\Domain\Search\Query; |
|
3
|
|
|
|
|
4
|
|
|
/*************************************************************** |
|
5
|
|
|
* Copyright notice |
|
6
|
|
|
* |
|
7
|
|
|
* (c) 2009-2015 Ingo Renner <[email protected]> |
|
8
|
|
|
* All rights reserved |
|
9
|
|
|
* |
|
10
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
|
11
|
|
|
* free software; you can redistribute it and/or modify |
|
12
|
|
|
* it under the terms of the GNU General Public License as published by |
|
13
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
|
14
|
|
|
* (at your option) any later version. |
|
15
|
|
|
* |
|
16
|
|
|
* The GNU General Public License can be found at |
|
17
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
|
18
|
|
|
* |
|
19
|
|
|
* This script is distributed in the hope that it will be useful, |
|
20
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
21
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
22
|
|
|
* GNU General Public License for more details. |
|
23
|
|
|
* |
|
24
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
|
25
|
|
|
***************************************************************/ |
|
26
|
|
|
|
|
27
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\Query\Helper\Pagination; |
|
28
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\Query\Helper\QueryStringContainer; |
|
29
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\Query\ParameterBuilder\BigramPhraseFields; |
|
30
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\Query\ParameterBuilder\Debug; |
|
31
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\Query\ParameterBuilder\Elevation; |
|
32
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\Query\ParameterBuilder\Faceting; |
|
33
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\Query\ParameterBuilder\FieldCollapsing; |
|
34
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\Query\ParameterBuilder\Filters; |
|
35
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\Query\ParameterBuilder\Grouping; |
|
36
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\Query\ParameterBuilder\Highlighting; |
|
37
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\Query\ParameterBuilder\Operator; |
|
38
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\Query\ParameterBuilder\PhraseFields; |
|
39
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\Query\ParameterBuilder\QueryFields; |
|
40
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\Query\ParameterBuilder\ReturnFields; |
|
41
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\Query\ParameterBuilder\Slops; |
|
42
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\Query\ParameterBuilder\Sorting; |
|
43
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\Query\ParameterBuilder\Spellchecking; |
|
44
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\Query\ParameterBuilder\TrigramPhraseFields; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* A Solr search query |
|
48
|
|
|
* |
|
49
|
|
|
* @author Ingo Renner <[email protected]> |
|
50
|
|
|
* @author Timo Hund <[email protected]> |
|
51
|
|
|
*/ |
|
52
|
|
|
class Query |
|
53
|
|
|
{ |
|
54
|
|
|
/** |
|
55
|
|
|
* @var QueryStringContainer |
|
56
|
|
|
*/ |
|
57
|
|
|
protected $queryStringContainer = null; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @var Pagination |
|
61
|
|
|
*/ |
|
62
|
|
|
protected $pagination = null; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @var Operator |
|
66
|
|
|
*/ |
|
67
|
|
|
protected $operator = null; |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* ParameterBuilder for filters. |
|
71
|
|
|
* |
|
72
|
|
|
* @var Filters |
|
73
|
|
|
*/ |
|
74
|
|
|
protected $filters = null; |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Holds the query fields with their associated boosts. The key represents |
|
78
|
|
|
* the field name, value represents the field's boost. These are the fields |
|
79
|
|
|
* that will actually be searched. |
|
80
|
|
|
* |
|
81
|
|
|
* Used in Solr's qf parameter |
|
82
|
|
|
* |
|
83
|
|
|
* @var QueryFields |
|
84
|
|
|
* @see http://wiki.apache.org/solr/DisMaxQParserPlugin#qf_.28Query_Fields.29 |
|
85
|
|
|
*/ |
|
86
|
|
|
protected $queryFields = null; |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Holds the phrase fields with their associated boosts. The key represents |
|
90
|
|
|
* the field name, value represents the field's boost. These are the fields |
|
91
|
|
|
* for those Apache Solr should build phrase quieries and by phrase occurrences should be boosted. |
|
92
|
|
|
* |
|
93
|
|
|
* @var PhraseFields |
|
94
|
|
|
* @see https://lucene.apache.org/solr/guide/7_0/the-dismax-query-parser.html#pf-phrase-fields-parameter |
|
95
|
|
|
*/ |
|
96
|
|
|
protected $phraseFields; |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Holds the bigram phrase fields with their associated boosts. The key represents |
|
100
|
|
|
* the field name, value represents the field's boost. These are the fields |
|
101
|
|
|
* for those Apache Solr should build the phrases from triplets and sentences. |
|
102
|
|
|
* |
|
103
|
|
|
* @var BigramPhraseFields |
|
104
|
|
|
* @see "pf2" https://lucene.apache.org/solr/guide/7_0/the-extended-dismax-query-parser.html#extended-dismax-parameters |
|
105
|
|
|
*/ |
|
106
|
|
|
protected $bigramPhraseFields; |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Holds the trigram phrase fields with their associated boosts. The key represents |
|
110
|
|
|
* the field name, value represents the field's boost. These are the fields |
|
111
|
|
|
* for those Apache Solr should build the phrases from triplets and sentences. |
|
112
|
|
|
* |
|
113
|
|
|
* @var TrigramPhraseFields |
|
114
|
|
|
* @see "pf3" https://lucene.apache.org/solr/guide/7_0/the-extended-dismax-query-parser.html#extended-dismax-parameters |
|
115
|
|
|
*/ |
|
116
|
|
|
protected $trigramPhraseFields; |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* List of fields that will be returned in the result documents. |
|
120
|
|
|
* |
|
121
|
|
|
* used in Solr's fl parameter |
|
122
|
|
|
* |
|
123
|
|
|
* @var ReturnFields |
|
124
|
|
|
* @see http://wiki.apache.org/solr/CommonQueryParameters#fl |
|
125
|
|
|
*/ |
|
126
|
|
|
protected $returnFields = null; |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* ParameterBuilder for the highlighting. |
|
130
|
|
|
* |
|
131
|
|
|
* @var Highlighting |
|
132
|
|
|
*/ |
|
133
|
|
|
protected $highlighting = null; |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* ParameterBuilder for the faceting. |
|
137
|
|
|
* |
|
138
|
|
|
* @var Faceting |
|
139
|
|
|
*/ |
|
140
|
|
|
protected $faceting = null; |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* ParameterBuilder for the spellchecking |
|
144
|
|
|
* |
|
145
|
|
|
* @var Spellchecking |
|
146
|
|
|
*/ |
|
147
|
|
|
protected $spellchecking = null; |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* ParameterBuilder for the grouping. |
|
151
|
|
|
* |
|
152
|
|
|
* @var Grouping |
|
153
|
|
|
*/ |
|
154
|
|
|
protected $grouping = null; |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* ParameterBuilder for the field collapsing (variants) |
|
158
|
|
|
* |
|
159
|
|
|
* @var FieldCollapsing |
|
160
|
|
|
*/ |
|
161
|
|
|
protected $fieldCollapsing = null; |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* ParameterBuilder for the debugging. |
|
165
|
|
|
* |
|
166
|
|
|
* @var Debug |
|
167
|
|
|
*/ |
|
168
|
|
|
protected $debug = null; |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* ParameterBuilder for the sorting |
|
172
|
|
|
* |
|
173
|
|
|
* @var Sorting |
|
174
|
|
|
*/ |
|
175
|
|
|
protected $sorting = null; |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* ParameterBuilder for the slops (qs,ps,ps2,ps3) |
|
179
|
|
|
* |
|
180
|
|
|
* @var Slops |
|
181
|
|
|
*/ |
|
182
|
|
|
protected $slops = null; |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* ParameterBuilder for the elevation |
|
186
|
|
|
* |
|
187
|
|
|
* @var Elevation |
|
188
|
|
|
*/ |
|
189
|
|
|
protected $elevation = null; |
|
190
|
|
|
|
|
191
|
|
|
/** |
|
192
|
|
|
* @var QueryParametersContainer |
|
193
|
|
|
*/ |
|
194
|
|
|
protected $queryParametersContainer = null; |
|
195
|
|
|
|
|
196
|
|
|
/** |
|
197
|
|
|
* Query constructor. |
|
198
|
|
|
* @param string $keywords |
|
199
|
|
|
*/ |
|
200
|
177 |
|
public function __construct($keywords) |
|
201
|
|
|
{ |
|
202
|
177 |
|
$this->queryStringContainer = new QueryStringContainer((string)$keywords); |
|
203
|
177 |
|
$this->pagination = new Pagination(); |
|
204
|
177 |
|
$this->filters = new Filters(); |
|
205
|
177 |
|
$this->queryFields = QueryFields::fromString('*'); |
|
206
|
177 |
|
$this->returnFields = ReturnFields::fromArray(['*', 'score']); |
|
207
|
|
|
|
|
208
|
177 |
|
$this->faceting = new Faceting(false); |
|
209
|
177 |
|
$this->grouping = new Grouping(false); |
|
210
|
177 |
|
$this->highlighting = new Highlighting(false); |
|
211
|
177 |
|
$this->bigramPhraseFields = new BigramPhraseFields(false); |
|
212
|
177 |
|
$this->trigramPhraseFields = new TrigramPhraseFields(false); |
|
213
|
177 |
|
$this->phraseFields = new PhraseFields(false); |
|
214
|
177 |
|
$this->spellchecking = new Spellchecking(false); |
|
215
|
177 |
|
$this->debug = new Debug(false); |
|
216
|
177 |
|
$this->sorting = new Sorting(false); |
|
217
|
177 |
|
$this->fieldCollapsing = new FieldCollapsing(false); |
|
218
|
177 |
|
$this->elevation = new Elevation(false); |
|
219
|
177 |
|
$this->operator = new Operator(false); |
|
220
|
177 |
|
$this->slops = new Slops(); |
|
221
|
|
|
|
|
222
|
177 |
|
$this->queryParametersContainer = new QueryParametersContainer(); |
|
223
|
177 |
|
} |
|
224
|
|
|
|
|
225
|
|
|
/** |
|
226
|
|
|
* @param QueryFields $queryFields |
|
227
|
|
|
*/ |
|
228
|
151 |
|
public function setQueryFields(QueryFields $queryFields) |
|
229
|
|
|
{ |
|
230
|
151 |
|
$this->queryFields = $queryFields; |
|
231
|
151 |
|
} |
|
232
|
|
|
|
|
233
|
|
|
/** |
|
234
|
|
|
* @return QueryFields |
|
235
|
|
|
*/ |
|
236
|
128 |
|
public function getQueryFields() |
|
237
|
|
|
{ |
|
238
|
128 |
|
return $this->queryFields; |
|
239
|
|
|
} |
|
240
|
|
|
|
|
241
|
|
|
/** |
|
242
|
|
|
* @param PhraseFields $phraseFields |
|
243
|
|
|
* @return void |
|
244
|
|
|
*/ |
|
245
|
143 |
|
public function setPhraseFields(PhraseFields $phraseFields) |
|
246
|
|
|
{ |
|
247
|
143 |
|
$this->phraseFields = $phraseFields; |
|
248
|
143 |
|
} |
|
249
|
|
|
|
|
250
|
|
|
/** |
|
251
|
|
|
* @return PhraseFields |
|
252
|
|
|
*/ |
|
253
|
126 |
|
public function getPhraseFields() |
|
254
|
|
|
{ |
|
255
|
126 |
|
return $this->phraseFields; |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
/** |
|
259
|
|
|
* @return BigramPhraseFields |
|
260
|
|
|
*/ |
|
261
|
124 |
|
public function getBigramPhraseFields() |
|
262
|
|
|
{ |
|
263
|
124 |
|
return $this->bigramPhraseFields; |
|
264
|
|
|
} |
|
265
|
|
|
|
|
266
|
|
|
/** |
|
267
|
|
|
* @param BigramPhraseFields $bigramPhraseFields |
|
268
|
|
|
* @return void |
|
269
|
|
|
*/ |
|
270
|
142 |
|
public function setBigramPhraseFields(BigramPhraseFields $bigramPhraseFields) |
|
271
|
|
|
{ |
|
272
|
142 |
|
$this->bigramPhraseFields = $bigramPhraseFields; |
|
273
|
142 |
|
} |
|
274
|
|
|
|
|
275
|
|
|
/** |
|
276
|
|
|
* @return TrigramPhraseFields |
|
277
|
|
|
*/ |
|
278
|
125 |
|
public function getTrigramPhraseFields() |
|
279
|
|
|
{ |
|
280
|
125 |
|
return $this->trigramPhraseFields; |
|
281
|
|
|
} |
|
282
|
|
|
|
|
283
|
|
|
/** |
|
284
|
|
|
* @param TrigramPhraseFields $trigramPhraseFields |
|
285
|
|
|
* @return void |
|
286
|
|
|
*/ |
|
287
|
142 |
|
public function setTrigramPhraseFields(TrigramPhraseFields $trigramPhraseFields) |
|
288
|
|
|
{ |
|
289
|
142 |
|
$this->trigramPhraseFields = $trigramPhraseFields; |
|
290
|
142 |
|
} |
|
291
|
|
|
|
|
292
|
|
|
/** |
|
293
|
|
|
* returns a string representation of the query |
|
294
|
|
|
* |
|
295
|
|
|
* @return string the string representation of the query |
|
296
|
|
|
*/ |
|
297
|
2 |
|
public function __toString() |
|
298
|
|
|
{ |
|
299
|
2 |
|
return $this->queryStringContainer->__toString(); |
|
300
|
|
|
} |
|
301
|
|
|
|
|
302
|
|
|
/** |
|
303
|
|
|
* Builds the query string which is then used for Solr's q parameters |
|
304
|
|
|
* |
|
305
|
|
|
* @return QueryStringContainer |
|
306
|
|
|
*/ |
|
307
|
61 |
|
public function getQueryStringContainer() |
|
308
|
|
|
{ |
|
309
|
61 |
|
return $this->queryStringContainer; |
|
310
|
|
|
} |
|
311
|
|
|
|
|
312
|
|
|
/** |
|
313
|
|
|
* @param QueryStringContainer $queryStringContainer |
|
314
|
|
|
*/ |
|
315
|
|
|
public function setQueryStringContainer(QueryStringContainer $queryStringContainer) |
|
316
|
|
|
{ |
|
317
|
|
|
$this->queryStringContainer = $queryStringContainer; |
|
318
|
|
|
} |
|
319
|
|
|
|
|
320
|
|
|
/** |
|
321
|
|
|
* @return Pagination |
|
322
|
|
|
*/ |
|
323
|
141 |
|
public function getPagination(): Pagination |
|
324
|
|
|
{ |
|
325
|
141 |
|
return $this->pagination; |
|
326
|
|
|
} |
|
327
|
|
|
|
|
328
|
|
|
/** |
|
329
|
|
|
* @param Pagination $pagination |
|
330
|
|
|
*/ |
|
331
|
|
|
public function setPagination(Pagination $pagination) |
|
332
|
|
|
{ |
|
333
|
|
|
$this->pagination = $pagination; |
|
334
|
|
|
} |
|
335
|
|
|
|
|
336
|
|
|
// query elevation |
|
337
|
|
|
|
|
338
|
|
|
/** |
|
339
|
|
|
* @param Elevation $elevation |
|
340
|
|
|
*/ |
|
341
|
37 |
|
public function setElevation(Elevation $elevation) |
|
342
|
|
|
{ |
|
343
|
37 |
|
$this->elevation = $elevation; |
|
344
|
37 |
|
} |
|
345
|
|
|
|
|
346
|
|
|
/** |
|
347
|
|
|
* @return Elevation |
|
348
|
|
|
*/ |
|
349
|
124 |
|
public function getElevation(): Elevation |
|
350
|
|
|
{ |
|
351
|
124 |
|
return $this->elevation; |
|
352
|
|
|
} |
|
353
|
|
|
|
|
354
|
|
|
// collapsing |
|
355
|
|
|
|
|
356
|
|
|
/** |
|
357
|
|
|
* @param FieldCollapsing $fieldCollapsing |
|
358
|
|
|
*/ |
|
359
|
141 |
|
public function setFieldCollapsing(FieldCollapsing $fieldCollapsing) |
|
360
|
|
|
{ |
|
361
|
141 |
|
$this->fieldCollapsing = $fieldCollapsing; |
|
362
|
141 |
|
} |
|
363
|
|
|
|
|
364
|
|
|
/** |
|
365
|
|
|
* @return FieldCollapsing |
|
366
|
|
|
*/ |
|
367
|
127 |
|
public function getFieldCollapsing(): FieldCollapsing |
|
368
|
|
|
{ |
|
369
|
127 |
|
return $this->fieldCollapsing; |
|
370
|
|
|
} |
|
371
|
|
|
|
|
372
|
|
|
// grouping |
|
373
|
|
|
|
|
374
|
|
|
/** |
|
375
|
|
|
* Activates and deactivates grouping for the current query. |
|
376
|
|
|
* |
|
377
|
|
|
* @param Grouping $grouping TRUE to enable grouping, FALSE to disable grouping |
|
378
|
|
|
* @return void |
|
379
|
|
|
*/ |
|
380
|
141 |
|
public function setGrouping(Grouping $grouping) |
|
381
|
|
|
{ |
|
382
|
141 |
|
$this->grouping = $grouping; |
|
383
|
141 |
|
} |
|
384
|
|
|
|
|
385
|
|
|
/** |
|
386
|
|
|
* @return Grouping |
|
387
|
|
|
*/ |
|
388
|
132 |
|
public function getGrouping(): Grouping |
|
389
|
|
|
{ |
|
390
|
132 |
|
return $this->grouping; |
|
391
|
|
|
} |
|
392
|
|
|
|
|
393
|
|
|
/** |
|
394
|
|
|
* Returns the number of results that should be shown per page or the number of groups, when grouping is active |
|
395
|
|
|
* |
|
396
|
|
|
* @return int number of results to show per page |
|
397
|
|
|
*/ |
|
398
|
40 |
|
public function getRows() |
|
399
|
|
|
{ |
|
400
|
40 |
|
if ($this->getGrouping() instanceof Grouping && $this->getGrouping()->getIsEnabled()) { |
|
401
|
1 |
|
return $this->getGrouping()->getNumberOfGroups(); |
|
402
|
|
|
} |
|
403
|
|
|
|
|
404
|
40 |
|
return $this->getPagination()->getResultsPerPage(); |
|
405
|
|
|
} |
|
406
|
|
|
|
|
407
|
|
|
// faceting |
|
408
|
|
|
|
|
409
|
|
|
/** |
|
410
|
|
|
* Activates and deactivates faceting for the current query. |
|
411
|
|
|
* |
|
412
|
|
|
* @param Faceting $faceting TRUE to enable faceting, FALSE to disable faceting |
|
413
|
|
|
* @return void |
|
414
|
|
|
*/ |
|
415
|
141 |
|
public function setFaceting(Faceting $faceting) |
|
416
|
|
|
{ |
|
417
|
141 |
|
$this->faceting = $faceting; |
|
418
|
141 |
|
} |
|
419
|
|
|
|
|
420
|
|
|
/** |
|
421
|
|
|
* @return Faceting |
|
422
|
|
|
*/ |
|
423
|
124 |
|
public function getFaceting(): Faceting |
|
424
|
|
|
{ |
|
425
|
124 |
|
return $this->faceting; |
|
426
|
|
|
} |
|
427
|
|
|
|
|
428
|
|
|
/** |
|
429
|
|
|
* Sets the filters to use. |
|
430
|
|
|
* |
|
431
|
|
|
* @param Filters $filters |
|
432
|
|
|
*/ |
|
433
|
143 |
|
public function setFilters(Filters $filters) |
|
434
|
|
|
{ |
|
435
|
143 |
|
$this->filters = $filters; |
|
436
|
143 |
|
} |
|
437
|
|
|
|
|
438
|
|
|
/** |
|
439
|
|
|
* Gets all currently applied filters. |
|
440
|
|
|
* |
|
441
|
|
|
* @return Filters Array of filters |
|
442
|
|
|
*/ |
|
443
|
174 |
|
public function getFilters(): Filters |
|
444
|
|
|
{ |
|
445
|
174 |
|
return $this->filters; |
|
446
|
|
|
} |
|
447
|
|
|
|
|
448
|
|
|
/** |
|
449
|
|
|
* @param Filters $filtersToAdd |
|
450
|
|
|
* @return Filters |
|
451
|
|
|
*/ |
|
452
|
|
|
public function addFilters(Filters $filtersToAdd) |
|
453
|
|
|
{ |
|
454
|
|
|
foreach($filtersToAdd->getValues() as $key => $value) { |
|
455
|
|
|
$this->getFilters()->add($value, $key); |
|
456
|
|
|
} |
|
457
|
|
|
|
|
458
|
|
|
return $this->filters; |
|
459
|
|
|
} |
|
460
|
|
|
|
|
461
|
|
|
/** |
|
462
|
|
|
* @param ReturnFields $returnFields |
|
463
|
|
|
*/ |
|
464
|
142 |
|
public function setReturnFields(ReturnFields $returnFields) |
|
465
|
|
|
{ |
|
466
|
142 |
|
$this->returnFields = $returnFields; |
|
467
|
142 |
|
} |
|
468
|
|
|
|
|
469
|
|
|
/** |
|
470
|
|
|
* @return ReturnFields |
|
471
|
|
|
*/ |
|
472
|
129 |
|
public function getReturnFields(): ReturnFields |
|
473
|
|
|
{ |
|
474
|
129 |
|
return $this->returnFields; |
|
475
|
|
|
} |
|
476
|
|
|
|
|
477
|
|
|
/** |
|
478
|
|
|
* Gets the query type, Solr's qt parameter. |
|
479
|
|
|
* |
|
480
|
|
|
* @return string Query type, qt parameter. |
|
481
|
|
|
*/ |
|
482
|
1 |
|
public function getQueryType() |
|
483
|
|
|
{ |
|
484
|
1 |
|
return $this->queryParametersContainer->get('qt'); |
|
485
|
|
|
} |
|
486
|
|
|
|
|
487
|
|
|
/** |
|
488
|
|
|
* Sets the query type, Solr's qt parameter. |
|
489
|
|
|
* |
|
490
|
|
|
* @param string|bool $queryType String query type or boolean FALSE to disable / reset the qt parameter. |
|
491
|
|
|
* @see http://wiki.apache.org/solr/CoreQueryParameters#qt |
|
492
|
|
|
*/ |
|
493
|
2 |
|
public function setQueryType($queryType) |
|
494
|
|
|
{ |
|
495
|
2 |
|
$this->queryParametersContainer->setWhenStringOrUnsetWhenEmpty('qt', $queryType); |
|
496
|
2 |
|
} |
|
497
|
|
|
|
|
498
|
|
|
/** |
|
499
|
|
|
* Set the operator that should be used for the query. Operators an be created e.g. by using |
|
500
|
|
|
* Operator::and() |
|
501
|
|
|
* |
|
502
|
|
|
* @param Operator $operator |
|
503
|
|
|
*/ |
|
504
|
1 |
|
public function setOperator(Operator $operator) |
|
505
|
|
|
{ |
|
506
|
1 |
|
$this->operator = $operator; |
|
507
|
1 |
|
} |
|
508
|
|
|
|
|
509
|
|
|
/** |
|
510
|
|
|
* Returns the operator of the query. |
|
511
|
|
|
* |
|
512
|
|
|
* @return Operator |
|
513
|
|
|
*/ |
|
514
|
1 |
|
public function getOperator(): Operator |
|
515
|
|
|
{ |
|
516
|
1 |
|
return $this->operator; |
|
517
|
|
|
} |
|
518
|
|
|
|
|
519
|
|
|
/** |
|
520
|
|
|
* @return Slops |
|
521
|
|
|
*/ |
|
522
|
4 |
|
public function getSlops(): Slops |
|
523
|
|
|
{ |
|
524
|
4 |
|
return $this->slops; |
|
525
|
|
|
} |
|
526
|
|
|
|
|
527
|
|
|
/** |
|
528
|
|
|
* @param Slops $slops |
|
529
|
|
|
*/ |
|
530
|
50 |
|
public function setSlops(Slops $slops) |
|
531
|
|
|
{ |
|
532
|
50 |
|
$this->slops = $slops; |
|
533
|
50 |
|
} |
|
534
|
|
|
|
|
535
|
|
|
/** |
|
536
|
|
|
* Gets the alternative query, Solr's q.alt parameter. |
|
537
|
|
|
* |
|
538
|
|
|
* @return string Alternative query, q.alt parameter. |
|
539
|
|
|
*/ |
|
540
|
6 |
|
public function getAlternativeQuery() |
|
541
|
|
|
{ |
|
542
|
6 |
|
return $this->queryParametersContainer->get('q.alt'); |
|
543
|
|
|
} |
|
544
|
|
|
|
|
545
|
|
|
/** |
|
546
|
|
|
* Sets an alternative query, Solr's q.alt parameter. |
|
547
|
|
|
* |
|
548
|
|
|
* This query supports the complete Lucene Query Language. |
|
549
|
|
|
* |
|
550
|
|
|
* @param string $alternativeQuery String alternative query or boolean FALSE to disable / reset the q.alt parameter. |
|
551
|
|
|
* @see http://wiki.apache.org/solr/DisMaxQParserPlugin#q.alt |
|
552
|
|
|
*/ |
|
553
|
44 |
|
public function setAlternativeQuery($alternativeQuery) |
|
554
|
|
|
{ |
|
555
|
44 |
|
$this->queryParametersContainer->setWhenStringOrUnsetWhenEmpty('q.alt', $alternativeQuery); |
|
556
|
44 |
|
} |
|
557
|
|
|
|
|
558
|
|
|
// keywords |
|
559
|
|
|
|
|
560
|
|
|
/** |
|
561
|
|
|
* Set the query to omit the response header |
|
562
|
|
|
* |
|
563
|
|
|
* @param bool $omitHeader TRUE (default) to omit response headers, FALSE to re-enable |
|
564
|
|
|
*/ |
|
565
|
3 |
|
public function setOmitHeader($omitHeader = true) |
|
566
|
|
|
{ |
|
567
|
3 |
|
$omitHeader = ($omitHeader === true) ? 'true' : $omitHeader; |
|
568
|
3 |
|
$this->queryParametersContainer->setWhenStringOrUnsetWhenEmpty('omitHeader', $omitHeader); |
|
569
|
3 |
|
} |
|
570
|
|
|
|
|
571
|
|
|
/** |
|
572
|
|
|
* Sets the minimum match (mm) parameter |
|
573
|
|
|
* |
|
574
|
|
|
* @param mixed $minimumMatch Minimum match parameter as string or boolean FALSE to disable / reset the mm parameter |
|
575
|
|
|
* @see http://wiki.apache.org/solr/DisMaxRequestHandler#mm_.28Minimum_.27Should.27_Match.29 |
|
576
|
|
|
*/ |
|
577
|
2 |
|
public function setMinimumMatch($minimumMatch) |
|
578
|
|
|
{ |
|
579
|
2 |
|
$this->queryParametersContainer->setWhenStringOrUnsetWhenEmpty('mm', $minimumMatch); |
|
580
|
2 |
|
} |
|
581
|
|
|
|
|
582
|
|
|
/** |
|
583
|
|
|
* Sets the boost function (bf) parameter |
|
584
|
|
|
* |
|
585
|
|
|
* @param mixed $boostFunction boost function parameter as string or boolean FALSE to disable / reset the bf parameter |
|
586
|
|
|
* @see http://wiki.apache.org/solr/DisMaxRequestHandler#bf_.28Boost_Functions.29 |
|
587
|
|
|
*/ |
|
588
|
2 |
|
public function setBoostFunction($boostFunction) |
|
589
|
|
|
{ |
|
590
|
2 |
|
$this->queryParametersContainer->setWhenStringOrUnsetWhenEmpty('bf', $boostFunction); |
|
591
|
2 |
|
} |
|
592
|
|
|
|
|
593
|
|
|
/** |
|
594
|
|
|
* Sets the boost query (bq) parameter |
|
595
|
|
|
* |
|
596
|
|
|
* @param mixed $boostQuery boost query parameter as string or array to set a boost query or boolean FALSE to disable / reset the bq parameter |
|
597
|
|
|
* @see http://wiki.apache.org/solr/DisMaxQParserPlugin#bq_.28Boost_Query.29 |
|
598
|
|
|
*/ |
|
599
|
3 |
|
public function setBoostQuery($boostQuery) |
|
600
|
|
|
{ |
|
601
|
3 |
|
if (is_array($boostQuery)) { |
|
602
|
1 |
|
$this->queryParametersContainer->set('bq', $boostQuery); |
|
603
|
1 |
|
return; |
|
604
|
|
|
} |
|
605
|
2 |
|
$this->queryParametersContainer->setWhenStringOrUnsetWhenEmpty('bq', $boostQuery); |
|
606
|
2 |
|
} |
|
607
|
|
|
|
|
608
|
|
|
/** |
|
609
|
|
|
* Set the tie breaker (tie) parameter |
|
610
|
|
|
* |
|
611
|
|
|
* @param mixed $tieParameter tie breaker parameter as string or boolean FALSE to disable / reset the tie parameter |
|
612
|
|
|
* @return void |
|
613
|
|
|
*/ |
|
614
|
1 |
|
public function setTieParameter($tieParameter) |
|
615
|
|
|
{ |
|
616
|
1 |
|
$this->queryParametersContainer->setWhenStringOrUnsetWhenEmpty('tie', $tieParameter); |
|
617
|
1 |
|
} |
|
618
|
|
|
|
|
619
|
|
|
/** |
|
620
|
|
|
* Gets a specific query parameter by its name. |
|
621
|
|
|
* |
|
622
|
|
|
* @param string $parameterName The parameter to return |
|
623
|
|
|
* @param mixed $defaultIfEmpty |
|
624
|
|
|
* @return mixed The parameter's value or $defaultIfEmpty if not set |
|
625
|
|
|
*/ |
|
626
|
27 |
|
public function getQueryParameter($parameterName, $defaultIfEmpty = null) |
|
627
|
|
|
{ |
|
628
|
27 |
|
$parameters = $this->getQueryParameters(); |
|
629
|
27 |
|
return isset($parameters[$parameterName]) ? $parameters[$parameterName] : $defaultIfEmpty; |
|
630
|
|
|
} |
|
631
|
|
|
|
|
632
|
|
|
/** |
|
633
|
|
|
* The build method calls build on all ParameterBuilder that fill the QueryParameterContainer |
|
634
|
|
|
* |
|
635
|
|
|
* @return void |
|
636
|
|
|
*/ |
|
637
|
124 |
|
protected function build() |
|
638
|
|
|
{ |
|
639
|
124 |
|
$this->getQueryFields()->build($this); |
|
640
|
124 |
|
$this->getPhraseFields()->build($this); |
|
641
|
124 |
|
$this->getBigramPhraseFields()->build($this); |
|
642
|
124 |
|
$this->getTrigramPhraseFields()->build($this); |
|
643
|
124 |
|
$this->getHighlighting()->build($this); |
|
644
|
124 |
|
$this->getFaceting()->build($this); |
|
645
|
124 |
|
$this->getGrouping()->build($this); |
|
646
|
124 |
|
$this->getSpellchecking()->build($this); |
|
647
|
124 |
|
$this->getFieldCollapsing()->build($this); |
|
648
|
124 |
|
$this->getElevation()->build($this); |
|
649
|
|
|
|
|
650
|
124 |
|
$this->debug->build($this); |
|
651
|
124 |
|
$this->sorting->build($this); |
|
652
|
124 |
|
$this->operator->build($this); |
|
653
|
124 |
|
$this->slops->build($this); |
|
654
|
|
|
|
|
655
|
|
|
// it is important that this parameters get build in the end because other builders add filters and return fields |
|
656
|
124 |
|
$this->getReturnFields()->build($this); |
|
657
|
124 |
|
$this->getFilters()->build($this); |
|
658
|
124 |
|
} |
|
659
|
|
|
|
|
660
|
|
|
/** |
|
661
|
|
|
* Builds an array of query parameters to use for the search query. |
|
662
|
|
|
* |
|
663
|
|
|
* @return array An array ready to use with query parameters |
|
664
|
|
|
*/ |
|
665
|
124 |
|
public function getQueryParameters() |
|
666
|
|
|
{ |
|
667
|
124 |
|
$this->build(); |
|
668
|
124 |
|
return $this->queryParametersContainer->toArray(); |
|
669
|
|
|
} |
|
670
|
|
|
|
|
671
|
|
|
/** |
|
672
|
|
|
* @return QueryParametersContainer |
|
673
|
|
|
*/ |
|
674
|
126 |
|
public function getQueryParametersContainer(): QueryParametersContainer |
|
675
|
|
|
{ |
|
676
|
126 |
|
return $this->queryParametersContainer; |
|
677
|
|
|
} |
|
678
|
|
|
|
|
679
|
|
|
/** |
|
680
|
|
|
* Adds a parameter to the query. |
|
681
|
|
|
* |
|
682
|
|
|
* @param string $parameterName |
|
683
|
|
|
* @param mixed $value |
|
684
|
|
|
*/ |
|
685
|
|
|
public function addQueryParameter($parameterName, $value) |
|
686
|
|
|
{ |
|
687
|
|
|
$this->queryParametersContainer->set($parameterName, $value); |
|
688
|
|
|
} |
|
689
|
|
|
|
|
690
|
|
|
// general query parameters |
|
691
|
|
|
|
|
692
|
|
|
/** |
|
693
|
|
|
* Enables or disables highlighting of search terms in result teasers. |
|
694
|
|
|
* |
|
695
|
|
|
* @param Highlighting $highlighting |
|
696
|
|
|
* @see http://wiki.apache.org/solr/HighlightingParameters |
|
697
|
|
|
* @return void |
|
698
|
|
|
*/ |
|
699
|
141 |
|
public function setHighlighting(Highlighting $highlighting) |
|
700
|
|
|
{ |
|
701
|
141 |
|
$this->highlighting = $highlighting; |
|
702
|
141 |
|
} |
|
703
|
|
|
|
|
704
|
|
|
/** |
|
705
|
|
|
* @return Highlighting |
|
706
|
|
|
*/ |
|
707
|
124 |
|
public function getHighlighting(): Highlighting |
|
708
|
|
|
{ |
|
709
|
124 |
|
return $this->highlighting; |
|
710
|
|
|
} |
|
711
|
|
|
|
|
712
|
|
|
// misc |
|
713
|
|
|
/** |
|
714
|
|
|
* @param Spellchecking $spellchecking |
|
715
|
|
|
*/ |
|
716
|
33 |
|
public function setSpellchecking(Spellchecking $spellchecking) |
|
717
|
|
|
{ |
|
718
|
33 |
|
$this->spellchecking = $spellchecking; |
|
719
|
33 |
|
} |
|
720
|
|
|
|
|
721
|
|
|
/** |
|
722
|
|
|
* @return Spellchecking |
|
723
|
|
|
*/ |
|
724
|
124 |
|
public function getSpellchecking(): Spellchecking |
|
725
|
|
|
{ |
|
726
|
124 |
|
return $this->spellchecking; |
|
727
|
|
|
} |
|
728
|
|
|
|
|
729
|
|
|
/** |
|
730
|
|
|
* Sets the sort parameter. |
|
731
|
|
|
* |
|
732
|
|
|
* $sorting must include a field name (or the pseudo-field score), |
|
733
|
|
|
* followed by a space, |
|
734
|
|
|
* followed by a sort direction (asc or desc). |
|
735
|
|
|
* |
|
736
|
|
|
* Multiple fallback sortings can be separated by comma, |
|
737
|
|
|
* ie: <field name> <direction>[,<field name> <direction>]... |
|
738
|
|
|
* |
|
739
|
|
|
* @param string|bool $sorting Either a comma-separated list of sort fields and directions or FALSE to reset sorting to the default behavior (sort by score / relevance) |
|
740
|
|
|
* @see http://wiki.apache.org/solr/CommonQueryParameters#sort |
|
741
|
|
|
*/ |
|
742
|
7 |
|
public function setSorting($sorting) |
|
743
|
|
|
{ |
|
744
|
7 |
|
$sorting = trim((string)$sorting); |
|
745
|
7 |
|
$enabled = $sorting !== ''; |
|
746
|
7 |
|
$this->sorting->setIsEnabled($enabled); |
|
747
|
7 |
|
$this->sorting->setSortField($sorting); |
|
748
|
7 |
|
} |
|
749
|
|
|
|
|
750
|
|
|
/** |
|
751
|
|
|
* Enables or disables the debug parameter for the query. |
|
752
|
|
|
* |
|
753
|
|
|
* @param bool $debugMode Enables debugging when set to TRUE, deactivates debugging when set to FALSE, defaults to TRUE. |
|
754
|
|
|
*/ |
|
755
|
34 |
|
public function setDebugMode($debugMode = true) |
|
756
|
|
|
{ |
|
757
|
34 |
|
$this->debug->setIsEnabled($debugMode); |
|
758
|
34 |
|
} |
|
759
|
|
|
} |
|
760
|
|
|
|