-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathQuery.php
More file actions
1519 lines (1309 loc) · 40.1 KB
/
Query.php
File metadata and controls
1519 lines (1309 loc) · 40.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* @link https://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license https://www.yiiframework.com/license/
*/
namespace b0rner\solr;
use Yii;
use yii\base\InvalidArgumentException;
use yii\base\Component;
/**
* Query represents a search against a SOLR application server.
*
* Query provides a set of methods to facilitate the specification of different clauses
* in a Solr search. These methods can be chained together.
*
* By calling [[createCommand()]], we can get a [[Command]] instance which can be further
* used to perform/execute the SOLR query against a SOLR Host.
*
* This class tries to emulate the SQL behavior as close as possible.
*
*/
class Query extends Component
{
/**
* @var array|null the columns (aka fields) being selected. For example, `['id', 'name']`.
* If not set, it means selecting all columns.
* @see https://solr.apache.org/guide/7_6/common-query-parameters.html#fl-field-list-parameter
* @see select()
*/
public $select = '*';
/**
* @var int|bool|null the default number of seconds that query results can remain valid in cache.
* Use 0 to indicate that the cached data will never expire.
* Use a negative number to indicate that query cache should not be used.
* Use boolean `true` to indicate that [[Connection::queryCacheDuration]] should be used.
* @see cache()
* @since 2.0.14
*/
public $queryCacheDuration;
/**
* @var \yii\caching\Dependency|null the dependency to be associated with the cached query result for this query
* @see cache()
* @since 2.0.14
*/
public $queryCacheDependency;
/**
* @var string the search phrase (aka query, aka q=) itself, like "color: red AND size:large"
*/
public $q;
/**
* @var array query condition. This refers to the Filter Query in a SOLR search.
* Multiple Filter Queries can be provided by chaining ->where()
* @see where() for valid syntax on specifying this value.
*/
public $where = [];
/**
* @var int|null maximum number of records to be returned.
* @see https://solr.apache.org/guide/7_6/common-query-parameters.html#rows-parameter
*/
public $limit;
/**
* @var int|null zero-based offset from where the records are to be returned, see start parameter in SOLR queries.
* @see https://solr.apache.org/guide/7_6/common-query-parameters.html#start-parameter
* If not set or 0, it means starting from the beginning.
*/
public $offset;
/**
* @var array|null how to sort the query results. This is used to construct the sort parameter.
* @see https://solr.apache.org/guide/7_6/common-query-parameters.html#sort-parameter
*/
public $orderBy;
/**
* @var string|callable|null the name of the column by which the query results should be indexed by.
* This can also be a callable (e.g. anonymous function) that returns the index value based on the given
* row data. For more details, see [[indexBy()]]. This property is only used by [[QueryInterface::all()|all()]].
*/
public $indexBy;
/**
* @var bool Whether to use the highlighting component.
* @see https://solr.apache.org/guide/solr/latest/query-guide/highlighting.html
*/
public $hl = false;
/**
* @var string The highlighting implementation/engine to use. Acceptable values are: unified, original, fastVector.
* @see https://solr.apache.org/guide/solr/latest/query-guide/highlighting.html
*/
public $hlMethod = 'unified';
/**
* @var string Fields to generate highlighted snippets for. Separate multiple fields with commas.
* @see https://solr.apache.org/guide/solr/latest/query-guide/highlighting.html
*/
public $hlFl = null;
/**
* @var string Overrides the q parameter for highlighting
* @see https://solr.apache.org/guide/solr/latest/query-guide/highlighting.html
*/
public $hlQ = null;
/**
* @var string The query parser to use if the query option is set
* @see https://solr.apache.org/guide/solr/latest/query-guide/highlighting.html
*/
public $hlQParser = null;
/**
* @var bool If false, all query terms will be highlighted for each field to be highlighted (hl.fl) no matter what
* fields the parsed query refer to. If set to true, only query terms aligning with the field being highlighted
* will in turn be highlighted.
* @see https://solr.apache.org/guide/solr/latest/query-guide/highlighting.html
*/
public $hlRequireFieldMatch = false;
/**
* @var bool If set to true, Solr will highlight phrase queries (and other advanced position-sensitive queries) accurately
* as phrases. If false, the parts of the phrase will be highlighted everywhere instead of only when it forms the given phrase.
* @see https://solr.apache.org/guide/solr/latest/query-guide/highlighting.html
*/
public $hlUsePhraseHighlighter = false;
/**
* @var int Maximum number of snippets per field
* @see https://solr.apache.org/guide/solr/latest/query-guide/highlighting.html
*/
public $hlSnippets = 1;
/**
* @var int The size, in characters, of fragments to consider for highlighting
* @see https://solr.apache.org/guide/solr/latest/query-guide/highlighting.html
*/
public $hlFragsize = 100;
/**
* @var string Solr option hl.tag.pre
* @see https://solr.apache.org/guide/solr/latest/query-guide/highlighting.html
*/
public $hlTagPre = '<em>';
/**
* @var string Solr option hl.tag.post
* @see https://solr.apache.org/guide/solr/latest/query-guide/highlighting.html
*/
public $hlTagPost = '</em>';
/**
* @var string If blank, then the stored text will be returned without any escaping/encoding
* performed by the highlighter. If set to html then special HTML/XML characters will be encoded
* (e.g., & becomes &). The pre- and post-snippet characters are never encoded.
* @see https://solr.apache.org/guide/solr/latest/query-guide/highlighting.html
*/
public $hlEncoder = null;
/**
* @var string|array Boost Query Parameter
* @see https://solr.apache.org/guide/solr/latest/query-guide/dismax-query-parser.html#bq-boost-query-parameter
*/
public $bq = [];
/**
* @var string Boost Functions Parameter
* @see https://solr.apache.org/guide/solr/latest/query-guide/dismax-query-parser.html#bf-boost-functions-parameter
*/
public $bf = null;
/**
* @var string Boost Functions Parameter for the EdisMax Query Handler. It behaves differently than bf!
* @see https://solr.apache.org/guide/solr/latest/query-guide/edismax-query-parser.html
*
* Also
* @see https://solr.apache.org/guide/solr/latest/query-guide/dismax-query-parser.html#bq-bf-shortcomings
*/
public $boost = null;
/**
* @var string Query Fields Parameter
* @see https://solr.apache.org/guide/solr/latest/query-guide/dismax-query-parser.html#qf-query-fields-parameter
*/
public $qf = null;
/**
* Whether to use the EDisMax Query Handler
* @var bool using the EDisMax Handler
*/
public $edismax = false;
/**
* Whether to use spellchecking
* @see https://solr.apache.org/guide/solr/latest/query-guide/spell-checking.html
* @var bool using spellcheck component
*/
public $spellcheck = false;
public $spellcheckQuery = null;
public $spellcheckBuild = false;
public $spellcheckCount = 5;
public $spellcheckCollate = false;
public $spellcheckOnlyMorePopular = false;
public $spellcheckExtendedResults = false;
public $spellcheckCollateExtendedResults = false;
/**
* Grouping
* @see https://solr.apache.org/guide/8_0/result-grouping.html
* @see https://solarium.readthedocs.io/en/stable/queries/select-query/building-a-select-query/components/grouping-component/
*/
public $group = false;
# Array of all group-queries added was by ->groupAddQuery()
public $groupQueries = [];
# Array of all group-queries added was by ->groupAddField()
public $groupFields = [];
public $groupLimit = null;
public $groupOffset = null;
public $groupSort = null;
public $groupNumberOfGroups = null;
public $groupCachepercentage = null;
public $groupFormat = null;
// Grouping facet parameters
public $groupTruncate = null;
public $groupFacet = null;
/**
* Facets Common Options
*/
public $facetSetPrefix = null;
public $facetSetContains = null;
public $facetSetMatches = null;
public $facetSetExcludeTerms = null;
public $facetSetSort = null;
public $facetSetLimit = null;
/**
* Facets Fields
*/
public $facetCreateFacetField = null;
public $facetSetField = null;
public $facetSetTerms = null;
/**
* Facets Query
*/
public $facetCreateFacetQuery = null;
public $facetSetQuery = null;
/**
* Facet MultiQuery
*/
public $facetCreateFacetMultiQuery = null;
public $facetCreateQuery = null;
/**
* Facet Range
*/
public $facetCreateFacetRange = null;
public $facetSetStart = null;
public $facetSetEnd = null;
public $facetSetGap = null;
/**
* MoreLikeThis
*/
public $mlt = false;
public $mltQuery = null ;
public $mltStart = null ;
public $mltRows = null ;
public $mltFields = null ;
public $mltSort = null ;
public $mltMatchInclude = null ;
public $mltInterestingTerms = null ;
public $mltMltFields = null ;
public $mltMinimumTermFrequency = null ;
public $mltMinimumDocumentFrequency = null ;
public $mltMaximumDocumentFrequency = null ;
public $mltMaximumDocumentFrequencyPercentage = null ;
public $mltMinimumWordLength = null ;
public $mltMaximumWordLength = null ;
public $mltMaximumQueryTerms = null ;
public $mltMaximumNumberOfTokens = null ;
public $mltBoost = null ;
public $mltQueryFields = null ;
/**
* Creates a DB command that can be used to execute this query.
* @param Connection $db the database connection used to execute the query.
* If this parameter is not given, the `solr` application
* component will be used.
* @return Command the created DB command instance.
*/
public function createCommand($db = null)
{
if ($db === null) {
$db = Yii::$app->get('solr');
}
$commandConfig = $db->getQueryBuilder()->build($this);
return $db->createCommand(null, $commandConfig);
}
/**
* Enables query cache for this Query.
* @param int|true $duration the number of seconds that query results can remain valid in cache.
* Use 0 to indicate that the cached data will never expire.
* Use a negative number to indicate that query cache should not be used.
* @param \yii\caching\Dependency|null $dependency the cache dependency associated with the cached result.
* @return $this the Query object itself
* @since 2.0.14
*/
public function cache($duration = 0, $dependency = null)
{
$this->queryCacheDuration = $duration;
$this->queryCacheDependency = $dependency;
return $this;
}
/**
* Disables query cache for this Query.
* @return $this the Query object itself
* @since 2.0.14
*/
public function noCache()
{
$this->queryCacheDuration = -1;
return $this;
}
/**
* @var string setting the search phrase
*/
public function q($q)
{
$this->q = $q;
return $this;
}
/**
* Sets the Field List Parameter of a SOLR search.
* @var string|array names of fields to fetch e.g ` ['title', 'text']` or
* `'title, text'`
*/
public function select($fields)
{
$this->select = $fields;
return $this;
}
public function fl($fields)
{
return $this->select($fields);
}
public function offset($offset)
{
$this->offset = $offset;
return $this;
}
public function start($offset)
{
return $this->offset($offset);
}
public function limit($limit)
{
$this->limit = $limit;
return $this;
}
public function rows($limit)
{
return $this->limit($limit);
}
/**
* @var array|string field name to sort plus order, e.g.
* ['date' => 'desc'] or 'date, desc'.
* Multiple fields may be provided, e.g. `['date' => 'asc', 'price' => 'desc']`
* Valid order types are `asc`, `ASC`, `DESC`, `desc`
*/
public function orderBy($orderBy)
{
$this->orderBy = $orderBy;
return $this;
}
public function sort($orderBy)
{
return $this->orderBy($orderBy);
}
/**
* condition is provided.
*
* A search can be filtered with multiple Filterqueries (aka &fq= parameter).
* So chaing multiple where() leads to multiple fq= parameter.
*
* Examples:
*
* `where(['price' => '[1 TO 300]'])`
* `where(['animal' => 'dog', 'sound' => 'barks'])`
*
* The following will split up to a OR search:
* `animal: (dog OR cat)`
*
* `where(['animal' => ['dog', 'cat']])
*
* This one will split up as follows
* `animal: (dog OR cat) AND sound: meow`
*
* ```php
* where([
* 'animal' => ['dog', 'cat'],
* 'sound' => 'meow'
* ], 'and')
* ```
*
* This one goes to:
* `animal: dog OR sound: barks`
*
* `where(['animal' => 'dog', 'sound' => 'barks'], 'or')`
*
* Every where() call adds an extra fq= call so SOLR.
*
* @param array condition of WHERE statemend (aka Filter Query) like `[$field => $query]`
* @param string search operator that is used to chain $conditions in case more than 1
* @see fq()
*
* @return Query
*
*/
public function where(array $condition = null, $operator = 'and')
{
if ($condition !== null) {
$this->where[] = [
'condition' => $condition,
'operator' => $operator
];
}
return $this;
}
public function fq(array $condition = null, $operator = 'and')
{
return $this->where($condition, $operator);
}
/**
* Shortcut for `where($condition, 'and')`
*
* @var array build an AND Filterquery. e.g.
* foo: bar AND faz: baz
* @return Query
*/
public function andWhere(array $condition = null)
{
if ($condition !== null) {
$this->where($condition, 'and');
}
return $this;
}
/**
* Shortcut for `where($condition, 'or')`
*
* @var array build an OR Filterquery. e.g.
* foo: bar OR faz: baz
* @return Query
*/
public function orWhere(array $condition = null)
{
if ($condition !== null) {
$this->where($condition, 'or');
}
return $this;
}
/**
* Because EDisMax supports all DisMax query parameter, we just use
* the EdisMax Handler. This is for convinience.
* Activating this affects the handling of the query string.
* @return this
*/
public function dismax()
{
$this->edismax = true;
return $this;
}
/**
* Whether to use the EDisMax Query Handler
* Activating this affects the handling of the query string.
* @return this
*/
public function edismax()
{
$this->edismax = true;
return $this;
}
/**
* This can be given as string like:
*
* `bq('date:[NOW/DAY-1YEAR TO NOW/DAY]')`
*
* or as array
*
* `bq(['date' => '[NOW/DAY-1YEAR TO NOW/DAY]'])`
*
* Multiple calls for multiple `&bq=` are possible:
*
* ```php
*
* $query->find()
* ->bq(['vendor'=> 'foo^2'])
* ->bq(['vendor'=> 'bar^1'])
*
* ```
*
*
* @var string|array Boost Query
* @return this
*/
public function bq($boostQuery)
{
if (is_array($boostQuery)) {
$this->bq[] = $boostQuery;
}
if (is_string($boostQuery)) {
$this->bq = $boostQuery;
}
return $this->edismax();
}
/**
* @var string Boost Function
* @return this
*/
public function bf($boostFunction)
{
$this->bf = $boostFunction;
return $this->edismax();
}
/**
* @var string Boost Function in EdixMax Context
* @return this
*/
public function boost($boostFunction)
{
$this->boost = $boostFunction;
return $this->edismax();
}
/**
* @var string Query Fields
* @return this
*/
public function qf($queryFields)
{
$this->qf = $queryFields;
return $this->edismax();
}
/**
* Sets a highlight parameters to retrieve from the documents.
* @param array $highlight array of parameters to highlight results.
* @return $this the query object itself
*/
public function hl()
{
$this->hl = true;
return $this;
}
public function hlMethod(string $method)
{
$this->hlMethod = $method;
return $this->hl();
}
/**
* @var string Fields to generate highlighted snippets for. Separate multiple fields with commas.
* @see https://solr.apache.org/guide/solr/latest/query-guide/highlighting.html
*/
public function hlFl(string $fields)
{
$this->hlFl = $fields;
return $this->hl();
}
/**
* @var string Overrides the q parameter for highlighting
* @see https://solr.apache.org/guide/solr/latest/query-guide/highlighting.html
*/
public function hlQ(string $queryString)
{
$this->hlQ = $queryString;
return $this->hl();
}
/**
* @var string The query parser to use if the query option is set
* @see https://solr.apache.org/guide/solr/latest/query-guide/highlighting.html
*/
public function hlQParser(string $queryParser)
{
$this->hlQParser = $queryParser;
return $this->hl();
}
/**
* @var bool If false, all query terms will be highlighted for each field to be highlighted (hl.fl) no matter what
* fields the parsed query refer to. If set to true, only query terms aligning with the field being highlighted
* will in turn be highlighted.
* @see https://solr.apache.org/guide/solr/latest/query-guide/highlighting.html
*/
public function hlRequireFieldMatch(bool $requireFM)
{
$this->hlRequireFieldMatch = $requireFM;
return $this->hl();
}
/**
* @var bool If set to true, Solr will highlight phrase queries (and other advanced position-sensitive queries) accurately
* as phrases. If false, the parts of the phrase will be highlighted everywhere instead of only when it forms the given phrase.
* @see https://solr.apache.org/guide/solr/latest/query-guide/highlighting.html
*/
public function hlUsePhraseHighlighter(bool $usePhraseHighlighter)
{
$this->hlUsePhraseHighlighter = $usePhraseHighlighter;
return $this->hl();
}
/**
* @var int Maximum number of snippets per field
* @see https://solr.apache.org/guide/solr/latest/query-guide/highlighting.html
*/
public function hlSnippets(int $snippets)
{
$this->hlSnippets = $snippets;
return $this->hl();
}
/**
* @var int The size, in characters, of fragments to consider for highlighting
* @see https://solr.apache.org/guide/solr/latest/query-guide/highlighting.html
*/
public function hlFragsize(int $fragsize)
{
$this->hlFragsize = $fragsize;
return $this->hl();
}
/**
* @var string Solr option hl.tag.pre
* @see https://solr.apache.org/guide/solr/latest/query-guide/highlighting.html
*/
public function hlTagPre(string $tagPre)
{
$this->hlTagPre = $tagPre;
return $this->hl();
}
/**
* @var string Solr option hl.tag.post
* @see https://solr.apache.org/guide/solr/latest/query-guide/highlighting.html
*/
public function hlTagPost(string $tagPost)
{
$this->hlTagPost = $tagPost;
return $this->hl();
}
/**
* @var string If blank, then the stored text will be returned without any escaping/encoding
* performed by the highlighter. If set to html then special HTML/XML characters will be encoded
* (e.g., & becomes &). The pre- and post-snippet characters are never encoded.
* @see https://solr.apache.org/guide/solr/latest/query-guide/highlighting.html
*/
public function hlEncoder(string $encoder)
{
$this->hlEncoder = $encoder;
return $this->hl();
}
/**
* Whether to activate spellchecking
* @see https://solr.apache.org/guide/solr/latest/query-guide/spell-checking.html
*/
public function spellcheck()
{
$this->spellcheck = true;
return $this;
}
public function spellcheckQuery(string $query) {
$this->spellcheckQuery = $query;
return $this->spellcheck();
}
public function spellcheckBuild() {
$this->spellcheckBuild = true;
return $this->spellcheck();
}
public function spellcheckCount(int $count) {
$this->spellcheckCount = $count;
return $this->spellcheck();
}
public function spellcheckCollate() {
$this->spellcheckCollate = true;
return $this->spellcheck();
}
public function spellcheckOnlyMorePopular() {
$this->spellcheckOnlyMorePopular = true;
return $this->spellcheck();
}
public function spellcheckExtendedResults() {
$this->spellcheckExtendedResults = true;
return $this->spellcheck();
}
public function spellcheckCollateExtendedResults() {
$this->spellcheckCollateExtendedResults = true;
return $this->spellcheck();
}
/**
* enable grouping by setting ...find()->group()->...
* set rows `find()->rows(..)` to define the number of groups
* that should be returned (relevant for grouping per field)
*
* @return void
*
*/
public function group()
{
$this->group = true;
return $this;
}
/**
* adding groupQuery with
* find()->group()->groupAddQuery('foo')->groupAddQuery(...)
* Multiple addQuery results in multiple groups,
* ignoring the numbers of rows (which is in fact "number of groups").
*
* @param string $term
*
*/
public function groupAddQuery(string $term)
{
if (gettype($term) == 'string') {
$this->groupQueries[] = $term;
}
return $this;
}
/**
* Adding Field to group by.
* adding groupField with:
* find()->group()->groupAddField('foo')->groupAddField(...)
*
* @param string $term
*
*/
public function groupAddField(string $term)
{
if (gettype($term) == 'string') {
$this->groupFields[] = $term;
}
return $this;
}
/**
* The number of documents per group, if groupSetFormat('grouped')
* Has no effect, for groupSetFormat('simple'). Use ->limit() instead.
* ...for any reason.
*
* This will not set the numer of groups.
* The Numer of groups is defined by the
* row parameter (for grouping by field)
* or the numer of queries added by addQuery().
*
* @param integer $limit
*
* @return void
*
*/
public function groupSetLimit(int $limit)
{
if (gettype($limit) == 'integer') {
$this->groupLimit = $limit;
}
return $this;
}
/**
* The offset of the document-block per group.
* This ist the group.start parameter from solr,
* that is called "offset" in solarium
* for any reason.
*
* @param integer $offset
*
* @return void
*
*/
public function groupSetOffset(int $offset)
{
if (gettype($offset) == 'integer') {
$this->groupOffset = $offset;
}
return $this;
}
/**
* How to sort documents within a single group.
*
* @param string $sort
*
* @return void
*
*/
public function groupSetSort(string $sort)
{
if (gettype($sort) == 'string') {
$this->groupSort = $sort;
}
return $this;
}
/**
* Return the number of groups in result-response.
*
* @param boolean $sort
*
* @return void
*
*/
public function groupSetNumberOfGroups(bool $numberOfGroupsEnabled)
{
if (gettype($numberOfGroupsEnabled) == 'boolean') {
$this->groupNumberOfGroups = $numberOfGroupsEnabled;
}
return $this;
}
/**
* Setting Solrs group.cache.percentage
* Testing has shown that group caching only improves
* search time with Boolean, wildcard, and fuzzy queries.
* For simple queries like term or "match all" queries,
* group caching degrades performance.
*
* @param integer $cachepercentage
*
* @return void
*/
public function groupSetCachepercentage(int $cachepercentage)
{
if (gettype($cachepercentage) == 'integer') {
$this->groupCachepercentage = $cachepercentage;
}
return $this;
}
/**
* Setting Group-Facet truncate option
*
* @param boolean $truncateEnabled
*
* @return void
*
*/
public function groupSetTruncate(bool $truncateEnabled)
{
if (gettype($truncateEnabled) == 'boolean') {
$this->groupTruncate = $truncateEnabled;
}
return $this;
}
/**
* Setting the group format. Valide values:
* - 'simple' use ->limit() to limit documents for each group
* - 'grouped' use ->groupSetLimit() to limit documents for each group
*
* @param string $format
*
* @return void
*/
public function groupSetFormat(string $format)
{
if (gettype($format) == 'string') {
$this->groupFormat = $format;
}
return $this;
}
/**
* Enable facetting for grouping
*
* @param boolean $facetEnabled
*
* @return void
*/
public function groupSetFacet(bool $facetEnabled)
{
if (gettype($facetEnabled) == 'boolean') {
$this->groupFacet = $facetEnabled;
}
return $this;
}
/**
* Facets Common Options
*/
public function facetSetPrefix($prefix)
{
$this->facetSetPrefix = $prefix;
return $this;
}
public function facetSetContains($contains)
{
$this->facetSetContains = $contains;
return $this;
}
public function facetSetMatches($matches)
{
$this->facetSetMatches = $matches;
return $this;
}
public function facetSetExcludeTerms($excludeTerms)
{
$this->facetSetExcludeTerms = $excludeTerms;
return $this;
}