|
1
|
|
|
<?php |
|
2
|
|
|
namespace ApacheSolrForTypo3\Solr\Domain\Search\Query; |
|
3
|
|
|
|
|
4
|
|
|
/*************************************************************** |
|
5
|
|
|
* Copyright notice |
|
6
|
|
|
* |
|
7
|
|
|
* (c) 2017 <[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\ParameterBuilder\BigramPhraseFields; |
|
28
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\Query\ParameterBuilder\Elevation; |
|
29
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\Query\ParameterBuilder\Faceting; |
|
30
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\Query\ParameterBuilder\FieldCollapsing; |
|
31
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\Query\ParameterBuilder\Filters; |
|
32
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\Query\ParameterBuilder\Grouping; |
|
33
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\Query\ParameterBuilder\Highlighting; |
|
34
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\Query\ParameterBuilder\PhraseFields; |
|
35
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\Query\ParameterBuilder\QueryFields; |
|
36
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\Query\ParameterBuilder\ReturnFields; |
|
37
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\Query\ParameterBuilder\Slops; |
|
38
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\Query\ParameterBuilder\Sorting; |
|
39
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\Query\ParameterBuilder\Sortings; |
|
40
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\Query\ParameterBuilder\Spellchecking; |
|
41
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\Query\ParameterBuilder\TrigramPhraseFields; |
|
42
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Site\SiteHashService; |
|
43
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Site\SiteRepository; |
|
44
|
|
|
use ApacheSolrForTypo3\Solr\FieldProcessor\PageUidToHierarchy; |
|
45
|
|
|
use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration; |
|
46
|
|
|
use ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager; |
|
47
|
|
|
use ApacheSolrForTypo3\Solr\Util; |
|
48
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
49
|
|
|
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* The concrete QueryBuilder contains all TYPO3 specific initialization logic of solr queries, for TYPO3. |
|
53
|
|
|
*/ |
|
54
|
|
|
class QueryBuilder extends AbstractQueryBuilder { |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Additional filters, which will be added to the query, as well as to |
|
58
|
|
|
* suggest queries. |
|
59
|
|
|
* |
|
60
|
|
|
* @var array |
|
61
|
|
|
*/ |
|
62
|
|
|
protected $additionalFilters = []; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @var TypoScriptConfiguration |
|
66
|
|
|
*/ |
|
67
|
|
|
protected $typoScriptConfiguration = null; |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @var SolrLogManager; |
|
71
|
|
|
*/ |
|
72
|
|
|
protected $logger = null; |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @var SiteHashService |
|
76
|
|
|
*/ |
|
77
|
|
|
protected $siteHashService = null; |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* QueryBuilder constructor. |
|
81
|
|
|
* @param TypoScriptConfiguration|null $configuration |
|
82
|
|
|
* @param SolrLogManager|null $solrLogManager |
|
83
|
|
|
* @param SiteHashService|null $siteHashService |
|
84
|
|
|
*/ |
|
85
|
|
|
public function __construct(TypoScriptConfiguration $configuration = null, SolrLogManager $solrLogManager = null, SiteHashService $siteHashService = null) |
|
86
|
|
|
{ |
|
87
|
|
|
$this->typoScriptConfiguration = $configuration ?? Util::getSolrConfiguration(); |
|
88
|
|
|
$this->logger = $solrLogManager ?? GeneralUtility::makeInstance(SolrLogManager::class, /** @scrutinizer ignore-type */ __CLASS__); |
|
89
|
184 |
|
$this->siteHashService = $siteHashService ?? GeneralUtility::makeInstance(SiteHashService::class); |
|
90
|
|
|
} |
|
91
|
184 |
|
|
|
92
|
184 |
|
/** |
|
93
|
184 |
|
* @param string $queryString |
|
94
|
184 |
|
* @return QueryBuilder |
|
95
|
|
|
*/ |
|
96
|
|
|
public function newSearchQuery($queryString): QueryBuilder |
|
97
|
|
|
{ |
|
98
|
|
|
$this->queryToBuild = $this->getSearchQueryInstance($queryString); |
|
99
|
|
|
return $this; |
|
100
|
150 |
|
} |
|
101
|
|
|
|
|
102
|
150 |
|
/** |
|
103
|
150 |
|
* @param string $queryString |
|
104
|
|
|
* @return QueryBuilder |
|
105
|
|
|
*/ |
|
106
|
|
|
public function newSuggestQuery($queryString): QueryBuilder |
|
107
|
|
|
{ |
|
108
|
|
|
$this->queryToBuild = $this->getSuggestQueryInstance($queryString); |
|
109
|
|
|
return $this; |
|
110
|
4 |
|
} |
|
111
|
|
|
|
|
112
|
4 |
|
/** |
|
113
|
4 |
|
* Initializes the Query object and SearchComponents and returns |
|
114
|
|
|
* the initialized query object, when a search should be executed. |
|
115
|
|
|
* |
|
116
|
|
|
* @param string|null $rawQuery |
|
117
|
|
|
* @param int $resultsPerPage |
|
118
|
|
|
* @param array $additionalFiltersFromRequest |
|
119
|
|
|
* @return SearchQuery |
|
120
|
|
|
*/ |
|
121
|
|
|
public function buildSearchQuery($rawQuery, $resultsPerPage = 10, array $additionalFiltersFromRequest = []) : SearchQuery |
|
122
|
|
|
{ |
|
123
|
|
|
if ($this->typoScriptConfiguration->getLoggingQuerySearchWords()) { |
|
124
|
|
|
$this->logger->log(SolrLogManager::INFO, 'Received search query', [$rawQuery]); |
|
125
|
138 |
|
} |
|
126
|
|
|
|
|
127
|
138 |
|
/* @var $query SearchQuery */ |
|
128
|
|
|
return $this->newSearchQuery($rawQuery) |
|
|
|
|
|
|
129
|
|
|
->useResultsPerPage($resultsPerPage) |
|
130
|
|
|
->useReturnFieldsFromTypoScript() |
|
131
|
|
|
->useQueryFieldsFromTypoScript() |
|
132
|
138 |
|
->useInitialQueryFromTypoScript() |
|
133
|
138 |
|
->useFiltersFromTypoScript() |
|
134
|
138 |
|
->useFilterArray($additionalFiltersFromRequest) |
|
135
|
138 |
|
->useFacetingFromTypoScript() |
|
136
|
138 |
|
->useVariantsFromTypoScript() |
|
137
|
138 |
|
->useGroupingFromTypoScript() |
|
138
|
138 |
|
->useHighlightingFromTypoScript() |
|
139
|
138 |
|
->usePhraseFieldsFromTypoScript() |
|
140
|
138 |
|
->useBigramPhraseFieldsFromTypoScript() |
|
141
|
138 |
|
->useTrigramPhraseFieldsFromTypoScript() |
|
142
|
138 |
|
->useOmitHeader(false) |
|
143
|
138 |
|
->getQuery(); |
|
144
|
138 |
|
} |
|
145
|
138 |
|
|
|
146
|
138 |
|
/** |
|
147
|
138 |
|
* Builds a SuggestQuery with all applied filters. |
|
148
|
|
|
* |
|
149
|
|
|
* @param string $queryString |
|
150
|
|
|
* @param array $additionalFilters |
|
151
|
|
|
* @param integer $requestedPageId |
|
152
|
|
|
* @param string $groupList |
|
153
|
|
|
* @return SuggestQuery |
|
154
|
|
|
*/ |
|
155
|
|
|
public function buildSuggestQuery(string $queryString, array $additionalFilters, int $requestedPageId, string $groupList) : SuggestQuery |
|
156
|
|
|
{ |
|
157
|
|
|
$this->newSuggestQuery($queryString) |
|
158
|
|
|
->useFiltersFromTypoScript() |
|
159
|
3 |
|
->useSiteHashFromTypoScript($requestedPageId) |
|
160
|
|
|
->useUserAccessGroups(explode(',', $groupList)) |
|
161
|
3 |
|
->useOmitHeader(); |
|
162
|
3 |
|
|
|
163
|
3 |
|
|
|
164
|
3 |
|
if (!empty($additionalFilters)) { |
|
165
|
3 |
|
$this->useFilterArray($additionalFilters); |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
3 |
|
return $this->queryToBuild; |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
3 |
|
* Returns Query for Search which finds document for given page. |
|
173
|
|
|
* Note: The Connection is per language as recommended in ext-solr docs. |
|
174
|
|
|
* |
|
175
|
|
|
* @return Query |
|
176
|
|
|
*/ |
|
177
|
|
|
public function buildPageQuery($pageId) |
|
178
|
|
|
{ |
|
179
|
|
|
$siteRepository = GeneralUtility::makeInstance(SiteRepository::class); |
|
180
|
|
|
$site = $siteRepository->getSiteByPageId($pageId); |
|
181
|
1 |
|
|
|
182
|
|
|
return $this->newSearchQuery('') |
|
183
|
1 |
|
->useQueryString('*:*') |
|
184
|
1 |
|
->useFilter('(type:pages AND uid:' . $pageId . ') OR (*:* AND pid:' . $pageId . ' NOT type:pages)', 'type') |
|
185
|
|
|
->useFilter('siteHash:' . $site->getSiteHash(), 'siteHash') |
|
186
|
1 |
|
->useReturnFields(ReturnFields::fromString('*')) |
|
187
|
1 |
|
->useSortings(Sortings::fromString('type asc, title asc')) |
|
188
|
1 |
|
->useQueryType('standard') |
|
189
|
1 |
|
->getQuery(); |
|
190
|
1 |
|
} |
|
191
|
1 |
|
|
|
192
|
1 |
|
/** |
|
193
|
1 |
|
* Returns a query for single record |
|
194
|
|
|
* |
|
195
|
|
|
* @return Query |
|
196
|
|
|
*/ |
|
197
|
|
|
public function buildRecordQuery($type, $uid, $pageId): Query |
|
198
|
|
|
{ |
|
199
|
|
|
$siteRepository = GeneralUtility::makeInstance(SiteRepository::class); |
|
200
|
|
|
$site = $siteRepository->getSiteByPageId($pageId); |
|
201
|
|
|
|
|
202
|
|
|
return $this->newSearchQuery('') |
|
203
|
|
|
->useQueryString('*:*') |
|
204
|
|
|
->useFilter('type:' . $type . ' AND uid:' . $uid, 'type') |
|
205
|
|
|
->useFilter('siteHash:' . $site->getSiteHash(), 'siteHash') |
|
206
|
|
|
->useReturnFields(ReturnFields::fromString('*')) |
|
207
|
|
|
->useSortings(Sortings::fromString('type asc, title asc')) |
|
208
|
|
|
->useQueryType('standard') |
|
209
|
|
|
->getQuery(); |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
/** |
|
213
|
|
|
* @return QueryBuilder |
|
214
|
|
|
*/ |
|
215
|
|
|
public function useSlopsFromTypoScript(): QueryBuilder |
|
216
|
|
|
{ |
|
217
|
|
|
return $this->useSlops(Slops::fromTypoScriptConfiguration($this->typoScriptConfiguration)); |
|
218
|
|
|
} |
|
219
|
52 |
|
|
|
220
|
|
|
/** |
|
221
|
52 |
|
* Uses the configured boost queries from typoscript |
|
222
|
|
|
* |
|
223
|
|
|
* @return QueryBuilder |
|
224
|
|
|
*/ |
|
225
|
|
|
public function useBoostQueriesFromTypoScript(): QueryBuilder |
|
226
|
|
|
{ |
|
227
|
|
|
$searchConfiguration = $this->typoScriptConfiguration->getSearchConfiguration(); |
|
228
|
|
|
|
|
229
|
52 |
|
if (!empty($searchConfiguration['query.']['boostQuery'])) { |
|
230
|
|
|
return $this->useBoostQueries($searchConfiguration['query.']['boostQuery']); |
|
231
|
52 |
|
} |
|
232
|
|
|
|
|
233
|
52 |
|
if (!empty($searchConfiguration['query.']['boostQuery.'])) { |
|
234
|
1 |
|
$boostQueries = $searchConfiguration['query.']['boostQuery.']; |
|
235
|
|
|
return $this->useBoostQueries(array_values($boostQueries)); |
|
236
|
|
|
} |
|
237
|
51 |
|
|
|
238
|
1 |
|
return $this; |
|
239
|
1 |
|
} |
|
240
|
|
|
|
|
241
|
|
|
/** |
|
242
|
50 |
|
* Uses the configured boostFunction from the typoscript configuration. |
|
243
|
|
|
* |
|
244
|
|
|
* @return QueryBuilder |
|
245
|
|
|
*/ |
|
246
|
|
|
public function useBoostFunctionFromTypoScript(): QueryBuilder |
|
247
|
|
|
{ |
|
248
|
|
|
$searchConfiguration = $this->typoScriptConfiguration->getSearchConfiguration(); |
|
249
|
|
|
if (!empty($searchConfiguration['query.']['boostFunction'])) { |
|
250
|
52 |
|
return $this->useBoostFunction($searchConfiguration['query.']['boostFunction']); |
|
251
|
|
|
} |
|
252
|
52 |
|
|
|
253
|
52 |
|
return $this; |
|
254
|
1 |
|
} |
|
255
|
|
|
|
|
256
|
|
|
/** |
|
257
|
51 |
|
* Uses the configured minimumMatch from the typoscript configuration. |
|
258
|
|
|
* |
|
259
|
|
|
* @return QueryBuilder |
|
260
|
|
|
*/ |
|
261
|
|
|
public function useMinimumMatchFromTypoScript(): QueryBuilder |
|
262
|
|
|
{ |
|
263
|
|
|
$searchConfiguration = $this->typoScriptConfiguration->getSearchConfiguration(); |
|
264
|
|
|
if (!empty($searchConfiguration['query.']['minimumMatch'])) { |
|
265
|
52 |
|
return $this->useMinimumMatch($searchConfiguration['query.']['minimumMatch']); |
|
266
|
|
|
} |
|
267
|
52 |
|
|
|
268
|
52 |
|
return $this; |
|
269
|
1 |
|
} |
|
270
|
|
|
|
|
271
|
|
|
/** |
|
272
|
51 |
|
* @return QueryBuilder |
|
273
|
|
|
*/ |
|
274
|
|
|
public function useTieParameterFromTypoScript(): QueryBuilder |
|
275
|
|
|
{ |
|
276
|
|
|
$searchConfiguration = $this->typoScriptConfiguration->getSearchConfiguration(); |
|
277
|
|
|
if (empty($searchConfiguration['query.']['tieParameter'])) { |
|
278
|
52 |
|
return $this; |
|
279
|
|
|
} |
|
280
|
52 |
|
|
|
281
|
52 |
|
return $this->useTieParameter($searchConfiguration['query.']['tieParameter']); |
|
282
|
51 |
|
} |
|
283
|
|
|
|
|
284
|
|
|
/** |
|
285
|
1 |
|
* Applies the configured query fields from the typoscript configuration. |
|
286
|
|
|
* |
|
287
|
|
|
* @return QueryBuilder |
|
288
|
|
|
*/ |
|
289
|
|
|
public function useQueryFieldsFromTypoScript(): QueryBuilder |
|
290
|
|
|
{ |
|
291
|
|
|
return $this->useQueryFields(QueryFields::fromString($this->typoScriptConfiguration->getSearchQueryQueryFields())); |
|
292
|
|
|
} |
|
293
|
138 |
|
|
|
294
|
|
|
/** |
|
295
|
138 |
|
* Applies the configured return fields from the typoscript configuration. |
|
296
|
|
|
* |
|
297
|
|
|
* @return QueryBuilder |
|
298
|
|
|
*/ |
|
299
|
|
|
public function useReturnFieldsFromTypoScript(): QueryBuilder |
|
300
|
|
|
{ |
|
301
|
|
|
$returnFieldsArray = (array)$this->typoScriptConfiguration->getSearchQueryReturnFieldsAsArray(['*', 'score']); |
|
302
|
|
|
return $this->useReturnFields(ReturnFields::fromArray($returnFieldsArray)); |
|
303
|
138 |
|
} |
|
304
|
|
|
|
|
305
|
138 |
|
|
|
306
|
138 |
|
|
|
307
|
|
|
/** |
|
308
|
|
|
* Can be used to apply the allowed sites from plugin.tx_solr.search.query.allowedSites to the query. |
|
309
|
|
|
* |
|
310
|
|
|
* @param int $requestedPageId |
|
311
|
|
|
* @return QueryBuilder |
|
312
|
|
|
*/ |
|
313
|
|
|
public function useSiteHashFromTypoScript(int $requestedPageId): QueryBuilder |
|
314
|
|
|
{ |
|
315
|
|
|
$queryConfiguration = $this->typoScriptConfiguration->getObjectByPathOrDefault('plugin.tx_solr.search.query.', []); |
|
316
|
|
|
$allowedSites = $this->siteHashService->getAllowedSitesForPageIdAndAllowedSitesConfiguration($requestedPageId, $queryConfiguration['allowedSites']); |
|
317
|
41 |
|
return $this->useSiteHashFromAllowedSites($allowedSites); |
|
318
|
|
|
} |
|
319
|
41 |
|
|
|
320
|
41 |
|
/** |
|
321
|
41 |
|
* Can be used to apply a list of allowed sites to the query. |
|
322
|
|
|
* |
|
323
|
|
|
* @param string $allowedSites |
|
324
|
|
|
* @return QueryBuilder |
|
325
|
|
|
*/ |
|
326
|
|
|
public function useSiteHashFromAllowedSites($allowedSites): QueryBuilder |
|
327
|
|
|
{ |
|
328
|
|
|
$isAnySiteAllowed = trim($allowedSites) === '*'; |
|
329
|
|
|
if ($isAnySiteAllowed) { |
|
330
|
41 |
|
// no filter required |
|
331
|
|
|
return $this; |
|
332
|
41 |
|
} |
|
333
|
41 |
|
|
|
334
|
|
|
$allowedSites = GeneralUtility::trimExplode(',', $allowedSites); |
|
335
|
1 |
|
$filters = []; |
|
336
|
|
|
foreach ($allowedSites as $site) { |
|
337
|
|
|
$siteHash = $this->siteHashService->getSiteHashForDomain($site); |
|
338
|
40 |
|
$filters[] = 'siteHash:"' . $siteHash . '"'; |
|
339
|
40 |
|
} |
|
340
|
40 |
|
|
|
341
|
40 |
|
$siteHashFilterString = implode(' OR ', $filters); |
|
342
|
40 |
|
return $this->useFilter($siteHashFilterString, 'siteHash'); |
|
343
|
|
|
} |
|
344
|
|
|
|
|
345
|
40 |
|
/** |
|
346
|
40 |
|
* Can be used to filter the result on an applied list of user groups. |
|
347
|
|
|
* |
|
348
|
|
|
* @param array $groups |
|
349
|
|
|
* @return QueryBuilder |
|
350
|
|
|
*/ |
|
351
|
|
|
public function useUserAccessGroups(array $groups): QueryBuilder |
|
352
|
|
|
{ |
|
353
|
|
|
$groups = array_map('intval', $groups); |
|
354
|
|
|
$groups[] = 0; // always grant access to public documents |
|
355
|
45 |
|
$groups = array_unique($groups); |
|
356
|
|
|
sort($groups, SORT_NUMERIC); |
|
357
|
45 |
|
|
|
358
|
45 |
|
$accessFilter = '{!typo3access}' . implode(',', $groups); |
|
359
|
45 |
|
$this->queryToBuild->removeFilterQuery('access'); |
|
360
|
45 |
|
return $this->useFilter($accessFilter, 'access'); |
|
361
|
|
|
} |
|
362
|
45 |
|
|
|
363
|
45 |
|
/** |
|
364
|
45 |
|
* Applies the configured initial query settings to set the alternative query for solr as required. |
|
365
|
|
|
* |
|
366
|
|
|
* @return QueryBuilder |
|
367
|
|
|
*/ |
|
368
|
|
|
public function useInitialQueryFromTypoScript(): QueryBuilder |
|
369
|
|
|
{ |
|
370
|
|
|
if ($this->typoScriptConfiguration->getSearchInitializeWithEmptyQuery() || $this->typoScriptConfiguration->getSearchQueryAllowEmptyQuery()) { |
|
371
|
|
|
// empty main query, but using a "return everything" |
|
372
|
138 |
|
// alternative query in q.alt |
|
373
|
|
|
$this->useAlternativeQuery('*:*'); |
|
374
|
138 |
|
} |
|
375
|
|
|
|
|
376
|
|
|
if ($this->typoScriptConfiguration->getSearchInitializeWithQuery()) { |
|
377
|
40 |
|
$this->useAlternativeQuery($this->typoScriptConfiguration->getSearchInitializeWithQuery()); |
|
378
|
|
|
} |
|
379
|
|
|
|
|
380
|
138 |
|
return $this; |
|
381
|
4 |
|
} |
|
382
|
|
|
|
|
383
|
|
|
/** |
|
384
|
138 |
|
* Applies the configured facets from the typoscript configuration on the query. |
|
385
|
|
|
* |
|
386
|
|
|
* @return QueryBuilder |
|
387
|
|
|
*/ |
|
388
|
|
|
public function useFacetingFromTypoScript(): QueryBuilder |
|
389
|
|
|
{ |
|
390
|
|
|
return $this->useFaceting(Faceting::fromTypoScriptConfiguration($this->typoScriptConfiguration)); |
|
391
|
|
|
} |
|
392
|
138 |
|
|
|
393
|
|
|
/** |
|
394
|
138 |
|
* Applies the configured variants from the typoscript configuration on the query. |
|
395
|
|
|
* |
|
396
|
|
|
* @return QueryBuilder |
|
397
|
|
|
*/ |
|
398
|
|
|
public function useVariantsFromTypoScript(): QueryBuilder |
|
399
|
|
|
{ |
|
400
|
|
|
return $this->useFieldCollapsing(FieldCollapsing::fromTypoScriptConfiguration($this->typoScriptConfiguration)); |
|
401
|
|
|
} |
|
402
|
138 |
|
|
|
403
|
|
|
/** |
|
404
|
138 |
|
* Applies the configured groupings from the typoscript configuration to the query. |
|
405
|
|
|
* |
|
406
|
|
|
* @return QueryBuilder |
|
407
|
|
|
*/ |
|
408
|
|
|
public function useGroupingFromTypoScript(): QueryBuilder |
|
409
|
|
|
{ |
|
410
|
|
|
return $this->useGrouping(Grouping::fromTypoScriptConfiguration($this->typoScriptConfiguration)); |
|
411
|
|
|
} |
|
412
|
138 |
|
|
|
413
|
|
|
/** |
|
414
|
138 |
|
* Applies the configured highlighting from the typoscript configuration to the query. |
|
415
|
|
|
* |
|
416
|
|
|
* @return QueryBuilder |
|
417
|
|
|
*/ |
|
418
|
|
|
public function useHighlightingFromTypoScript(): QueryBuilder |
|
419
|
|
|
{ |
|
420
|
|
|
return $this->useHighlighting(Highlighting::fromTypoScriptConfiguration($this->typoScriptConfiguration)); |
|
421
|
|
|
} |
|
422
|
138 |
|
|
|
423
|
|
|
/** |
|
424
|
138 |
|
* Applies the configured filters (page section and other from typoscript). |
|
425
|
|
|
* |
|
426
|
|
|
* @return QueryBuilder |
|
427
|
|
|
*/ |
|
428
|
|
|
public function useFiltersFromTypoScript(): QueryBuilder |
|
429
|
|
|
{ |
|
430
|
|
|
$filters = Filters::fromTypoScriptConfiguration($this->typoScriptConfiguration); |
|
431
|
|
|
$this->queryToBuild->setFilterQueries($filters->getValues()); |
|
432
|
140 |
|
|
|
433
|
|
|
$this->useFilterArray($this->getAdditionalFilters()); |
|
434
|
140 |
|
|
|
435
|
140 |
|
$searchQueryFilters = $this->typoScriptConfiguration->getSearchQueryFilterConfiguration(); |
|
436
|
|
|
|
|
437
|
140 |
|
if (!is_array($searchQueryFilters) || count($searchQueryFilters) <= 0) { |
|
|
|
|
|
|
438
|
|
|
return $this; |
|
439
|
140 |
|
} |
|
440
|
|
|
|
|
441
|
140 |
|
// special filter to limit search to specific page tree branches |
|
442
|
136 |
|
if (array_key_exists('__pageSections', $searchQueryFilters)) { |
|
443
|
|
|
$pageIds = GeneralUtility::trimExplode(',', $searchQueryFilters['__pageSections']); |
|
444
|
|
|
$this->usePageSectionsFromPageIds($pageIds); |
|
445
|
|
|
$this->typoScriptConfiguration->removeSearchQueryFilterForPageSections(); |
|
446
|
4 |
|
} |
|
447
|
1 |
|
|
|
448
|
1 |
|
return $this; |
|
449
|
1 |
|
} |
|
450
|
|
|
|
|
451
|
|
|
/** |
|
452
|
4 |
|
* Applies the configured elevation from the typoscript configuration. |
|
453
|
|
|
* |
|
454
|
|
|
* @return QueryBuilder |
|
455
|
|
|
*/ |
|
456
|
|
|
public function useElevationFromTypoScript(): QueryBuilder |
|
457
|
|
|
{ |
|
458
|
|
|
return $this->useElevation(Elevation::fromTypoScriptConfiguration($this->typoScriptConfiguration)); |
|
459
|
|
|
} |
|
460
|
39 |
|
|
|
461
|
|
|
/** |
|
462
|
39 |
|
* Applies the configured spellchecking from the typoscript configuration. |
|
463
|
|
|
* |
|
464
|
|
|
* @return QueryBuilder |
|
465
|
|
|
*/ |
|
466
|
|
|
public function useSpellcheckingFromTypoScript(): QueryBuilder |
|
467
|
|
|
{ |
|
468
|
|
|
return $this->useSpellchecking(Spellchecking::fromTypoScriptConfiguration($this->typoScriptConfiguration)); |
|
469
|
|
|
} |
|
470
|
35 |
|
|
|
471
|
|
|
/** |
|
472
|
35 |
|
* Applies the passed pageIds as __pageSection filter. |
|
473
|
|
|
* |
|
474
|
|
|
* @param array $pageIds |
|
475
|
|
|
* @return QueryBuilder |
|
476
|
|
|
*/ |
|
477
|
|
|
public function usePageSectionsFromPageIds(array $pageIds = []): QueryBuilder |
|
478
|
|
|
{ |
|
479
|
|
|
$filters = []; |
|
480
|
|
|
|
|
481
|
1 |
|
/** @var $processor PageUidToHierarchy */ |
|
482
|
|
|
$processor = GeneralUtility::makeInstance(PageUidToHierarchy::class); |
|
483
|
1 |
|
$hierarchies = $processor->process($pageIds); |
|
484
|
|
|
|
|
485
|
|
|
foreach ($hierarchies as $hierarchy) { |
|
486
|
1 |
|
$lastLevel = array_pop($hierarchy); |
|
487
|
1 |
|
$filters[] = 'rootline:"' . $lastLevel . '"'; |
|
488
|
|
|
} |
|
489
|
1 |
|
|
|
490
|
1 |
|
$pageSectionsFilterString = implode(' OR ', $filters); |
|
491
|
1 |
|
return $this->useFilter($pageSectionsFilterString, 'pageSections'); |
|
492
|
|
|
} |
|
493
|
|
|
|
|
494
|
1 |
|
/** |
|
495
|
1 |
|
* Applies the configured phrase fields from the typoscript configuration to the query. |
|
496
|
|
|
* |
|
497
|
|
|
* @return QueryBuilder |
|
498
|
|
|
*/ |
|
499
|
|
|
public function usePhraseFieldsFromTypoScript(): QueryBuilder |
|
500
|
|
|
{ |
|
501
|
|
|
return $this->usePhraseFields(PhraseFields::fromTypoScriptConfiguration($this->typoScriptConfiguration)); |
|
502
|
|
|
} |
|
503
|
138 |
|
|
|
504
|
|
|
/** |
|
505
|
138 |
|
* Applies the configured bigram phrase fields from the typoscript configuration to the query. |
|
506
|
|
|
* |
|
507
|
|
|
* @return QueryBuilder |
|
508
|
|
|
*/ |
|
509
|
|
|
public function useBigramPhraseFieldsFromTypoScript(): QueryBuilder |
|
510
|
|
|
{ |
|
511
|
|
|
return $this->useBigramPhraseFields(BigramPhraseFields::fromTypoScriptConfiguration($this->typoScriptConfiguration)); |
|
512
|
|
|
} |
|
513
|
138 |
|
|
|
514
|
|
|
/** |
|
515
|
138 |
|
* Applies the configured trigram phrase fields from the typoscript configuration to the query. |
|
516
|
|
|
* |
|
517
|
|
|
* @return QueryBuilder |
|
518
|
|
|
*/ |
|
519
|
|
|
public function useTrigramPhraseFieldsFromTypoScript(): QueryBuilder |
|
520
|
|
|
{ |
|
521
|
|
|
return $this->useTrigramPhraseFields(TrigramPhraseFields::fromTypoScriptConfiguration($this->typoScriptConfiguration)); |
|
522
|
|
|
} |
|
523
|
138 |
|
|
|
524
|
|
|
/** |
|
525
|
138 |
|
* Retrieves the configuration filters from the TypoScript configuration, except the __pageSections filter. |
|
526
|
|
|
* |
|
527
|
|
|
* @return array |
|
528
|
|
|
*/ |
|
529
|
|
|
public function getAdditionalFilters() : array |
|
530
|
|
|
{ |
|
531
|
|
|
// when we've build the additionalFilter once, we could return them |
|
532
|
|
|
if (count($this->additionalFilters) > 0) { |
|
533
|
145 |
|
return $this->additionalFilters; |
|
534
|
|
|
} |
|
535
|
|
|
|
|
536
|
145 |
|
$searchQueryFilters = $this->typoScriptConfiguration->getSearchQueryFilterConfiguration(); |
|
537
|
2 |
|
if (!is_array($searchQueryFilters) || count($searchQueryFilters) <= 0) { |
|
|
|
|
|
|
538
|
|
|
return []; |
|
539
|
|
|
} |
|
540
|
145 |
|
|
|
541
|
145 |
|
$cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class); |
|
542
|
142 |
|
|
|
543
|
|
|
// all other regular filters |
|
544
|
|
|
foreach ($searchQueryFilters as $filterKey => $filter) { |
|
545
|
4 |
|
// the __pageSections filter should not be handled as additional filter |
|
546
|
|
|
if ($filterKey === '__pageSections') { |
|
547
|
|
|
continue; |
|
548
|
4 |
|
} |
|
549
|
|
|
|
|
550
|
4 |
|
$filterIsArray = is_array($searchQueryFilters[$filterKey]); |
|
551
|
1 |
|
if ($filterIsArray) { |
|
552
|
|
|
continue; |
|
553
|
|
|
} |
|
554
|
3 |
|
|
|
555
|
3 |
|
$hasSubConfiguration = is_array($searchQueryFilters[$filterKey . '.']); |
|
556
|
|
|
if ($hasSubConfiguration) { |
|
557
|
|
|
$filter = $cObj->stdWrap($searchQueryFilters[$filterKey], $searchQueryFilters[$filterKey . '.']); |
|
558
|
|
|
} |
|
559
|
3 |
|
|
|
560
|
3 |
|
$this->additionalFilters[$filterKey] = $filter; |
|
561
|
|
|
} |
|
562
|
|
|
|
|
563
|
|
|
return $this->additionalFilters; |
|
564
|
3 |
|
} |
|
565
|
|
|
|
|
566
|
|
|
/** |
|
567
|
4 |
|
* @param string $rawQuery |
|
568
|
|
|
* @return SearchQuery |
|
569
|
|
|
*/ |
|
570
|
|
|
protected function getSearchQueryInstance($rawQuery): SearchQuery |
|
571
|
|
|
{ |
|
572
|
|
|
$query = GeneralUtility::makeInstance(SearchQuery::class); |
|
573
|
|
|
$query->setQuery($rawQuery); |
|
574
|
150 |
|
return $query; |
|
575
|
|
|
} |
|
576
|
150 |
|
|
|
577
|
150 |
|
/** |
|
578
|
150 |
|
* @param string $rawQuery |
|
579
|
|
|
* @return SuggestQuery |
|
580
|
|
|
*/ |
|
581
|
|
|
protected function getSuggestQueryInstance($rawQuery): SuggestQuery |
|
582
|
|
|
{ |
|
583
|
|
|
$query = GeneralUtility::makeInstance(SuggestQuery::class, /** @scrutinizer ignore-type */ $rawQuery, /** @scrutinizer ignore-type */ $this->typoScriptConfiguration); |
|
584
|
|
|
|
|
585
|
|
|
return $query; |
|
586
|
4 |
|
} |
|
587
|
|
|
} |
|
588
|
|
|
|