Passed
Pull Request — main (#3532)
by Markus
44:05
created

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