Passed
Pull Request — release-11.5.x (#3373)
by Rafael
41:25
created

getSuggestShowTopResults()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of the TYPO3 CMS project.
5
 *
6
 * It is free software; you can redistribute it and/or modify it under
7
 * the terms of the GNU General Public License, either version 2
8
 * of the License, or any later version.
9
 *
10
 * For the full copyright and license information, please read the
11
 * LICENSE.txt file that was distributed with this source code.
12
 *
13
 * The TYPO3 project - inspiring people to share!
14
 */
15
16
namespace ApacheSolrForTypo3\Solr\System\Configuration;
17
18
use ApacheSolrForTypo3\Solr\IndexQueue\Indexer;
19
use ApacheSolrForTypo3\Solr\IndexQueue\Initializer\Record;
20
use ApacheSolrForTypo3\Solr\System\ContentObject\ContentObjectService;
21
use ApacheSolrForTypo3\Solr\System\Util\ArrayAccessor;
22
use InvalidArgumentException;
23
use TYPO3\CMS\Core\Utility\ArrayUtility;
24
use TYPO3\CMS\Core\Utility\GeneralUtility;
25
26
/**
27
 * TypoScript configuration object, used to read all TypoScript configuration.
28
 *
29
 * The TypoScriptConfiguration was introduced in order to be able to replace the old,
30
 * array based configuration with one configuration object.
31
 *
32
 * To read the configuration, you should use
33
 *
34
 * $configuration->getValueByPath
35
 *
36
 * or
37
 *
38
 * $configuration->isValidPath
39
 *
40
 * to check if a configuration path exists.
41
 *
42
 * To ensure Backwards compatibility the TypoScriptConfiguration object implements the
43
 * ArrayAccess interface (offsetGet,offsetExists,offsetUnset and offsetSet)
44
 *
45
 * This was only introduced to be backwards compatible in long term only "getValueByPath", "isValidPath" or
46
 * speaking methods for configuration settings should be used!
47
 *
48
 * @author Marc Bastian Heinrichs <[email protected]>
49
 * @author Timo Schmidt <[email protected]>
50
 * @copyright (c) 2016 Timo Schmidt <[email protected]>
51
 */
52
class TypoScriptConfiguration
53
{
54
    /**
55
     * @var ArrayAccessor
56
     */
57
    protected ArrayAccessor $configurationAccess;
58
59
    /**
60
     * Holds the pageId in which context the configuration was parsed
61
     * (normally $GLOBALS['TSFE']->id)
62
     * @var int
63
     */
64
    protected int $contextPageId = 0;
65
66
    /**
67
     * @var ContentObjectService
68
     */
69
    protected ContentObjectService $contentObjectService;
70
71
    /**
72
     * @param array $configuration
73
     * @param int|null $contextPageId
74
     * @param ContentObjectService|null $contentObjectService
75
     */
76 459
    public function __construct(
77
        array $configuration,
78
        int $contextPageId = null,
79
        ContentObjectService $contentObjectService = null
80
    ) {
81 459
        $this->configurationAccess = new ArrayAccessor($configuration, '.', true);
82 459
        $this->contextPageId = $contextPageId ?? 0;
83 459
        $this->contentObjectService = $contentObjectService ?? GeneralUtility::makeInstance(ContentObjectService::class);
84
    }
85
86
    /**
87
     * Checks if a value is 1, '1', 'true'
88
     * @param mixed $value
89
     * @return bool
90
     */
91 323
    protected function getBool($value): bool
92
    {
93 323
        return filter_var($value, FILTER_VALIDATE_BOOLEAN);
94
    }
95
96
    /**
97
     * This method can be used to only retrieve array keys where the value is not an array.
98
     *
99
     * This can be very handy in the configuration when only keys should be taken into account
100
     * where the value is not a subconfiguration (typically a typoscript object path).
101
     *
102
     * @param $inputArray
103
     * @return array
104
     */
105 71
    protected function getOnlyArrayKeysWhereValueIsNotAnArray($inputArray): array
106
    {
107 71
        $keysWithNonArrayValue = [];
108
109 71
        foreach ($inputArray as $key => $value) {
110 43
            if (is_array($value)) {
111
                // configuration for a content object, skipping
112 10
                continue;
113
            }
114
115 43
            $keysWithNonArrayValue[] = $key;
116
        }
117
118 71
        return $keysWithNonArrayValue;
119
    }
120
121
    /**
122
     * Gets the value from a given TypoScript path.
123
     *
124
     * In the context of a frontend content element the path plugin.tx_solr is
125
     * merged recursive with overrule with the content element specific typoscript
126
     * settings, like plugin.tx_solr_PiResults_Results, and possible flex form settings
127
     * (depends on the solr plugin).
128
     *
129
     * Example: plugin.tx_solr.search.targetPage
130
     * returns $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_solr.']['search.']['targetPage']
131
     *
132
     * @param string $path TypoScript path
133
     * @return mixed The TypoScript object defined by the given path
134
     * @throws InvalidArgumentException
135
     */
136 350
    public function getValueByPath(string $path)
137
    {
138 350
        return $this->configurationAccess->get($path);
139
    }
140
141
    /**
142
     * This method can be used to get  a configuration value by path if it exists or return a
143
     * default value when it does not exist.
144
     *
145
     * @param string $path
146
     * @param mixed $defaultValue
147
     * @return mixed
148
     */
149 342
    public function getValueByPathOrDefaultValue(string $path, $defaultValue)
150
    {
151 342
        $value = $this->getValueByPath($path);
152 342
        if (is_null($value)) {
153 312
            return $defaultValue;
154
        }
155
156 217
        return $value;
157
    }
158
159
    /**
160
     * Gets the parent TypoScript Object from a given TypoScript path.
161
     *
162
     * In the context of a frontend content element the path plugin.tx_solr is
163
     * merged recursive with overrule with the content element specific typoscript
164
     * settings, like plugin.tx_solr_PiResults_Results, and possible flex form settings
165
     * (depends on the solr plugin).
166
     *
167
     * Example: plugin.tx_solr.index.queue.tt_news.fields.content
168
     * returns $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_solr.']['index.']['queue.']['tt_news.']['fields.']['content.']
169
     * which is a SOLR_CONTENT cObj.
170
     *
171
     * @param string $path TypoScript path
172
     * @return mixed The TypoScript object defined by the given path
173
     * @throws InvalidArgumentException
174
     */
175 320
    public function getObjectByPath(string $path)
176
    {
177 320
        if (substr($path, -1) !== '.') {
178 1
            $path = rtrim($path, '.');
179 1
            $path = substr($path, 0, strrpos($path, '.') + 1);
180
        }
181
182 320
        return $this->configurationAccess->get($path);
183
    }
184
185
    /**
186
     * Gets the parent TypoScript Object from a given TypoScript path and if not present return
187
     * the default value
188
     *
189
     * @param string $path
190
     * @param array $defaultValue
191
     * @return array
192
     * @see getObjectByPath()
193
     */
194 319
    public function getObjectByPathOrDefault(string $path, array $defaultValue = []): array
195
    {
196
        try {
197 319
            $object = $this->getObjectByPath($path);
198
        } catch (InvalidArgumentException $e) {
199
            return $defaultValue;
200
        }
201
202 319
        if (!is_array($object)) {
203 122
            return $defaultValue;
204
        }
205
206 240
        return $object;
207
    }
208
209
    /**
210
     * Checks whether a given TypoScript path is valid.
211
     *
212
     * @param string $path TypoScript path
213
     * @return bool TRUE if the path resolves, FALSE otherwise
214
     */
215
    public function isValidPath(string $path): bool
216
    {
217
        $isValidPath = false;
218
219
        $pathValue = $this->getValueByPath($path);
220
        if (!is_null($pathValue)) {
221
            $isValidPath = true;
222
        }
223
224
        return $isValidPath;
225
    }
226
227
    /**
228
     * Merges a configuration with another configuration a
229
     *
230
     * @param array $configurationToMerge
231
     * @param bool $addKeys If set to FALSE, keys that are NOT found in $original will not be set. Thus, only existing value can/will be overruled from overrule array.
232
     * @param bool $includeEmptyValues If set, values from $overrule will overrule if they are empty or zero.
233
     * @param bool $enableUnsetFeature If set, special values "__UNSET" can be used in overruled array in order to unset array keys in the original array.
234
     * @return TypoScriptConfiguration
235
     */
236 45
    public function mergeSolrConfiguration(array $configurationToMerge, bool $addKeys = true, bool $includeEmptyValues = true, bool $enableUnsetFeature = true): TypoScriptConfiguration
237
    {
238 45
        $data = $this->configurationAccess->getData();
239 45
        ArrayUtility::mergeRecursiveWithOverrule(
240 45
            $data['plugin.']['tx_solr.'],
241
            $configurationToMerge,
242
            $addKeys,
243
            $includeEmptyValues,
244
            $enableUnsetFeature
245
        );
246
247 45
        $this->configurationAccess->setData($data);
248
249 45
        return $this;
250
    }
251
252
    /**
253
     * Returns true when ext_solr is enabled
254
     *
255
     * @param bool $defaultIfEmpty
256
     * @return bool
257
     */
258 2
    public function getEnabled(bool $defaultIfEmpty = false): bool
259
    {
260 2
        $path = 'plugin.tx_solr.enabled';
261 2
        $result = $this->getValueByPathOrDefaultValue($path, $defaultIfEmpty);
262 2
        return $this->getBool($result);
263
    }
264
265
    /**
266
     * Returns the configured additionalFields configured for the indexing.
267
     *
268
     * plugin.tx_solr.index.additionalFields.
269
     *
270
     * @param array $defaultIfEmpty
271
     * @return array
272
     */
273 71
    public function getIndexAdditionalFieldsConfiguration(array $defaultIfEmpty = []): array
274
    {
275 71
        return $this->getObjectByPathOrDefault('plugin.tx_solr.index.additionalFields.', $defaultIfEmpty);
276
    }
277
278
    /**
279
     * Returns all solr fields names where a mapping is configured in index.additionalFields
280
     *
281
     * Returns all keys from
282
     * plugin.tx_solr.index.additionalFields.
283
     *
284
     * @param array $defaultIfEmpty
285
     * @return array
286
     */
287 70
    public function getIndexMappedAdditionalFieldNames(array $defaultIfEmpty = []): array
288
    {
289 70
        $mappingConfiguration = $this->getIndexAdditionalFieldsConfiguration();
290 70
        $mappedFieldNames = $this->getOnlyArrayKeysWhereValueIsNotAnArray($mappingConfiguration);
291 70
        return count($mappedFieldNames) == 0 ? $defaultIfEmpty : $mappedFieldNames;
292
    }
293
294
    /**
295
     * Returns the fieldProcessingInstructions configuration array
296
     *
297
     * plugin.tx_solr.index.fieldProcessingInstructions.
298
     *
299
     * @param array $defaultIfEmpty
300
     * @return array
301
     */
302 89
    public function getIndexFieldProcessingInstructionsConfiguration(array $defaultIfEmpty = []): array
303
    {
304 89
        return $this->getObjectByPathOrDefault('plugin.tx_solr.index.fieldProcessingInstructions.', $defaultIfEmpty);
305
    }
306
307
    /**
308
     * Retrieves the indexing configuration array for an indexing queue by configuration name.
309
     *
310
     * plugin.tx_solr.index.queue.<configurationName>.
311
     *
312
     * @param string $configurationName
313
     * @param array $defaultIfEmpty
314
     * @return array
315
     */
316 13
    public function getIndexQueueConfigurationByName(string $configurationName, array $defaultIfEmpty = []): array
317
    {
318 13
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.';
319 13
        return $this->getObjectByPathOrDefault($path, $defaultIfEmpty);
320
    }
321
322
    /**
323
     * Returns an array of all additionalPageIds by index configuration name.
324
     *
325
     * plugin.tx_solr.index.queue.pages.additionalPageIds
326
     *
327
     * @param string $configurationName
328
     * @param array $defaultIfEmpty
329
     * @return array
330
     */
331 67
    public function getIndexQueueAdditionalPageIdsByConfigurationName(string $configurationName = 'pages', array $defaultIfEmpty = []): array
332
    {
333 67
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.additionalPageIds';
334 67
        $result = $this->getValueByPathOrDefaultValue($path, '');
335 67
        if (trim($result) === '') {
336 58
            return $defaultIfEmpty;
337
        }
338
339 10
        return GeneralUtility::trimExplode(',', $result);
340
    }
341
342
    /**
343
     * Returns an array of all allowedPageTypes.
344
     *
345
     * plugin.tx_solr.index.queue.pages.allowedPageTypes
346
     *
347
     * @param string $configurationName The configuration name of the queue to use.
348
     * @param array $defaultIfEmpty
349
     * @return array
350
     */
351 54
    public function getIndexQueueAllowedPageTypesArrayByConfigurationName(string $configurationName = 'pages', array $defaultIfEmpty = []): array
352
    {
353 54
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.allowedPageTypes';
354 54
        $result = $this->getValueByPathOrDefaultValue($path, '');
355 54
        if (trim($result) === '') {
356
            return $defaultIfEmpty;
357
        }
358
359 54
        return GeneralUtility::trimExplode(',', $result);
360
    }
361
362
    /**
363
     * Returns the configured excludeContentByClass patterns as array.
364
     *
365
     * plugin.tx_solr.index.queue.pages.excludeContentByClass
366
     *
367
     * @param array $defaultIfEmpty
368
     * @return array
369
     */
370 53
    public function getIndexQueuePagesExcludeContentByClassArray(array $defaultIfEmpty = []): array
371
    {
372 53
        $path = 'plugin.tx_solr.index.queue.pages.excludeContentByClass';
373 53
        $result = $this->getValueByPathOrDefaultValue($path, '');
374
375 53
        if (trim($result) === '') {
376
            return $defaultIfEmpty;
377
        }
378
379 53
        return GeneralUtility::trimExplode(',', $result);
380
    }
381
382
    /**
383
     * Returns the configured database table for an indexing queue configuration or
384
     * the configurationName itself that is used by convention as tableName when no
385
     * other table name is present.
386
     *
387
     * plugin.tx_solr.index.queue.<configurationName>.table or configurationName
388
     *
389
     * @param string $configurationName
390
     * @return string
391
     * @deprecated queue.[indexConfig].table is deprecated and will be removed in v13. Use plugin.tx_solr.index.queue.[indexConfig].type instead
392
     */
393 1
    public function getIndexQueueTableNameOrFallbackToConfigurationName(string $configurationName = ''): string
394
    {
395 1
        trigger_error(
396
            'queue.[indexConfig].table is deprecated and will be removed in v13. Use plugin.tx_solr.index.queue.[indexConfig].type instead.',
397
            E_USER_DEPRECATED
398
        );
399
400 1
        return $this->getIndexQueueTypeOrFallbackToConfigurationName($configurationName);
401
    }
402
403
    /**
404
     * Returns the configured type for an indexing queue configuration (usally a db table) or
405
     * the configurationName itself that is used by convention as type when no
406
     * other type is present.
407
     *
408
     * plugin.tx_solr.index.queue.<configurationName>.type or configurationName
409
     *
410
     * @param string $configurationName
411
     * @return string
412
     */
413 103
    public function getIndexQueueTypeOrFallbackToConfigurationName(string $configurationName = ''): string
414
    {
415 103
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.type';
416 103
        $type = $this->getValueByPath($path);
417 103
        if (!is_null($type)) {
418 5
            return (string)$type;
419
        }
420
421
        // TODO: Remove fallback to "table" in v13
422 102
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.table';
423 102
        $type = $this->getValueByPath($path);
424 102
        if (!is_null($type)) {
425 33
            trigger_error(
426
                'queue.[indexConfig].table is deprecated and will be removed in v13. Use plugin.tx_solr.index.queue.[indexConfig].type instead.',
427
                E_USER_DEPRECATED
428
            );
429
430 33
            return (string)$type;
431
        }
432
433 85
        return $configurationName;
434
    }
435
436
    /**
437
     * Returns the field configuration for a specific index queue.
438
     *
439
     * plugin.tx_solr.index.queue.<configurationName>.fields.
440
     *
441
     * @param string $configurationName
442
     * @param array $defaultIfEmpty
443
     * @return array
444
     */
445 63
    public function getIndexQueueFieldsConfigurationByConfigurationName(string $configurationName = '', array $defaultIfEmpty = []): array
446
    {
447 63
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.fields.';
448 63
        return $this->getObjectByPathOrDefault($path, $defaultIfEmpty);
449
    }
450
451
    /**
452
     * Gets an array of tables configured for indexing by the Index Queue. Since the
453
     * record monitor must watch these tables for manipulation.
454
     *
455
     * @return array Array of table names to be watched by the record monitor.
456
     */
457 62
    public function getIndexQueueMonitoredTables(): array
458
    {
459 62
        $monitoredTables = [];
460
461 62
        $indexingConfigurations = $this->getEnabledIndexQueueConfigurationNames();
462 62
        foreach ($indexingConfigurations as $indexingConfigurationName) {
463 61
            $monitoredTable = $this->getIndexQueueTypeOrFallbackToConfigurationName($indexingConfigurationName);
464 61
            $monitoredTables[] = $monitoredTable;
465
        }
466
467 62
        return array_values(array_unique($monitoredTables));
468
    }
469
470
    /**
471
     * This method can be used to check if a table is configured to be monitored by the record monitor.
472
     *
473
     * @param string $tableName
474
     * @return bool
475
     */
476 61
    public function getIndexQueueIsMonitoredTable(string $tableName): bool
477
    {
478 61
        return in_array($tableName, $this->getIndexQueueMonitoredTables(), true);
479
    }
480
481
    /**
482
     * Returns the configured indexer class that should be used for a certain indexingConfiguration.
483
     * By default, "ApacheSolrForTypo3\Solr\IndexQueue\Indexer" will be returned.
484
     *
485
     * plugin.tx_solr.index.queue.<configurationName>.indexer
486
     *
487
     * @param string $configurationName
488
     * @param string $defaultIfEmpty
489
     * @return string
490
     */
491 2
    public function getIndexQueueIndexerByConfigurationName(string $configurationName, string $defaultIfEmpty = Indexer::class): string
492
    {
493 2
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.indexer';
494 2
        return (string)$this->getValueByPathOrDefaultValue($path, $defaultIfEmpty);
495
    }
496
497
    /**
498
     * Returns the configuration of an indexer for a special indexingConfiguration.
499
     * By default, an empty array is returned.
500
     *
501
     * plugin.tx_solr.index.queue.<configurationName>.indexer.
502
     *
503
     * @param string $configurationName
504
     * @param array $defaultIfEmpty
505
     * @return array
506
     */
507 2
    public function getIndexQueueIndexerConfigurationByConfigurationName(string $configurationName, array $defaultIfEmpty = []): array
508
    {
509 2
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.indexer.';
510 2
        return $this->getObjectByPathOrDefault($path, $defaultIfEmpty);
511
    }
512
513
    /**
514
     * Returns all solr fields names where a mapping configuration is set for a certain index configuration
515
     *
516
     * Returns all keys from
517
     * plugin.tx_solr.index.queue.<configurationName>.fields.
518
     *
519
     * @param string $configurationName
520
     * @param array $defaultIfEmpty
521
     * @return array
522
     */
523 42
    public function getIndexQueueMappedFieldsByConfigurationName(string $configurationName = '', array $defaultIfEmpty = []): array
524
    {
525 42
        $mappingConfiguration = $this->getIndexQueueFieldsConfigurationByConfigurationName($configurationName);
526 42
        $mappedFieldNames = $this->getOnlyArrayKeysWhereValueIsNotAnArray($mappingConfiguration);
527 42
        return count($mappedFieldNames) == 0 ? $defaultIfEmpty : $mappedFieldNames;
528
    }
529
530
    /**
531
     * This method is used to check if an index queue configuration is enabled or not
532
     *
533
     * plugin.tx_solr.index.queue.<configurationName> = 1
534
     *
535
     * @param string $configurationName
536
     * @param bool $defaultIfEmpty
537
     * @return bool
538
     */
539 91
    public function getIndexQueueConfigurationIsEnabled(string $configurationName, bool $defaultIfEmpty = false): bool
540
    {
541 91
        $path = 'plugin.tx_solr.index.queue.' . $configurationName;
542 91
        $result = $this->getValueByPathOrDefaultValue($path, $defaultIfEmpty);
543 91
        return $this->getBool($result);
544
    }
545
546
    /**
547
     * Retrieves an array of enabled index queue configurations.
548
     *
549
     * plugin.tx_solr.index.queue.<configurationName>
550
     *
551
     * @param array $defaultIfEmpty
552
     * @return array
553
     */
554 101
    public function getEnabledIndexQueueConfigurationNames(array $defaultIfEmpty = []): array
555
    {
556 101
        $tablesToIndex = [];
557 101
        $path = 'plugin.tx_solr.index.queue.';
558 101
        $indexQueueConfiguration = $this->getObjectByPathOrDefault($path, []);
559 101
        foreach ($indexQueueConfiguration as $configurationName => $indexingEnabled) {
560 98
            if (substr($configurationName, -1) != '.' && $indexingEnabled) {
561 98
                $tablesToIndex[] = $configurationName;
562
            }
563
        }
564
565 101
        return count($tablesToIndex) == 0 ? $defaultIfEmpty : $tablesToIndex;
566
    }
567
568
    /**
569
     * Retrieves an array of additional fields that will trigger a recursive update of pages
570
     * when some fields on that page are modified.
571
     *
572
     * plugin.tx_solr.index.queue.recursiveUpdateFields
573
     *
574
     * @param string $configurationName
575
     * @param array $defaultIfEmpty
576
     * @return array
577
     */
578 39
    public function getIndexQueueConfigurationRecursiveUpdateFields(string $configurationName, array $defaultIfEmpty = []): array
579
    {
580 39
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.recursiveUpdateFields';
581 39
        $recursiveUpdateFieldsString = $this->getValueByPathOrDefaultValue($path, '');
582 39
        if (trim($recursiveUpdateFieldsString) === '') {
583 30
            return $defaultIfEmpty;
584
        }
585 10
        $recursiveUpdateFields = GeneralUtility::trimExplode(',', $recursiveUpdateFieldsString);
586
        // For easier check later on we return an array by combining $recursiveUpdateFields
587 10
        return array_combine($recursiveUpdateFields, $recursiveUpdateFields);
588
    }
589
590
    /**
591
     * Retrieves and initialPagesAdditionalWhereClause where clause when configured or an empty string.
592
     *
593
     * plugin.tx_solr.index.queue.<configurationName>.initialPagesAdditionalWhereClause
594
     *
595
     * @param string $configurationName
596
     * @return string
597
     */
598 13
    public function getInitialPagesAdditionalWhereClause(string $configurationName): string
599
    {
600 13
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.initialPagesAdditionalWhereClause';
601 13
        $initialPagesAdditionalWhereClause = $this->getValueByPathOrDefaultValue($path, '');
602
603 13
        if (trim($initialPagesAdditionalWhereClause) === '') {
604 13
            return '';
605
        }
606
607 1
        return trim($initialPagesAdditionalWhereClause);
608
    }
609
610
    /**
611
     * Retrieves and additional where clause when configured or an empty string.
612
     *
613
     * plugin.tx_solr.index.queue.<configurationName>.additionalWhereClause
614
     *
615
     * @param string $configurationName
616
     * @return string
617
     */
618 94
    public function getIndexQueueAdditionalWhereClauseByConfigurationName(string $configurationName): string
619
    {
620 94
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.additionalWhereClause';
621 94
        $additionalWhere = $this->getValueByPathOrDefaultValue($path, '');
622
623 94
        if (trim($additionalWhere) === '') {
624 26
            return '';
625
        }
626
627 69
        return ' AND ' . $additionalWhere;
628
    }
629
630
    /**
631
     * This method can be used to retrieve all index queue configuration names, where
632
     * a certain table is used. It can be configured with the property "table" or is using the configuration
633
     * key a fallback for the table name.
634
     *
635
     * plugin.tx_solr.index.queue.<configurationName>.
636
     *
637
     * @param string $tableName
638
     * @param array $defaultIfEmpty
639
     * @return array
640
     */
641 1
    public function getIndexQueueConfigurationNamesByTableName(string $tableName, array $defaultIfEmpty = []): array
642
    {
643 1
        $path = 'plugin.tx_solr.index.queue.';
644 1
        $configuration = $this->getObjectByPathOrDefault($path, []);
645 1
        $possibleConfigurations = [];
646
647 1
        foreach ($configuration as $configurationName => $indexingEnabled) {
648 1
            $isObject = substr($configurationName, -1) === '.';
649 1
            if ($isObject || !$indexingEnabled) {
650 1
                continue;
651
            }
652
653 1
            $configuredType = $this->getIndexQueueTypeOrFallbackToConfigurationName($configurationName);
654 1
            if ($configuredType === $tableName) {
655 1
                $possibleConfigurations[] = $configurationName;
656
            }
657
        }
658
659 1
        return count($possibleConfigurations) > 0 ? $possibleConfigurations : $defaultIfEmpty;
660
    }
661
662
    /**
663
     * This method is used to retrieve the className of a queue initializer for a certain indexing configuration
664
     * of returns the default initializer class, when noting is configured.
665
     *
666
     * plugin.tx_solr.index.queue.<configurationName>.initialization
667
     *
668
     * @param string $configurationName
669
     * @param string $defaultIfEmpty
670
     * @return string
671
     */
672 7
    public function getIndexQueueInitializerClassByConfigurationName(string $configurationName, string $defaultIfEmpty = Record::class): string
673
    {
674 7
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.initialization';
675 7
        return (string)$this->getValueByPathOrDefaultValue($path, $defaultIfEmpty);
676
    }
677
678
    /**
679
     * Returns the _LOCAL_LANG configuration from the TypoScript.
680
     *
681
     * plugin.tx_solr._LOCAL_LANG.
682
     *
683
     * @param array $defaultIfEmpty
684
     * @return array
685
     */
686
    public function getLocalLangConfiguration(array $defaultIfEmpty = []): array
687
    {
688
        return $this->getObjectByPathOrDefault('plugin.tx_solr._LOCAL_LANG.', $defaultIfEmpty);
689
    }
690
691
    /**
692
     * When this is enabled the output of the devlog, will be printed as debug output.
693
     *
694
     * @param bool $defaultIfEmpty
695
     * @return bool
696
     */
697
    public function getLoggingDebugOutput(bool $defaultIfEmpty = false): bool
698
    {
699
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.debugOutput', $defaultIfEmpty);
700
        return $this->getBool($result);
701
    }
702
703
    /**
704
     * Returns if query filters should be written to the log.
705
     *
706
     * plugin.tx_solr.logging.query.filters
707
     *
708
     * @param bool $defaultIfEmpty
709
     * @return bool
710
     */
711
    public function getLoggingQueryFilters(bool $defaultIfEmpty = false): bool
712
    {
713
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.query.filters', $defaultIfEmpty);
714
        return $this->getBool($result);
715
    }
716
717
    /**
718
     * Returns if the querystring should be logged or not.
719
     *
720
     * plugin.tx_solr.logging.query.queryString
721
     *
722
     * @param bool $defaultIfEmpty
723
     * @return bool
724
     */
725 47
    public function getLoggingQueryQueryString(bool $defaultIfEmpty = false): bool
726
    {
727 47
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.query.queryString', $defaultIfEmpty);
728 47
        return $this->getBool($result);
729
    }
730
731
    /**
732
     * Returns if the searchWords should be logged or not.
733
     *
734
     * plugin.tx_solr.logging.query.searchWords
735
     *
736
     * @param bool $defaultIfEmpty
737
     * @return bool
738
     */
739 121
    public function getLoggingQuerySearchWords(bool $defaultIfEmpty = false): bool
740
    {
741 121
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.query.searchWords', $defaultIfEmpty);
742 121
        return $this->getBool($result);
743
    }
744
745
    /**
746
     * Returns if the rawGet requests should be logged or not.
747
     *
748
     * plugin.tx_solr.logging.query.rawGet
749
     *
750
     * @param bool $defaultIfEmpty
751
     * @return bool
752
     */
753
    public function getLoggingQueryRawGet(bool $defaultIfEmpty = false): bool
754
    {
755
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.query.rawGet', $defaultIfEmpty);
756
        return $this->getBool($result);
757
    }
758
759
    /**
760
     * Returns if the rawPost requests should be logged or not.
761
     *
762
     * plugin.tx_solr.logging.query.rawPost
763
     *
764
     * @param bool $defaultIfEmpty
765
     * @return bool
766
     */
767 22
    public function getLoggingQueryRawPost(bool $defaultIfEmpty = false): bool
768
    {
769 22
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.query.rawPost', $defaultIfEmpty);
770 22
        return $this->getBool($result);
771
    }
772
773
    /**
774
     * Returns if the rawDelete requests should be logged or not.
775
     *
776
     * plugin.tx_solr.logging.query.rawDelete
777
     *
778
     * @param bool $defaultIfEmpty
779
     * @return bool
780
     */
781
    public function getLoggingQueryRawDelete(bool $defaultIfEmpty = false): bool
782
    {
783
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.query.rawDelete', $defaultIfEmpty);
784
        return $this->getBool($result);
785
    }
786
787
    /**
788
     * Returns if exceptions should be logged or not.
789
     *
790
     * plugin.tx_solr.logging.exceptions
791
     *
792
     * @param bool $defaultIfEmpty
793
     * @return bool
794
     */
795
    public function getLoggingExceptions(bool $defaultIfEmpty = true): bool
796
    {
797
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.exceptions', $defaultIfEmpty);
798
        return $this->getBool($result);
799
    }
800
801
    /**
802
     * Returns if indexing operations should be logged or not.
803
     *
804
     * plugin.tx_solr.logging.indexing
805
     *
806
     * @param bool $defaultIfEmpty
807
     * @return bool
808
     */
809 22
    public function getLoggingIndexing(bool $defaultIfEmpty = false): bool
810
    {
811 22
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.indexing', $defaultIfEmpty);
812 22
        return $this->getBool($result);
813
    }
814
815
    /**
816
     * Returns if indexing queue operations should be logged or not.
817
     *
818
     * plugin.tx_solr.logging.indexing.queue
819
     *
820
     * @param bool $defaultIfEmpty
821
     * @return bool
822
     */
823 21
    public function getLoggingIndexingQueue(bool $defaultIfEmpty = false): bool
824
    {
825 21
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.indexing.queue', $defaultIfEmpty);
826 21
        return $this->getBool($result);
827
    }
828
829
    /**
830
     * This method can be used to check if the logging during indexing should be done.
831
     * It takes the specific configuration by indexQueueConfiguration into account or is using the
832
     * fallback when the logging is enabled on queue or indexing level.
833
     *
834
     * plugin.tx_solr.logging.indexing.queue.<indexQueueConfiguration>
835
     *
836
     * @param string $indexQueueConfiguration
837
     * @param bool $defaultIfEmpty
838
     * @return bool
839
     */
840 22
    public function getLoggingIndexingQueueOperationsByConfigurationNameWithFallBack(string $indexQueueConfiguration, bool $defaultIfEmpty = false): bool
841
    {
842
        // when logging is globally enabled we do not need to check the specific configuration
843 22
        if ($this->getLoggingIndexing()) {
844 1
            return true;
845
        }
846
847
        // when the logging for indexing is enabled on queue level we also do not need to check the specific configuration
848 21
        if ($this->getLoggingIndexingQueue()) {
849
            return true;
850
        }
851
852 21
        $path = 'plugin.tx_solr.logging.indexing.queue.' . $indexQueueConfiguration;
853 21
        $result = $this->getValueByPathOrDefaultValue($path, $defaultIfEmpty);
854 21
        return $this->getBool($result);
855
    }
856
857
    /**
858
     * Returns if a log message should be written when a page was indexed.
859
     *
860
     * plugin.tx_solr.logging.indexing.pageIndexed
861
     *
862
     * @param bool $defaultIfEmpty
863
     * @return bool
864
     */
865 10
    public function getLoggingIndexingPageIndexed(bool $defaultIfEmpty = false): bool
866
    {
867 10
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.indexing.pageIndexed', $defaultIfEmpty);
868 10
        return $this->getBool($result);
869
    }
870
871
    /**
872
     * Returns if a log message should be written when the TYPO3 search markers are missing in the page.
873
     *
874
     * plugin.tx_solr.logging.indexing.missingTypo3SearchMarkers
875
     *
876
     * @param bool $defaultIfEmpty
877
     * @return bool
878
     */
879 19
    public function getLoggingIndexingMissingTypo3SearchMarkers(bool $defaultIfEmpty = true): bool
880
    {
881 19
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.indexing.missingTypo3SearchMarkers', $defaultIfEmpty);
882 19
        return $this->getBool($result);
883
    }
884
885
    /**
886
     * Returns if the initialization of an indexqueue should be logged.
887
     *
888
     * plugin.tx_solr.logging.indexing.indexQueueInitialization
889
     *
890
     * @param bool $defaultIfEmpty
891
     * @return bool
892
     */
893 14
    public function getLoggingIndexingIndexQueueInitialization(bool $defaultIfEmpty = false): bool
894
    {
895 14
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.indexing.indexQueueInitialization', $defaultIfEmpty);
896 14
        return $this->getBool($result);
897
    }
898
899
    /**
900
     * Indicates if the debug mode is enabled or not.
901
     *
902
     * plugin.tx_solr.enableDebugMode
903
     *
904
     * @param bool $defaultIfEmpty
905
     * @return bool
906
     */
907 35
    public function getEnabledDebugMode(bool $defaultIfEmpty = false): bool
908
    {
909 35
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.enableDebugMode', $defaultIfEmpty);
910 35
        return $this->getBool($result);
911
    }
912
913
    /**
914
     * @param $path
915
     * @param $fallbackPath
916
     * @param $defaultIfBothIsEmpty
917
     * @return mixed
918
     */
919
    public function getValueByPathWithFallbackOrDefaultValueAndApplyStdWrap($path, $fallbackPath, $defaultIfBothIsEmpty)
920
    {
921
        $result = (string)$this->getValueByPathOrDefaultValue($path, '');
922
        if ($result !== '') {
923
            return $this->renderContentElementOfConfigured($path, $result);
924
        }
925
926
        $result = (string)$this->getValueByPathOrDefaultValue($fallbackPath, $defaultIfBothIsEmpty);
927
        return $this->renderContentElementOfConfigured($fallbackPath, $result);
928
    }
929
930
    /**
931
     * Retrieves the complete search configuration
932
     *
933
     * plugin.tx_solr.search.
934
     *
935
     * @param array $defaultIfEmpty
936
     * @return array
937
     */
938 48
    public function getSearchConfiguration(array $defaultIfEmpty = []): array
939
    {
940 48
        return $this->getObjectByPathOrDefault('plugin.tx_solr.search.', $defaultIfEmpty);
941
    }
942
943
    /**
944
     * Indicates if elevation should be used or not
945
     *
946
     * plugin.tx_solr.search.elevation
947
     *
948
     * @param bool $defaultIfEmpty
949
     * @return bool
950
     */
951 35
    public function getSearchElevation(bool $defaultIfEmpty = false): bool
952
    {
953 35
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.elevation', $defaultIfEmpty);
954 35
        return $this->getBool($result);
955
    }
956
957
    /**
958
     * Indicates if elevated results should be marked
959
     *
960
     * plugin.tx_solr.search.elevation.markElevatedResults
961
     *
962
     * @param bool $defaultIfEmpty
963
     * @return bool
964
     */
965
    public function getSearchElevationMarkElevatedResults(bool $defaultIfEmpty = true): bool
966
    {
967
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.elevation.markElevatedResults', $defaultIfEmpty);
968
        return $this->getBool($result);
969
    }
970
971
    /**
972
     * Indicates if elevation should be forced
973
     *
974
     *plugin.tx_solr.search.elevation.forceElevation
975
     *
976
     * @param bool $defaultIfEmpty
977
     * @return bool
978
     */
979
    public function getSearchElevationForceElevation(bool $defaultIfEmpty = true): bool
980
    {
981
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.elevation.forceElevation', $defaultIfEmpty);
982
        return $this->getBool($result);
983
    }
984
985
    /**
986
     * Indicates if collapsing on a certain field should be used to build variants or not.
987
     *
988
     * plugin.tx_solr.search.variants
989
     *
990
     * @param bool $defaultIfEmpty
991
     * @return bool
992
     */
993 121
    public function getSearchVariants(bool $defaultIfEmpty = false): bool
994
    {
995 121
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.variants', $defaultIfEmpty);
996 121
        return $this->getBool($result);
997
    }
998
999
    /**
1000
     * Indicates if collapsing on a certain field should be used or not
1001
     *
1002
     * plugin.tx_solr.search.variants.variantField
1003
     *
1004
     * @param string $defaultIfEmpty
1005
     * @return string
1006
     */
1007 6
    public function getSearchVariantsField(string $defaultIfEmpty = 'variantId'): string
1008
    {
1009 6
        return (string)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.variants.variantField', $defaultIfEmpty);
1010
    }
1011
1012
    /**
1013
     * Indicates if expanding of collapsed items it activated.
1014
     *
1015
     * plugin.tx_solr.search.variants.expand
1016
     *
1017
     * @param bool $defaultIfEmpty
1018
     * @return bool
1019
     */
1020 6
    public function getSearchVariantsExpand(bool $defaultIfEmpty = false): bool
1021
    {
1022 6
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.variants.expand', $defaultIfEmpty);
1023 6
        return $this->getBool($result);
1024
    }
1025
1026
    /**
1027
     * Retrieves the number of elements that should be expanded.
1028
     *
1029
     * plugin.tx_solr.search.variants.limit
1030
     *
1031
     * @param int $defaultIfEmpty
1032
     * @return int
1033
     */
1034 6
    public function getSearchVariantsLimit(int $defaultIfEmpty = 10): int
1035
    {
1036 6
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.variants.limit', $defaultIfEmpty);
1037 6
        return (int)$result;
1038
    }
1039
1040
    /**
1041
     * Indicates if frequent searches should be show or not.
1042
     *
1043
     * plugin.tx_solr.search.frequentSearches
1044
     *
1045
     * @param bool $defaultIfEmpty
1046
     * @return bool
1047
     */
1048 28
    public function getSearchFrequentSearches(bool $defaultIfEmpty = false): bool
1049
    {
1050 28
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.frequentSearches', $defaultIfEmpty);
1051 28
        return $this->getBool($result);
1052
    }
1053
1054
    /**
1055
     * Returns the sub configuration of the frequentSearches
1056
     *
1057
     * plugin.tx_solr.search.frequentSearches.
1058
     *
1059
     * @param array $defaultIfEmpty
1060
     * @return array
1061
     */
1062
    public function getSearchFrequentSearchesConfiguration(array $defaultIfEmpty = []): array
1063
    {
1064
        return $this->getObjectByPathOrDefault('plugin.tx_solr.search.frequentSearches.', $defaultIfEmpty);
1065
    }
1066
1067
    /**
1068
     * Retrieves the minimum font size that should be used for the frequentSearches.
1069
     *
1070
     * plugin.tx_solr.search.frequentSearches.minSize
1071
     *
1072
     * @param int $defaultIfEmpty
1073
     * @return int
1074
     */
1075
    public function getSearchFrequentSearchesMinSize(int $defaultIfEmpty = 14): int
1076
    {
1077
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.frequentSearches.minSize', $defaultIfEmpty);
1078
        return (int)$result;
1079
    }
1080
1081
    /**
1082
     * Retrieves the maximum font size that should be used for the frequentSearches.
1083
     *
1084
     * plugin.tx_solr.search.frequentSearches.minSize
1085
     *
1086
     * @param int $defaultIfEmpty
1087
     * @return int
1088
     */
1089
    public function getSearchFrequentSearchesMaxSize(int $defaultIfEmpty = 32): int
1090
    {
1091
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.frequentSearches.maxSize', $defaultIfEmpty);
1092
        return (int)$result;
1093
    }
1094
1095
    /**
1096
     * Indicates if frequent searches should be show or not.
1097
     *
1098
     * plugin.tx_solr.search.frequentSearches.useLowercaseKeywords
1099
     *
1100
     * @param bool $defaultIfEmpty
1101
     * @return bool
1102
     */
1103
    public function getSearchFrequentSearchesUseLowercaseKeywords(bool $defaultIfEmpty = false): bool
1104
    {
1105
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.frequentSearches.useLowercaseKeywords', $defaultIfEmpty);
1106
        return $this->getBool($result);
1107
    }
1108
1109
    /**
1110
     * Returns the configuration if the search should be initialized with an empty query.
1111
     *
1112
     * plugin.tx_solr.search.initializeWithEmptyQuery
1113
     *
1114
     * @param bool $defaultIfEmpty
1115
     * @return bool
1116
     */
1117 127
    public function getSearchInitializeWithEmptyQuery(bool $defaultIfEmpty = false): bool
1118
    {
1119 127
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.initializeWithEmptyQuery', $defaultIfEmpty);
1120 127
        return $this->getBool($result);
1121
    }
1122
1123
    /**
1124
     * Returns the configured initial query
1125
     *
1126
     * plugin.tx_solr.search.initializeWithQuery
1127
     *
1128
     * @param string $defaultIfEmpty
1129
     * @return string
1130
     */
1131 127
    public function getSearchInitializeWithQuery(string $defaultIfEmpty = ''): string
1132
    {
1133 127
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.initializeWithQuery', $defaultIfEmpty);
1134 127
        return (string)$result;
1135
    }
1136
1137
    /**
1138
     * Returns if the last searches should be displayed or not.
1139
     *
1140
     * plugin.tx_solr.search.lastSearches
1141
     *
1142
     * @param bool $defaultIfEmpty
1143
     * @return bool
1144
     */
1145 28
    public function getSearchLastSearches(bool $defaultIfEmpty = false): bool
1146
    {
1147 28
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.lastSearches', $defaultIfEmpty);
1148 28
        return $this->getBool($result);
1149
    }
1150
1151
    /**
1152
     * Returns the lastSearch mode. "user" for user specific
1153
     *
1154
     * plugin.tx_solr.search.lastSearches.mode
1155
     *
1156
     * @param string $defaultIfEmpty
1157
     * @return string
1158
     */
1159 2
    public function getSearchLastSearchesMode(string $defaultIfEmpty = 'user'): string
1160
    {
1161 2
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.lastSearches.mode', $defaultIfEmpty);
1162 2
        return (string)$result;
1163
    }
1164
1165
    /**
1166
     * Returns the lastSearch limit
1167
     *
1168
     * plugin.tx_solr.search.lastSearches.limit
1169
     *
1170
     * @param int $defaultIfEmpty
1171
     * @return int
1172
     */
1173 2
    public function getSearchLastSearchesLimit(int $defaultIfEmpty = 10): int
1174
    {
1175 2
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.lastSearches.limit', $defaultIfEmpty);
1176 2
        return (int)$result;
1177
    }
1178
1179
    /**
1180
     * Indicates if the results of an initial empty query should be shown or not.
1181
     *
1182
     * plugin.tx_solr.search.showResultsOfInitialEmptyQuery
1183
     *
1184
     * @param bool $defaultIfEmpty
1185
     * @return bool
1186
     */
1187 10
    public function getSearchShowResultsOfInitialEmptyQuery(bool $defaultIfEmpty = false): bool
1188
    {
1189 10
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.showResultsOfInitialEmptyQuery', $defaultIfEmpty);
1190 10
        return $this->getBool($result);
1191
    }
1192
1193
    /**
1194
     * Indicates if the results of an initial search query should be shown.
1195
     *
1196
     * plugin.tx_solr.search.showResultsOfInitialQuery
1197
     *
1198
     * @param bool $defaultIfEmpty
1199
     * @return bool
1200
     */
1201 7
    public function getSearchShowResultsOfInitialQuery(bool $defaultIfEmpty = false): bool
1202
    {
1203 7
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.showResultsOfInitialQuery', $defaultIfEmpty);
1204 7
        return $this->getBool($result);
1205
    }
1206
1207
    /**
1208
     * Indicates if sorting was enabled or not.
1209
     *
1210
     * plugin.tx_solr.search.sorting
1211
     *
1212
     * @param bool $defaultIfEmpty
1213
     * @return bool
1214
     */
1215 64
    public function getSearchSorting(bool $defaultIfEmpty = false): bool
1216
    {
1217 64
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.sorting', $defaultIfEmpty);
1218 64
        return $this->getBool($result);
1219
    }
1220
1221
    /**
1222
     * Returns the sorting options configurations.
1223
     *
1224
     * plugin.tx_solr.search.sorting.options.
1225
     *
1226
     * @param array $defaultIfEmpty
1227
     * @return array
1228
     */
1229 2
    public function getSearchSortingOptionsConfiguration(array $defaultIfEmpty = []): array
1230
    {
1231 2
        return $this->getObjectByPathOrDefault('plugin.tx_solr.search.sorting.options.', $defaultIfEmpty);
1232
    }
1233
1234
    /**
1235
     * Retrieves the sorting default order for a sort option.
1236
     *
1237
     * plugin.tx_solr.search.sorting.options.<sortOptionName>.defaultOrder
1238
     *
1239
     * or
1240
     *
1241
     * plugin.tx_solr.search.sorting.defaultOrder
1242
     *
1243
     *
1244
     * @param string $sortOptionName
1245
     * @param string $defaultIfEmpty
1246
     * @return string
1247
     */
1248 5
    public function getSearchSortingDefaultOrderBySortOptionName(string $sortOptionName = '', string $defaultIfEmpty = 'asc'): string
1249
    {
1250 5
        $sortOrderSpecificPath = 'plugin.tx_solr.search.sorting.options.' . $sortOptionName . '.defaultOrder';
1251 5
        $specificSortOrder = $this->getValueByPathOrDefaultValue($sortOrderSpecificPath, null);
1252
1253
        // if we have a concrete setting, use it
1254 5
        if ($specificSortOrder !== null) {
1255 2
            return mb_strtolower($specificSortOrder);
1256
        }
1257
1258
        // no specific setting, check common setting
1259 3
        $commonPath = 'plugin.tx_solr.search.sorting.defaultOrder';
1260 3
        $commonATagParamOrDefaultValue = $this->getValueByPathOrDefaultValue($commonPath, $defaultIfEmpty);
1261 3
        return mb_strtolower($commonATagParamOrDefaultValue);
1262
    }
1263
1264
    /**
1265
     * Returns the trusted fields configured for the search that do not need to be escaped.
1266
     *
1267
     * @param array $defaultIfEmpty
1268
     * @return array
1269
     */
1270 9
    public function getSearchTrustedFieldsArray(array $defaultIfEmpty = ['url']): array
1271
    {
1272 9
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.trustedFields', '');
1273
1274 9
        if (trim($result) === '') {
1275 3
            return $defaultIfEmpty;
1276
        }
1277
1278 6
        return GeneralUtility::trimExplode(',', $result);
1279
    }
1280
1281
    /**
1282
     * Indicates if the plugin arguments should be kept in the search form for a second submission.
1283
     *
1284
     * plugin.tx_solr.search.keepExistingParametersForNewSearches
1285
     *
1286
     * @param bool $defaultIfEmpty
1287
     * @return bool
1288
     */
1289 29
    public function getSearchKeepExistingParametersForNewSearches(bool $defaultIfEmpty = false): bool
1290
    {
1291 29
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.keepExistingParametersForNewSearches', $defaultIfEmpty);
1292 29
        return $this->getBool($result);
1293
    }
1294
1295
    /**
1296
     * Returns if an empty query is allowed on the query level.
1297
     *
1298
     * plugin.tx_solr.search.query.allowEmptyQuery
1299
     *
1300
     * @param string $defaultIfEmpty
1301
     * @return bool
1302
     */
1303 118
    public function getSearchQueryAllowEmptyQuery(string $defaultIfEmpty = ''): bool
1304
    {
1305 118
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.query.allowEmptyQuery', $defaultIfEmpty);
1306 118
        return $this->getBool($result);
1307
    }
1308
1309
    /**
1310
     * Returns the filter configuration array
1311
     *
1312
     * plugin.tx_solr.search.query.filter.
1313
     *
1314
     * @param array $defaultIfEmpty
1315
     * @return array
1316
     */
1317 126
    public function getSearchQueryFilterConfiguration(array $defaultIfEmpty = []): array
1318
    {
1319 126
        return $this->getObjectByPathOrDefault('plugin.tx_solr.search.query.filter.', $defaultIfEmpty);
1320
    }
1321
1322
    /**
1323
     * Can be used to overwrite the filterConfiguration.
1324
     *
1325
     * plugin.tx_solr.search.query.filter.
1326
     *
1327
     * @param array $configuration
1328
     */
1329 1
    public function setSearchQueryFilterConfiguration(array $configuration)
1330
    {
1331 1
        $this->configurationAccess->set('plugin.tx_solr.search.query.filter.', $configuration);
1332
    }
1333
1334
    /**
1335
     * Removes the pageSections filter setting.
1336
     */
1337 3
    public function removeSearchQueryFilterForPageSections()
1338
    {
1339 3
        $this->configurationAccess->reset('plugin.tx_solr.search.query.filter.__pageSections');
1340
    }
1341
1342
    /**
1343
     * Returns the configured queryFields from TypoScript
1344
     *
1345
     * plugin.tx_solr.search.query.queryFields
1346
     *
1347
     * @param string $defaultIfEmpty
1348
     * @return string
1349
     */
1350 121
    public function getSearchQueryQueryFields(string $defaultIfEmpty = ''): string
1351
    {
1352 121
        return (string)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.query.queryFields', $defaultIfEmpty);
1353
    }
1354
1355
    /**
1356
     * This method is used to check if a phrase search is enabled or not
1357
     *
1358
     * plugin.tx_solr.search.query.phrase = 1
1359
     *
1360
     * @param bool $defaultIfEmpty
1361
     * @return bool
1362
     */
1363 121
    public function getPhraseSearchIsEnabled(bool $defaultIfEmpty = false): bool
1364
    {
1365 121
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.query.phrase', $defaultIfEmpty);
1366 121
        return $this->getBool($result);
1367
    }
1368
1369
    /**
1370
     * Returns the configured phrase fields from TypoScript
1371
     *
1372
     * plugin.tx_solr.search.query.phrase.fields
1373
     *
1374
     * @param string $defaultIfEmpty
1375
     * @return string
1376
     */
1377 2
    public function getSearchQueryPhraseFields(string $defaultIfEmpty = ''): string
1378
    {
1379 2
        return (string)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.query.phrase.fields', $defaultIfEmpty);
1380
    }
1381
1382
    /**
1383
     * This method is used to check if a bigram phrase search is enabled or not
1384
     *
1385
     * plugin.tx_solr.search.query.bigramPhrase = 1
1386
     *
1387
     * @param bool $defaultIfEmpty
1388
     * @return bool
1389
     */
1390 121
    public function getBigramPhraseSearchIsEnabled(bool $defaultIfEmpty = false): bool
1391
    {
1392 121
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.query.bigramPhrase', $defaultIfEmpty);
1393 121
        return $this->getBool($result);
1394
    }
1395
1396
    /**
1397
     * Returns the configured phrase fields from TypoScript
1398
     *
1399
     * plugin.tx_solr.search.query.bigramPhrase.fields
1400
     *
1401
     * @param string $defaultIfEmpty
1402
     * @return string
1403
     */
1404 2
    public function getSearchQueryBigramPhraseFields(string $defaultIfEmpty = ''): string
1405
    {
1406 2
        return (string)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.query.bigramPhrase.fields', $defaultIfEmpty);
1407
    }
1408
1409
    /**
1410
     * This method is used to check if a trigram phrase search is enabled or not
1411
     *
1412
     * plugin.tx_solr.search.query.trigramPhrase = 1
1413
     *
1414
     * @param bool $defaultIfEmpty
1415
     * @return bool
1416
     */
1417 121
    public function getTrigramPhraseSearchIsEnabled(bool $defaultIfEmpty = false): bool
1418
    {
1419 121
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.query.trigramPhrase', $defaultIfEmpty);
1420 121
        return $this->getBool($result);
1421
    }
1422
1423
    /**
1424
     * Returns the configured trigram phrase fields from TypoScript
1425
     *
1426
     * plugin.tx_solr.search.query.trigramPhrase.fields
1427
     *
1428
     * @param string $defaultIfEmpty
1429
     * @return string
1430
     */
1431 2
    public function getSearchQueryTrigramPhraseFields(string $defaultIfEmpty = ''): string
1432
    {
1433 2
        return (string)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.query.trigramPhrase.fields', $defaultIfEmpty);
1434
    }
1435
1436
    /**
1437
     * Returns the configured returnFields as array.
1438
     *
1439
     * plugin.tx_solr.search.query.returnFields
1440
     *
1441
     * @param array $defaultIfEmpty
1442
     * @return array
1443
     */
1444 123
    public function getSearchQueryReturnFieldsAsArray(array $defaultIfEmpty = []): array
1445
    {
1446 123
        $returnFields = $this->getValueByPath('plugin.tx_solr.search.query.returnFields');
1447 123
        if (is_null($returnFields)) {
1448 86
            return $defaultIfEmpty;
1449
        }
1450
1451 37
        return GeneralUtility::trimExplode(',', $returnFields);
1452
    }
1453
1454
    /**
1455
     * Returns the configured target page for the search.
1456
     * By default, the contextPageId will be used
1457
     *
1458
     * plugin.tx_solr.search.targetPage
1459
     *
1460
     * @return int
1461
     */
1462 29
    public function getSearchTargetPage(): int
1463
    {
1464 29
        $targetPage = (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.targetPage', 0);
1465 29
        if ($targetPage === 0) {
1466
            // when no specific page was configured we use the contextPageId (which is usual $GLOBALS['TSFE']->id)
1467 29
            $targetPage = $this->contextPageId;
1468
        }
1469
1470 29
        return $targetPage;
1471
    }
1472
1473
    /**
1474
     * Retrieves the targetPage configuration.
1475
     *
1476
     * plugin.tx_solr.search.targetPage.
1477
     *
1478
     * @param array $defaultIfEmpty
1479
     * @return array
1480
     */
1481
    public function getSearchTargetPageConfiguration(array $defaultIfEmpty = []): array
1482
    {
1483
        return $this->getObjectByPathOrDefault('plugin.tx_solr.search.targetPage.', $defaultIfEmpty);
1484
    }
1485
1486
    /**
1487
     * Method to check if the site highlighting is enabled. When the siteHighlighting is enabled the
1488
     * sword_list parameter is added to the results link.
1489
     *
1490
     * plugin.tx_solr.search.results.siteHighlighting
1491
     *
1492
     * @param bool $defaultIfEmpty
1493
     * @return bool
1494
     */
1495 22
    public function getSearchResultsSiteHighlighting(bool $defaultIfEmpty = true): bool
1496
    {
1497 22
        $isSiteHighlightingEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.siteHighlighting', $defaultIfEmpty);
1498 22
        return $this->getBool($isSiteHighlightingEnabled);
1499
    }
1500
1501
    /**
1502
     * Can be used to check if the highlighting is enabled
1503
     *
1504
     * plugin.tx_solr.search.results.resultsHighlighting
1505
     *
1506
     * @param bool $defaultIfEmpty
1507
     * @return bool
1508
     */
1509 121
    public function getIsSearchResultsHighlightingEnabled(bool $defaultIfEmpty = false): bool
1510
    {
1511 121
        $isHighlightingEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.resultsHighlighting', $defaultIfEmpty);
1512 121
        return $this->getBool($isHighlightingEnabled);
1513
    }
1514
1515
    /**
1516
     * Returns the result highlighting fields.
1517
     *
1518
     * plugin.tx_solr.search.results.resultsHighlighting.highlightFields
1519
     *
1520
     * @param string $defaultIfEmpty
1521
     * @return string
1522
     */
1523 8
    public function getSearchResultsHighlightingFields(string $defaultIfEmpty = ''): string
1524
    {
1525 8
        return (string)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.resultsHighlighting.highlightFields', $defaultIfEmpty);
1526
    }
1527
1528
    /**
1529
     * Returns the result highlighting fields as array.
1530
     *
1531
     * plugin.tx_solr.search.results.resultsHighlighting.highlightFields
1532
     *
1533
     * @param array $defaultIfEmpty
1534
     * @return array
1535
     */
1536
    public function getSearchResultsHighlightingFieldsAsArray(array $defaultIfEmpty = []): array
1537
    {
1538
        $highlightingFields = $this->getSearchResultsHighlightingFields();
1539
1540
        if ($highlightingFields === '') {
1541
            return $defaultIfEmpty;
1542
        }
1543
1544
        return GeneralUtility::trimExplode(',', $highlightingFields, true);
1545
    }
1546
1547
    /**
1548
     * Returns the fragmentSize for highlighted segments.
1549
     *
1550
     * plugin.tx_solr.search.results.resultsHighlighting.fragmentSize
1551
     *
1552
     * @param int $defaultIfEmpty
1553
     * @return int
1554
     */
1555 8
    public function getSearchResultsHighlightingFragmentSize(int $defaultIfEmpty = 200): int
1556
    {
1557 8
        return (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.resultsHighlighting.fragmentSize', $defaultIfEmpty);
1558
    }
1559
1560
    /**
1561
     * Returns the fragmentSeparator for highlighted segments.
1562
     *
1563
     * plugin.tx_solr.search.results.resultsHighlighting.fragmentSeparator
1564
     *
1565
     * @param string $defaultIfEmpty
1566
     * @return string
1567
     */
1568 22
    public function getSearchResultsHighlightingFragmentSeparator(string $defaultIfEmpty = '[...]'): string
1569
    {
1570 22
        return (string)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.resultsHighlighting.fragmentSeparator', $defaultIfEmpty);
1571
    }
1572
1573
    /**
1574
     * Returns the number of results that should be shown per page.
1575
     *
1576
     * plugin.tx_solr.search.results.resultsPerPage
1577
     *
1578
     * @param int $defaultIfEmpty
1579
     * @return int
1580
     */
1581 33
    public function getSearchResultsPerPage(int $defaultIfEmpty = 10): int
1582
    {
1583 33
        return (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.resultsPerPage', $defaultIfEmpty);
1584
    }
1585
1586
    /**
1587
     * Returns the available options for the per page switch.
1588
     *
1589
     * plugin.tx_solr.search.results.resultsPerPageSwitchOptions
1590
     *
1591
     * @param array $defaultIfEmpty
1592
     * @return array
1593
     */
1594 33
    public function getSearchResultsPerPageSwitchOptionsAsArray(array $defaultIfEmpty = []): array
1595
    {
1596 33
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.resultsPerPageSwitchOptions', '');
1597
1598 33
        if (trim($result) === '') {
1599
            return $defaultIfEmpty;
1600
        }
1601
1602 33
        return GeneralUtility::intExplode(',', $result, true);
1603
    }
1604
1605
    /**
1606
     * Returns the maximum number of links shown in the paginator.
1607
     *
1608
     * plugin.tx_solr.search.results.maxPaginatorLinks
1609
     *
1610
     * @param int $defaultIfEmpty
1611
     * @return int
1612
     */
1613 33
    public function getMaxPaginatorLinks(int $defaultIfEmpty = 0): int
1614
    {
1615 33
        return (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.maxPaginatorLinks', $defaultIfEmpty);
1616
    }
1617
1618
    /**
1619
     * Returns the configured wrap for the resultHighlighting.
1620
     *
1621
     * plugin.tx_solr.search.results.resultsHighlighting.wrap
1622
     *
1623
     * @param string $defaultIfEmpty
1624
     * @return string
1625
     */
1626 30
    public function getSearchResultsHighlightingWrap(string $defaultIfEmpty = ''): string
1627
    {
1628 30
        return (string)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.resultsHighlighting.wrap', $defaultIfEmpty);
1629
    }
1630
1631
    /**
1632
     * Indicates if spellchecking is enabled or not.
1633
     *
1634
     * plugin.tx_solr.search.spellchecking
1635
     *
1636
     * @param bool $defaultIfEmpty
1637
     * @return bool
1638
     */
1639 3
    public function getSearchSpellchecking(bool $defaultIfEmpty = false): bool
1640
    {
1641 3
        $isFacetingEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.spellchecking', $defaultIfEmpty);
1642 3
        return $this->getBool($isFacetingEnabled);
1643
    }
1644
1645
    /**
1646
     * Returns the numberOfSuggestionsToTry that should be used for the spellchecking.
1647
     *
1648
     * plugin.tx_solr.search.spellchecking.numberOfSuggestionsToTry
1649
     *
1650
     * @param int $defaultIfEmpty
1651
     * @return int
1652
     */
1653 3
    public function getSearchSpellcheckingNumberOfSuggestionsToTry(int $defaultIfEmpty = 1): int
1654
    {
1655 3
        return (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.spellchecking.numberOfSuggestionsToTry', $defaultIfEmpty);
1656
    }
1657
1658
    /**
1659
     * Indicates if a second search should be fired from the spellchecking suggestion if no results could be found.
1660
     *
1661
     * plugin.tx_solr.search.spellchecking.searchUsingSpellCheckerSuggestion
1662
     *
1663
     * @param bool $defaultIfEmpty
1664
     * @return bool
1665
     */
1666 35
    public function getSearchSpellcheckingSearchUsingSpellCheckerSuggestion(bool $defaultIfEmpty = false): bool
1667
    {
1668 35
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.spellchecking.searchUsingSpellCheckerSuggestion', $defaultIfEmpty);
1669 35
        return $this->getBool($result);
1670
    }
1671
1672
    /**
1673
     * Indicates if faceting is enabled or not.
1674
     *
1675
     * plugin.tx_solr.search.faceting
1676
     *
1677
     * @param bool $defaultIfEmpty
1678
     * @return bool
1679
     */
1680 121
    public function getSearchFaceting(bool $defaultIfEmpty = false): bool
1681
    {
1682 121
        $isFacetingEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting', $defaultIfEmpty);
1683 121
        return $this->getBool($isFacetingEnabled);
1684
    }
1685
1686
    /**
1687
     * Retrieves the showEvenWhenEmpty for a facet by facet name. If nothing specific is configured
1688
     * the global showEmptyFacets with be returned.
1689
     *
1690
     * plugin.tx_solr.search.faceting.facets.<facetName>.showEvenWhenEmpty
1691
     *
1692
     * or
1693
     *
1694
     * plugin.tx_solr.search.faceting.showEmptyFacets
1695
     *
1696
     *
1697
     * @param string $facetName
1698
     * @param bool $defaultIfEmpty
1699
     * @return bool
1700
     */
1701 54
    public function getSearchFacetingShowEmptyFacetsByName(string $facetName = '', bool $defaultIfEmpty = false): bool
1702
    {
1703 54
        $facetSpecificPath = 'plugin.tx_solr.search.faceting.facets.' . $facetName . '.showEvenWhenEmpty';
1704 54
        $specificShowWhenEmpty = $this->getValueByPathOrDefaultValue($facetSpecificPath, null);
1705
1706
        // if we have a concrete setting, use it
1707 54
        if ($specificShowWhenEmpty !== null) {
1708 2
            return $this->getBool($specificShowWhenEmpty);
1709
        }
1710
1711
        // no specific setting, check common setting
1712 54
        $commonPath = 'plugin.tx_solr.search.faceting.showEmptyFacets';
1713 54
        return $this->getBool($this->getValueByPathOrDefaultValue($commonPath, $defaultIfEmpty));
1714
    }
1715
1716
    /**
1717
     * Returns the wrap for the faceting show all link
1718
     *
1719
     * plugin.tx_solr.search.faceting.showAllLink.wrap
1720
     *
1721
     * @param string $defaultIfEmpty
1722
     * @return string
1723
     */
1724
    public function getSearchFacetingShowAllLinkWrap(string $defaultIfEmpty = ''): string
1725
    {
1726
        return (string)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.showAllLink.wrap', $defaultIfEmpty);
1727
    }
1728
1729
    /**
1730
     * Returns the link url parameters that should be added to a facet.
1731
     *
1732
     * plugin.tx_solr.search.faceting.facetLinkUrlParameters
1733
     *
1734
     * @param string $defaultIfEmpty
1735
     * @return string
1736
     */
1737 16
    public function getSearchFacetingFacetLinkUrlParameters(string $defaultIfEmpty = ''): string
1738
    {
1739 16
        return trim($this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.facetLinkUrlParameters', $defaultIfEmpty));
1740
    }
1741
1742
    /**
1743
     * Returns if the facetLinkUrlsParameters should be included in the reset link.
1744
     *
1745
     * plugin.tx_solr.search.faceting.facetLinkUrlParameters.useForFacetResetLinkUrl
1746
     *
1747
     * @param bool $defaultIfEmpty
1748
     * @return bool
1749
     */
1750 4
    public function getSearchFacetingFacetLinkUrlParametersUseForFacetResetLinkUrl(bool $defaultIfEmpty = true): bool
1751
    {
1752 4
        $useForFacetResetLinkUrl = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.facetLinkUrlParameters.useForFacetResetLinkUrl', $defaultIfEmpty);
1753 4
        return $this->getBool($useForFacetResetLinkUrl);
1754
    }
1755
1756
    /**
1757
     * Returns the link url parameters that should be added to a facet as array.
1758
     *
1759
     * plugin.tx_solr.search.faceting.facetLinkUrlParameters
1760
     *
1761
     * @param array $defaultIfEmpty
1762
     * @return array
1763
     */
1764 16
    public function getSearchFacetingFacetLinkUrlParametersAsArray(array $defaultIfEmpty = []): array
1765
    {
1766 16
        $linkUrlParameters = $this->getSearchFacetingFacetLinkUrlParameters();
1767 16
        if ($linkUrlParameters === '') {
1768 16
            return $defaultIfEmpty;
1769
        }
1770
1771
        return GeneralUtility::explodeUrl2Array($linkUrlParameters);
1772
    }
1773
1774
    /**
1775
     * Return the configured minimumCount value for facets.
1776
     *
1777
     * plugin.tx_solr.search.faceting.minimumCount
1778
     *
1779
     * @param int $defaultIfEmpty
1780
     * @return int
1781
     */
1782 32
    public function getSearchFacetingMinimumCount(int $defaultIfEmpty = 1): int
1783
    {
1784 32
        return (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.minimumCount', $defaultIfEmpty);
1785
    }
1786
1787
    /**
1788
     * Return the configured limit value for facets, used for displaying.
1789
     *
1790
     * plugin.tx_solr.search.faceting.limit
1791
     *
1792
     * @param int $defaultIfEmpty
1793
     * @return int
1794
     */
1795
    public function getSearchFacetingLimit(int $defaultIfEmpty = 10): int
1796
    {
1797
        return (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.limit', $defaultIfEmpty);
1798
    }
1799
1800
    /**
1801
     * Return the configured limit value for facets, used for the response.
1802
     *
1803
     * plugin.tx_solr.search.faceting.facetLimit
1804
     *
1805
     * @param int $defaultIfEmpty
1806
     * @return int
1807
     */
1808 32
    public function getSearchFacetingFacetLimit(int $defaultIfEmpty = 100): int
1809
    {
1810 32
        return (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.facetLimit', $defaultIfEmpty);
1811
    }
1812
1813
    /**
1814
     * Return the configured url parameter style value for facets, used for building faceting parameters.
1815
     *
1816
     * plugin.tx_solr.search.faceting.urlParameterStyle
1817
     *
1818
     * @param string $defaultUrlParameterStyle
1819
     * @return string
1820
     */
1821 48
    public function getSearchFacetingUrlParameterStyle(string $defaultUrlParameterStyle = 'index'): string
1822
    {
1823 48
        return (string)$this->getValueByPathOrDefaultValue(
1824
            'plugin.tx_solr.search.faceting.urlParameterStyle',
1825
            $defaultUrlParameterStyle
1826
        );
1827
    }
1828
1829
    /**
1830
     * Return the configuration if the URL parameters should be sorted.
1831
     *
1832
     * plugin.tx_solr.search.faceting.urlParameterSort
1833
     *
1834
     * @param bool $defaultUrlParameterSort
1835
     * @return bool
1836
     */
1837 41
    public function getSearchFacetingUrlParameterSort(bool $defaultUrlParameterSort = false): bool
1838
    {
1839 41
        return (bool)$this->getValueByPathOrDefaultValue(
1840
            'plugin.tx_solr.search.faceting.urlParameterSort',
1841
            $defaultUrlParameterSort
1842
        );
1843
    }
1844
1845
    /**
1846
     * Return the configured faceting sortBy value.
1847
     *
1848
     * plugin.tx_solr.search.faceting.sortBy
1849
     *
1850
     * @param string $defaultIfEmpty
1851
     * @return string
1852
     */
1853 32
    public function getSearchFacetingSortBy(string $defaultIfEmpty = ''): string
1854
    {
1855 32
        return (string)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.sortBy', $defaultIfEmpty);
1856
    }
1857
1858
    /**
1859
     * Returns if a facets should be kept on selection. Global faceting setting
1860
     * can also be configured on facet level by using
1861
     * (plugin.tx_solr.search.faceting.facets.<fieldName>.keepAllOptionsOnSelection)
1862
     *
1863
     * plugin.tx_solr.search.faceting.keepAllFacetsOnSelection
1864
     *
1865
     * @param bool $defaultIfEmpty
1866
     * @return bool
1867
     */
1868 32
    public function getSearchFacetingKeepAllFacetsOnSelection(bool $defaultIfEmpty = false): bool
1869
    {
1870 32
        $keepAllOptionsOnSelection = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.keepAllFacetsOnSelection', $defaultIfEmpty);
1871 32
        return $this->getBool($keepAllOptionsOnSelection);
1872
    }
1873
1874
    /**
1875
     * Returns if the facet count should be calculated based on the facet selection when
1876
     * plugin.tx_solr.search.faceting.keepAllFacetsOnSelection has been enabled
1877
     *
1878
     * plugin.tx_solr.search.faceting.countAllFacetsForSelection
1879
     *
1880
     * @param bool $defaultIfEmpty
1881
     * @return bool
1882
     */
1883 5
    public function getSearchFacetingCountAllFacetsForSelection(bool $defaultIfEmpty = false): bool
1884
    {
1885 5
        $countAllFacetsForSelection = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.countAllFacetsForSelection', $defaultIfEmpty);
1886 5
        return $this->getBool($countAllFacetsForSelection);
1887
    }
1888
1889
    /**
1890
     * Returns the configured faceting configuration.
1891
     *
1892
     * plugin.tx_solr.search.faceting.facets
1893
     *
1894
     * @param array $defaultIfEmpty
1895
     * @return array
1896
     */
1897 59
    public function getSearchFacetingFacets(array $defaultIfEmpty = []): array
1898
    {
1899 59
        return $this->getObjectByPathOrDefault('plugin.tx_solr.search.faceting.facets.', $defaultIfEmpty);
1900
    }
1901
1902
    /**
1903
     * Returns the configuration of a single facet by facet name.
1904
     *
1905
     * plugin.tx_solr.search.faceting.facets.<facetName>
1906
     *
1907
     * @param string $facetName
1908
     * @param array $defaultIfEmpty
1909
     * @return array
1910
     */
1911 32
    public function getSearchFacetingFacetByName(string $facetName, array $defaultIfEmpty = []): array
1912
    {
1913 32
        return $this->getObjectByPathOrDefault('plugin.tx_solr.search.faceting.facets.' . $facetName . '.', $defaultIfEmpty);
1914
    }
1915
1916
    /**
1917
     * Indicates if statistics is enabled or not.
1918
     *
1919
     * plugin.tx_solr.statistics
1920
     *
1921
     * @param bool $defaultIfEmpty
1922
     * @return bool
1923
     */
1924 37
    public function getStatistics(bool $defaultIfEmpty = false): bool
1925
    {
1926 37
        $isStatisticsEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.statistics', $defaultIfEmpty);
1927 37
        return $this->getBool($isStatisticsEnabled);
1928
    }
1929
1930
    /**
1931
     * Indicates to which length an ip should be anonymized in the statistics
1932
     *
1933
     * plugin.tx_solr.statistics.anonymizeIP
1934
     *
1935
     * @param int $defaultIfEmpty
1936
     * @return int
1937
     */
1938
    public function getStatisticsAnonymizeIP(int $defaultIfEmpty = 0): int
1939
    {
1940
        $anonymizeToLength = $this->getValueByPathOrDefaultValue('plugin.tx_solr.statistics.anonymizeIP', $defaultIfEmpty);
1941
        return (int)$anonymizeToLength;
1942
    }
1943
1944
    /**
1945
     * Indicates if additional debug Data should be added to the statistics
1946
     *
1947
     * plugin.tx_solr.statistics.addDebugData
1948
     *
1949
     * @param bool $defaultIfEmpty
1950
     * @return bool
1951
     */
1952 2
    public function getStatisticsAddDebugData(bool $defaultIfEmpty = false): bool
1953
    {
1954 2
        $statisticsAddDebugDataEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.statistics.addDebugData', $defaultIfEmpty);
1955 2
        return $this->getBool($statisticsAddDebugDataEnabled);
1956
    }
1957
1958
    /**
1959
     * Indicates if suggestion is enabled or not.
1960
     *
1961
     * plugin.tx_solr.suggest
1962
     *
1963
     * @param bool $defaultIfEmpty
1964
     * @return bool
1965
     */
1966
    public function getSuggest(bool $defaultIfEmpty = false): bool
1967
    {
1968
        $isSuggestionEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.suggest', $defaultIfEmpty);
1969
        return $this->getBool($isSuggestionEnabled);
1970
    }
1971
1972
    /**
1973
     * Indicates if https should be used for the suggestions form.
1974
     *
1975
     * plugin.tx_solr.suggest.forceHttps
1976
     *
1977
     * @param bool $defaultIfEmpty
1978
     * @return bool
1979
     */
1980
    public function getSuggestForceHttps(bool $defaultIfEmpty = false): bool
1981
    {
1982
        $isHttpsForced = $this->getValueByPathOrDefaultValue('plugin.tx_solr.suggest.forceHttps', $defaultIfEmpty);
1983
        return $this->getBool($isHttpsForced);
1984
    }
1985
1986
    /**
1987
     * Returns the allowed number of suggestions.
1988
     *
1989
     * plugin.tx_solr.suggest.numberOfSuggestions
1990
     *
1991
     * @param int $defaultIfEmpty
1992
     * @return int
1993
     */
1994 3
    public function getSuggestNumberOfSuggestions(int $defaultIfEmpty = 10): int
1995
    {
1996 3
        $numberOfSuggestions = $this->getValueByPathOrDefaultValue('plugin.tx_solr.suggest.numberOfSuggestions', $defaultIfEmpty);
1997 3
        return (int)$numberOfSuggestions;
1998
    }
1999
2000
    /**
2001
     * Indicates if the topResults should be shown or not
2002
     *
2003
     * plugin.tx_solr.suggest.showTopResults
2004
     *
2005
     * @param bool $defaultIfEmpty
2006
     * @return bool
2007
     */
2008 3
    public function getSuggestShowTopResults(bool $defaultIfEmpty = true): bool
2009
    {
2010 3
        $showTopResults = $this->getValueByPathOrDefaultValue('plugin.tx_solr.suggest.showTopResults', $defaultIfEmpty);
2011 3
        return $this->getBool($showTopResults);
2012
    }
2013
2014
    /**
2015
     * Returns the configured number of top results to show
2016
     *
2017
     * plugin.tx_solr.suggest.numberOfTopResults
2018
     *
2019
     * @param int $defaultIfEmpty
2020
     * @return int
2021
     */
2022 3
    public function getSuggestNumberOfTopResults(int $defaultIfEmpty = 5): int
2023
    {
2024 3
        $numberOfTopResults = $this->getValueByPathOrDefaultValue('plugin.tx_solr.suggest.numberOfTopResults', $defaultIfEmpty);
2025 3
        return (int)$numberOfTopResults;
2026
    }
2027
2028
    /**
2029
     * Returns additional fields for the top results
2030
     *
2031
     * plugin.tx_solr.suggest.additionalTopResultsFields
2032
     *
2033
     * @param array $defaultIfEmpty
2034
     * @return array
2035
     */
2036 3
    public function getSuggestAdditionalTopResultsFields(array $defaultIfEmpty = []): array
2037
    {
2038 3
        $additionalTopResultsFields = $this->getValueByPathOrDefaultValue('plugin.tx_solr.suggest.additionalTopResultsFields', '');
2039 3
        if ($additionalTopResultsFields === '') {
2040 3
            return $defaultIfEmpty;
2041
        }
2042
2043
        return GeneralUtility::trimExplode(',', $additionalTopResultsFields, true);
2044
    }
2045
2046
    /**
2047
     * Returns the configured template for a specific template fileKey.
2048
     *
2049
     * plugin.tx_solr.view.templateFiles.<fileKey>
2050
     *
2051
     * @param string $fileKey
2052
     * @param string $defaultIfEmpty
2053
     * @return string
2054
     */
2055 35
    public function getViewTemplateByFileKey(string $fileKey, string $defaultIfEmpty = ''): string
2056
    {
2057 35
        $templateFileName = $this->getValueByPathOrDefaultValue('plugin.tx_solr.view.templateFiles.' . $fileKey, $defaultIfEmpty);
2058 35
        return (string)$templateFileName;
2059
    }
2060
2061
    /**
2062
     * Returns the configured available template files for the flexform.
2063
     *
2064
     * plugin.tx_solr.view.templateFiles.[fileKey].availableTemplates.
2065
     *
2066
     * @param string $fileKey
2067
     * @return array
2068
     */
2069
    public function getAvailableTemplatesByFileKey(string $fileKey): array
2070
    {
2071
        return $this->getObjectByPathOrDefault('plugin.tx_solr.view.templateFiles.' . $fileKey . '.availableTemplates.', []);
2072
    }
2073
2074
    /**
2075
     * Returns the configuration of the crop view helper.
2076
     *
2077
     * plugin.tx_solr.viewHelpers.crop.
2078
     *
2079
     * @param array $defaultIfEmpty
2080
     * @return array
2081
     */
2082
    public function getViewHelpersCropConfiguration(array $defaultIfEmpty = []): array
2083
    {
2084
        return $this->getObjectByPathOrDefault('plugin.tx_solr.viewHelpers.crop.', $defaultIfEmpty);
2085
    }
2086
2087
    /**
2088
     * Returns the configuration of the sorting view helper.
2089
     *
2090
     * plugin.tx_solr.viewHelpers.sortIndicator.
2091
     *
2092
     * @param array $defaultIfEmpty
2093
     * @return array
2094
     */
2095
    public function getViewHelpersSortIndicatorConfiguration(array $defaultIfEmpty = []): array
2096
    {
2097
        return $this->getObjectByPathOrDefault('plugin.tx_solr.viewHelpers.sortIndicator.', $defaultIfEmpty);
2098
    }
2099
2100
    /**
2101
     * Controls whether ext-solr will send commits to solr.
2102
     * Beware: If you disable this, you need to ensure
2103
     * that some other mechanism will commit your changes
2104
     * otherwise they will never be searchable.
2105
     * A good way to achieve this is enabling the solr
2106
     * daemons autoCommit feature.
2107
     *
2108
     * plugin.tx_solr.index.enableCommits
2109
     *
2110
     * @param bool $defaultIfEmpty
2111
     * @return bool
2112
     */
2113 22
    public function getEnableCommits(bool $defaultIfEmpty = true): bool
2114
    {
2115 22
        $enableCommits = $this->getValueByPathOrDefaultValue('plugin.tx_solr.index.enableCommits', $defaultIfEmpty);
2116 22
        return $this->getBool($enableCommits);
2117
    }
2118
2119
    /**
2120
     * Returns the url namespace that is used for the arguments.
2121
     *
2122
     * plugin.tx_solr.view.pluginNamespace
2123
     *
2124
     * @param string $defaultIfEmpty
2125
     * @return string
2126
     */
2127 42
    public function getSearchPluginNamespace(string $defaultIfEmpty = 'tx_solr'): string
2128
    {
2129 42
        return (string)$this->getValueByPathOrDefaultValue('plugin.tx_solr.view.pluginNamespace', $defaultIfEmpty);
2130
    }
2131
2132
    /**
2133
     * Returns true if the global url parameter q, that indicates the query should be used.
2134
     *
2135
     * Should be set to false, when multiple instance on the same page should have their querystring.
2136
     *
2137
     * plugin.tx_solr.search.ignoreGlobalQParameter
2138
     *
2139
     * @param bool $defaultIfEmpty
2140
     * @return bool
2141
     */
2142 1
    public function getSearchIgnoreGlobalQParameter(bool $defaultIfEmpty = false): bool
2143
    {
2144 1
        $enableQParameter = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.ignoreGlobalQParameter', $defaultIfEmpty);
2145 1
        return $this->getBool($enableQParameter);
2146
    }
2147
2148
    /**
2149
     * Returns the argument names, that should be added to the persistent arguments, as array.
2150
     *
2151
     * plugin.tx_solr.search.additionalPersistentArgumentNames
2152
     *
2153
     * @param array $defaultIfEmpty
2154
     * @return array
2155
     */
2156 43
    public function getSearchAdditionalPersistentArgumentNames(array $defaultIfEmpty = []): array
2157
    {
2158 43
        $additionalPersistentArgumentNames = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.additionalPersistentArgumentNames', '');
2159
2160 43
        if ($additionalPersistentArgumentNames === '') {
2161 42
            return $defaultIfEmpty;
2162
        }
2163
2164 1
        return GeneralUtility::trimExplode(',', $additionalPersistentArgumentNames, true);
2165
    }
2166
2167
    /**
2168
     * Method to check if grouping was enabled with typoscript.
2169
     *
2170
     * plugin.tx_solr.search.grouping
2171
     *
2172
     * @param bool $defaultIfEmpty
2173
     * @return bool
2174
     */
2175 123
    public function getIsSearchGroupingEnabled(bool $defaultIfEmpty = false): bool
2176
    {
2177 123
        $groupingEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.grouping', $defaultIfEmpty);
2178 123
        return $this->getBool($groupingEnabled);
2179
    }
2180
2181
    /**
2182
     * Returns the configured numberOfGroups.
2183
     *
2184
     * plugin.tx_solr.search.grouping.numberOfGroups
2185
     *
2186
     * @param int $defaultIfEmpty
2187
     * @return int
2188
     */
2189 1
    public function getSearchGroupingNumberOfGroups(int $defaultIfEmpty = 5): int
2190
    {
2191 1
        return (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.grouping.numberOfGroups', $defaultIfEmpty);
2192
    }
2193
2194
    /**
2195
     * Returns the sortBy configuration for the grouping.
2196
     *
2197
     * plugin.tx_solr.search.grouping.sortBy
2198
     *
2199
     * @param string $defaultIfEmpty
2200
     * @return string
2201
     */
2202 1
    public function getSearchGroupingSortBy(string $defaultIfEmpty = ''): string
2203
    {
2204 1
        return (string)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.grouping.sortBy', $defaultIfEmpty);
2205
    }
2206
2207
    /**
2208
     * Returns the highestValue of the numberOfResultsPerGroup configuration that is globally configured and
2209
     * for each group.
2210
     *
2211
     * plugin.tx_solr.search.grouping.
2212
     *
2213
     * @param ?int $defaultIfEmpty
2214
     * @return int
2215
     */
2216 3
    public function getSearchGroupingHighestGroupResultsLimit(?int $defaultIfEmpty = 1): int
2217
    {
2218 3
        $groupingConfiguration = $this->getObjectByPathOrDefault('plugin.tx_solr.search.grouping.', []);
2219 3
        $highestLimit = $defaultIfEmpty;
2220 3
        if (!empty($groupingConfiguration['numberOfResultsPerGroup'])) {
2221 2
            $highestLimit = $groupingConfiguration['numberOfResultsPerGroup'];
2222
        }
2223
2224 3
        if (!isset($groupingConfiguration['groups.']) || !is_array($groupingConfiguration['groups.'])) {
2225 1
            return $highestLimit;
2226
        }
2227
2228 2
        foreach ($groupingConfiguration['groups.'] as $groupConfiguration) {
2229 2
            if (!empty($groupConfiguration['numberOfResultsPerGroup']) && $groupConfiguration['numberOfResultsPerGroup'] > $highestLimit) {
2230 1
                $highestLimit = $groupConfiguration['numberOfResultsPerGroup'];
2231
            }
2232
        }
2233
2234 2
        return $highestLimit;
2235
    }
2236
2237
    /**
2238
     * Returns the valid numberOfResultsPerGroup value for a group.
2239
     *
2240
     * Returns:
2241
     *
2242
     * plugin.tx_solr.search.grouping.groups.<groupName>.numberOfResultsPerGroup if it is set otherwise
2243
     * plugin.tx_solr.search.grouping.numberOfResultsPerGroup
2244
     *
2245
     * @param string $groupName
2246
     * @param ?int $defaultIfEmpty
2247
     * @return int
2248
     */
2249
    public function getSearchGroupingResultLimit(string $groupName, ?int $defaultIfEmpty = 1): ?int
2250
    {
2251
        $specificPath = 'plugin.tx_solr.search.grouping.groups.' . $groupName . '.numberOfResultsPerGroup';
2252
        $specificResultsPerGroup = $this->getValueByPathOrDefaultValue($specificPath, null);
2253
2254
        if ($specificResultsPerGroup !== null) {
2255
            return (int)$specificResultsPerGroup;
2256
        }
2257
2258
        $commonPath = 'plugin.tx_solr.search.grouping.numberOfResultsPerGroup';
2259
        $commonValue = $this->getValueByPathOrDefaultValue($commonPath, null);
2260
        if ($commonValue !== null) {
2261
            return (int)$commonValue;
2262
        }
2263
2264
        return $defaultIfEmpty;
2265
    }
2266
2267
    /**
2268
     * Returns everything that is configured for the groups (plugin.tx_solr.search.grouping.groups.)
2269
     *
2270
     * plugin.tx_solr.search.grouping.groups.
2271
     *
2272
     * @param ?array $defaultIfEmpty
2273
     * @return array
2274
     */
2275 1
    public function getSearchGroupingGroupsConfiguration(?array $defaultIfEmpty = []): array
2276
    {
2277 1
        return $this->getObjectByPathOrDefault('plugin.tx_solr.search.grouping.groups.', $defaultIfEmpty);
2278
    }
2279
2280
    /*
2281
     * Applies the stdWrap if it is configured for the path, otherwise the unprocessed value will be returned.
2282
     *
2283
     * @param string $valuePath
2284
     * @param mixed $value
2285
     * @return mixed
2286
     */
2287
    protected function renderContentElementOfConfigured($valuePath, $value)
2288
    {
2289
        $configurationPath = $valuePath . '.';
2290
        $configuration = $this->getObjectByPath($configurationPath);
2291
2292
        if ($configuration == null) {
2293
            return $value;
2294
        }
2295
2296
        return $this->contentObjectService->renderSingleContentObject($value, $configuration);
2297
    }
2298
}
2299