Passed
Push — release-11.5.x ( 0d2d76...f14861 )
by Markus
34:30 queued 29:55
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
    * Retrieves indexingPriority when configured or 0.
708
    *
709
    * plugin.tx_solr.index.queue.<configurationName>.indexingPriority
710
    *
711
    * @param string $configurationName
712
    * @param int $defaultIfEmpty
713
    * @return int
714
    */
715 87
    public function getIndexQueueIndexingPriorityByConfigurationName(string $configurationName, int $defaultIfEmpty = 0): int
716
    {
717 87
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.indexingPriority';
718 87
        return (int)$this->getValueByPathOrDefaultValue($path, $defaultIfEmpty);
719
    }
720
721
    /**
722
     * Returns the _LOCAL_LANG configuration from the TypoScript.
723
     *
724
     * plugin.tx_solr._LOCAL_LANG.
725
     *
726
     * @param array $defaultIfEmpty
727
     * @return array
728
     */
729
    public function getLocalLangConfiguration(array $defaultIfEmpty = []): array
730
    {
731
        return $this->getObjectByPathOrDefault('plugin.tx_solr._LOCAL_LANG.', $defaultIfEmpty);
732
    }
733
734
    /**
735
     * When this is enabled the output of the devlog, will be printed as debug output.
736
     *
737
     * @param bool $defaultIfEmpty
738
     * @return bool
739
     */
740
    public function getLoggingDebugOutput(bool $defaultIfEmpty = false): bool
741
    {
742
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.debugOutput', $defaultIfEmpty);
743
        return $this->getBool($result);
744
    }
745
746
    /**
747
     * Returns if query filters should be written to the log.
748
     *
749
     * plugin.tx_solr.logging.query.filters
750
     *
751
     * @param bool $defaultIfEmpty
752
     * @return bool
753
     */
754
    public function getLoggingQueryFilters(bool $defaultIfEmpty = false): bool
755
    {
756
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.query.filters', $defaultIfEmpty);
757
        return $this->getBool($result);
758
    }
759
760
    /**
761
     * Returns if the querystring should be logged or not.
762
     *
763
     * plugin.tx_solr.logging.query.queryString
764
     *
765
     * @param bool $defaultIfEmpty
766
     * @return bool
767
     */
768 47
    public function getLoggingQueryQueryString(bool $defaultIfEmpty = false): bool
769
    {
770 47
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.query.queryString', $defaultIfEmpty);
771 47
        return $this->getBool($result);
772
    }
773
774
    /**
775
     * Returns if the searchWords should be logged or not.
776
     *
777
     * plugin.tx_solr.logging.query.searchWords
778
     *
779
     * @param bool $defaultIfEmpty
780
     * @return bool
781
     */
782 121
    public function getLoggingQuerySearchWords(bool $defaultIfEmpty = false): bool
783
    {
784 121
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.query.searchWords', $defaultIfEmpty);
785 121
        return $this->getBool($result);
786
    }
787
788
    /**
789
     * Returns if the rawGet requests should be logged or not.
790
     *
791
     * plugin.tx_solr.logging.query.rawGet
792
     *
793
     * @param bool $defaultIfEmpty
794
     * @return bool
795
     */
796
    public function getLoggingQueryRawGet(bool $defaultIfEmpty = false): bool
797
    {
798
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.query.rawGet', $defaultIfEmpty);
799
        return $this->getBool($result);
800
    }
801
802
    /**
803
     * Returns if the rawPost requests should be logged or not.
804
     *
805
     * plugin.tx_solr.logging.query.rawPost
806
     *
807
     * @param bool $defaultIfEmpty
808
     * @return bool
809
     */
810 22
    public function getLoggingQueryRawPost(bool $defaultIfEmpty = false): bool
811
    {
812 22
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.query.rawPost', $defaultIfEmpty);
813 22
        return $this->getBool($result);
814
    }
815
816
    /**
817
     * Returns if the rawDelete requests should be logged or not.
818
     *
819
     * plugin.tx_solr.logging.query.rawDelete
820
     *
821
     * @param bool $defaultIfEmpty
822
     * @return bool
823
     */
824
    public function getLoggingQueryRawDelete(bool $defaultIfEmpty = false): bool
825
    {
826
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.query.rawDelete', $defaultIfEmpty);
827
        return $this->getBool($result);
828
    }
829
830
    /**
831
     * Returns if exceptions should be logged or not.
832
     *
833
     * plugin.tx_solr.logging.exceptions
834
     *
835
     * @param bool $defaultIfEmpty
836
     * @return bool
837
     */
838
    public function getLoggingExceptions(bool $defaultIfEmpty = true): bool
839
    {
840
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.exceptions', $defaultIfEmpty);
841
        return $this->getBool($result);
842
    }
843
844
    /**
845
     * Returns if indexing operations should be logged or not.
846
     *
847
     * plugin.tx_solr.logging.indexing
848
     *
849
     * @param bool $defaultIfEmpty
850
     * @return bool
851
     */
852 22
    public function getLoggingIndexing(bool $defaultIfEmpty = false): bool
853
    {
854 22
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.indexing', $defaultIfEmpty);
855 22
        return $this->getBool($result);
856
    }
857
858
    /**
859
     * Returns if indexing queue operations should be logged or not.
860
     *
861
     * plugin.tx_solr.logging.indexing.queue
862
     *
863
     * @param bool $defaultIfEmpty
864
     * @return bool
865
     */
866 21
    public function getLoggingIndexingQueue(bool $defaultIfEmpty = false): bool
867
    {
868 21
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.indexing.queue', $defaultIfEmpty);
869 21
        return $this->getBool($result);
870
    }
871
872
    /**
873
     * This method can be used to check if the logging during indexing should be done.
874
     * It takes the specific configuration by indexQueueConfiguration into account or is using the
875
     * fallback when the logging is enabled on queue or indexing level.
876
     *
877
     * plugin.tx_solr.logging.indexing.queue.<indexQueueConfiguration>
878
     *
879
     * @param string $indexQueueConfiguration
880
     * @param bool $defaultIfEmpty
881
     * @return bool
882
     */
883 22
    public function getLoggingIndexingQueueOperationsByConfigurationNameWithFallBack(string $indexQueueConfiguration, bool $defaultIfEmpty = false): bool
884
    {
885
        // when logging is globally enabled we do not need to check the specific configuration
886 22
        if ($this->getLoggingIndexing()) {
887 1
            return true;
888
        }
889
890
        // when the logging for indexing is enabled on queue level we also do not need to check the specific configuration
891 21
        if ($this->getLoggingIndexingQueue()) {
892
            return true;
893
        }
894
895 21
        $path = 'plugin.tx_solr.logging.indexing.queue.' . $indexQueueConfiguration;
896 21
        $result = $this->getValueByPathOrDefaultValue($path, $defaultIfEmpty);
897 21
        return $this->getBool($result);
898
    }
899
900
    /**
901
     * Returns if a log message should be written when a page was indexed.
902
     *
903
     * plugin.tx_solr.logging.indexing.pageIndexed
904
     *
905
     * @param bool $defaultIfEmpty
906
     * @return bool
907
     */
908 10
    public function getLoggingIndexingPageIndexed(bool $defaultIfEmpty = false): bool
909
    {
910 10
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.indexing.pageIndexed', $defaultIfEmpty);
911 10
        return $this->getBool($result);
912
    }
913
914
    /**
915
     * Returns if a log message should be written when the TYPO3 search markers are missing in the page.
916
     *
917
     * plugin.tx_solr.logging.indexing.missingTypo3SearchMarkers
918
     *
919
     * @param bool $defaultIfEmpty
920
     * @return bool
921
     */
922 19
    public function getLoggingIndexingMissingTypo3SearchMarkers(bool $defaultIfEmpty = true): bool
923
    {
924 19
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.indexing.missingTypo3SearchMarkers', $defaultIfEmpty);
925 19
        return $this->getBool($result);
926
    }
927
928
    /**
929
     * Returns if the initialization of an indexqueue should be logged.
930
     *
931
     * plugin.tx_solr.logging.indexing.indexQueueInitialization
932
     *
933
     * @param bool $defaultIfEmpty
934
     * @return bool
935
     */
936 14
    public function getLoggingIndexingIndexQueueInitialization(bool $defaultIfEmpty = false): bool
937
    {
938 14
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.indexing.indexQueueInitialization', $defaultIfEmpty);
939 14
        return $this->getBool($result);
940
    }
941
942
    /**
943
     * Indicates if the debug mode is enabled or not.
944
     *
945
     * plugin.tx_solr.enableDebugMode
946
     *
947
     * @param bool $defaultIfEmpty
948
     * @return bool
949
     */
950 35
    public function getEnabledDebugMode(bool $defaultIfEmpty = false): bool
951
    {
952 35
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.enableDebugMode', $defaultIfEmpty);
953 35
        return $this->getBool($result);
954
    }
955
956
    /**
957
     * @param $path
958
     * @param $fallbackPath
959
     * @param $defaultIfBothIsEmpty
960
     * @return mixed
961
     */
962
    public function getValueByPathWithFallbackOrDefaultValueAndApplyStdWrap($path, $fallbackPath, $defaultIfBothIsEmpty)
963
    {
964
        $result = (string)$this->getValueByPathOrDefaultValue($path, '');
965
        if ($result !== '') {
966
            return $this->renderContentElementOfConfigured($path, $result);
967
        }
968
969
        $result = (string)$this->getValueByPathOrDefaultValue($fallbackPath, $defaultIfBothIsEmpty);
970
        return $this->renderContentElementOfConfigured($fallbackPath, $result);
971
    }
972
973
    /**
974
     * Retrieves the complete search configuration
975
     *
976
     * plugin.tx_solr.search.
977
     *
978
     * @param array $defaultIfEmpty
979
     * @return array
980
     */
981 48
    public function getSearchConfiguration(array $defaultIfEmpty = []): array
982
    {
983 48
        return $this->getObjectByPathOrDefault('plugin.tx_solr.search.', $defaultIfEmpty);
984
    }
985
986
    /**
987
     * Indicates if elevation should be used or not
988
     *
989
     * plugin.tx_solr.search.elevation
990
     *
991
     * @param bool $defaultIfEmpty
992
     * @return bool
993
     */
994 35
    public function getSearchElevation(bool $defaultIfEmpty = false): bool
995
    {
996 35
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.elevation', $defaultIfEmpty);
997 35
        return $this->getBool($result);
998
    }
999
1000
    /**
1001
     * Indicates if elevated results should be marked
1002
     *
1003
     * plugin.tx_solr.search.elevation.markElevatedResults
1004
     *
1005
     * @param bool $defaultIfEmpty
1006
     * @return bool
1007
     */
1008
    public function getSearchElevationMarkElevatedResults(bool $defaultIfEmpty = true): bool
1009
    {
1010
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.elevation.markElevatedResults', $defaultIfEmpty);
1011
        return $this->getBool($result);
1012
    }
1013
1014
    /**
1015
     * Indicates if elevation should be forced
1016
     *
1017
     *plugin.tx_solr.search.elevation.forceElevation
1018
     *
1019
     * @param bool $defaultIfEmpty
1020
     * @return bool
1021
     */
1022
    public function getSearchElevationForceElevation(bool $defaultIfEmpty = true): bool
1023
    {
1024
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.elevation.forceElevation', $defaultIfEmpty);
1025
        return $this->getBool($result);
1026
    }
1027
1028
    /**
1029
     * Indicates if collapsing on a certain field should be used to build variants or not.
1030
     *
1031
     * plugin.tx_solr.search.variants
1032
     *
1033
     * @param bool $defaultIfEmpty
1034
     * @return bool
1035
     */
1036 121
    public function getSearchVariants(bool $defaultIfEmpty = false): bool
1037
    {
1038 121
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.variants', $defaultIfEmpty);
1039 121
        return $this->getBool($result);
1040
    }
1041
1042
    /**
1043
     * Indicates if collapsing on a certain field should be used or not
1044
     *
1045
     * plugin.tx_solr.search.variants.variantField
1046
     *
1047
     * @param string $defaultIfEmpty
1048
     * @return string
1049
     */
1050 6
    public function getSearchVariantsField(string $defaultIfEmpty = 'variantId'): string
1051
    {
1052 6
        return (string)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.variants.variantField', $defaultIfEmpty);
1053
    }
1054
1055
    /**
1056
     * Indicates if expanding of collapsed items it activated.
1057
     *
1058
     * plugin.tx_solr.search.variants.expand
1059
     *
1060
     * @param bool $defaultIfEmpty
1061
     * @return bool
1062
     */
1063 6
    public function getSearchVariantsExpand(bool $defaultIfEmpty = false): bool
1064
    {
1065 6
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.variants.expand', $defaultIfEmpty);
1066 6
        return $this->getBool($result);
1067
    }
1068
1069
    /**
1070
     * Retrieves the number of elements that should be expanded.
1071
     *
1072
     * plugin.tx_solr.search.variants.limit
1073
     *
1074
     * @param int $defaultIfEmpty
1075
     * @return int
1076
     */
1077 6
    public function getSearchVariantsLimit(int $defaultIfEmpty = 10): int
1078
    {
1079 6
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.variants.limit', $defaultIfEmpty);
1080 6
        return (int)$result;
1081
    }
1082
1083
    /**
1084
     * Indicates if frequent searches should be show or not.
1085
     *
1086
     * plugin.tx_solr.search.frequentSearches
1087
     *
1088
     * @param bool $defaultIfEmpty
1089
     * @return bool
1090
     */
1091 28
    public function getSearchFrequentSearches(bool $defaultIfEmpty = false): bool
1092
    {
1093 28
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.frequentSearches', $defaultIfEmpty);
1094 28
        return $this->getBool($result);
1095
    }
1096
1097
    /**
1098
     * Returns the sub configuration of the frequentSearches
1099
     *
1100
     * plugin.tx_solr.search.frequentSearches.
1101
     *
1102
     * @param array $defaultIfEmpty
1103
     * @return array
1104
     */
1105
    public function getSearchFrequentSearchesConfiguration(array $defaultIfEmpty = []): array
1106
    {
1107
        return $this->getObjectByPathOrDefault('plugin.tx_solr.search.frequentSearches.', $defaultIfEmpty);
1108
    }
1109
1110
    /**
1111
     * Retrieves the minimum font size that should be used for the frequentSearches.
1112
     *
1113
     * plugin.tx_solr.search.frequentSearches.minSize
1114
     *
1115
     * @param int $defaultIfEmpty
1116
     * @return int
1117
     */
1118
    public function getSearchFrequentSearchesMinSize(int $defaultIfEmpty = 14): int
1119
    {
1120
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.frequentSearches.minSize', $defaultIfEmpty);
1121
        return (int)$result;
1122
    }
1123
1124
    /**
1125
     * Retrieves the maximum font size that should be used for the frequentSearches.
1126
     *
1127
     * plugin.tx_solr.search.frequentSearches.minSize
1128
     *
1129
     * @param int $defaultIfEmpty
1130
     * @return int
1131
     */
1132
    public function getSearchFrequentSearchesMaxSize(int $defaultIfEmpty = 32): int
1133
    {
1134
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.frequentSearches.maxSize', $defaultIfEmpty);
1135
        return (int)$result;
1136
    }
1137
1138
    /**
1139
     * Indicates if frequent searches should be show or not.
1140
     *
1141
     * plugin.tx_solr.search.frequentSearches.useLowercaseKeywords
1142
     *
1143
     * @param bool $defaultIfEmpty
1144
     * @return bool
1145
     */
1146
    public function getSearchFrequentSearchesUseLowercaseKeywords(bool $defaultIfEmpty = false): bool
1147
    {
1148
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.frequentSearches.useLowercaseKeywords', $defaultIfEmpty);
1149
        return $this->getBool($result);
1150
    }
1151
1152
    /**
1153
     * Returns the configuration if the search should be initialized with an empty query.
1154
     *
1155
     * plugin.tx_solr.search.initializeWithEmptyQuery
1156
     *
1157
     * @param bool $defaultIfEmpty
1158
     * @return bool
1159
     */
1160 127
    public function getSearchInitializeWithEmptyQuery(bool $defaultIfEmpty = false): bool
1161
    {
1162 127
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.initializeWithEmptyQuery', $defaultIfEmpty);
1163 127
        return $this->getBool($result);
1164
    }
1165
1166
    /**
1167
     * Returns the configured initial query
1168
     *
1169
     * plugin.tx_solr.search.initializeWithQuery
1170
     *
1171
     * @param string $defaultIfEmpty
1172
     * @return string
1173
     */
1174 127
    public function getSearchInitializeWithQuery(string $defaultIfEmpty = ''): string
1175
    {
1176 127
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.initializeWithQuery', $defaultIfEmpty);
1177 127
        return (string)$result;
1178
    }
1179
1180
    /**
1181
     * Returns if the last searches should be displayed or not.
1182
     *
1183
     * plugin.tx_solr.search.lastSearches
1184
     *
1185
     * @param bool $defaultIfEmpty
1186
     * @return bool
1187
     */
1188 28
    public function getSearchLastSearches(bool $defaultIfEmpty = false): bool
1189
    {
1190 28
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.lastSearches', $defaultIfEmpty);
1191 28
        return $this->getBool($result);
1192
    }
1193
1194
    /**
1195
     * Returns the lastSearch mode. "user" for user specific
1196
     *
1197
     * plugin.tx_solr.search.lastSearches.mode
1198
     *
1199
     * @param string $defaultIfEmpty
1200
     * @return string
1201
     */
1202 2
    public function getSearchLastSearchesMode(string $defaultIfEmpty = 'user'): string
1203
    {
1204 2
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.lastSearches.mode', $defaultIfEmpty);
1205 2
        return (string)$result;
1206
    }
1207
1208
    /**
1209
     * Returns the lastSearch limit
1210
     *
1211
     * plugin.tx_solr.search.lastSearches.limit
1212
     *
1213
     * @param int $defaultIfEmpty
1214
     * @return int
1215
     */
1216 2
    public function getSearchLastSearchesLimit(int $defaultIfEmpty = 10): int
1217
    {
1218 2
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.lastSearches.limit', $defaultIfEmpty);
1219 2
        return (int)$result;
1220
    }
1221
1222
    /**
1223
     * Indicates if the results of an initial empty query should be shown or not.
1224
     *
1225
     * plugin.tx_solr.search.showResultsOfInitialEmptyQuery
1226
     *
1227
     * @param bool $defaultIfEmpty
1228
     * @return bool
1229
     */
1230 10
    public function getSearchShowResultsOfInitialEmptyQuery(bool $defaultIfEmpty = false): bool
1231
    {
1232 10
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.showResultsOfInitialEmptyQuery', $defaultIfEmpty);
1233 10
        return $this->getBool($result);
1234
    }
1235
1236
    /**
1237
     * Indicates if the results of an initial search query should be shown.
1238
     *
1239
     * plugin.tx_solr.search.showResultsOfInitialQuery
1240
     *
1241
     * @param bool $defaultIfEmpty
1242
     * @return bool
1243
     */
1244 7
    public function getSearchShowResultsOfInitialQuery(bool $defaultIfEmpty = false): bool
1245
    {
1246 7
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.showResultsOfInitialQuery', $defaultIfEmpty);
1247 7
        return $this->getBool($result);
1248
    }
1249
1250
    /**
1251
     * Indicates if sorting was enabled or not.
1252
     *
1253
     * plugin.tx_solr.search.sorting
1254
     *
1255
     * @param bool $defaultIfEmpty
1256
     * @return bool
1257
     */
1258 64
    public function getSearchSorting(bool $defaultIfEmpty = false): bool
1259
    {
1260 64
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.sorting', $defaultIfEmpty);
1261 64
        return $this->getBool($result);
1262
    }
1263
1264
    /**
1265
     * Returns the sorting options configurations.
1266
     *
1267
     * plugin.tx_solr.search.sorting.options.
1268
     *
1269
     * @param array $defaultIfEmpty
1270
     * @return array
1271
     */
1272 2
    public function getSearchSortingOptionsConfiguration(array $defaultIfEmpty = []): array
1273
    {
1274 2
        return $this->getObjectByPathOrDefault('plugin.tx_solr.search.sorting.options.', $defaultIfEmpty);
1275
    }
1276
1277
    /**
1278
     * Retrieves the sorting default order for a sort option.
1279
     *
1280
     * plugin.tx_solr.search.sorting.options.<sortOptionName>.defaultOrder
1281
     *
1282
     * or
1283
     *
1284
     * plugin.tx_solr.search.sorting.defaultOrder
1285
     *
1286
     *
1287
     * @param string $sortOptionName
1288
     * @param string $defaultIfEmpty
1289
     * @return string
1290
     */
1291 5
    public function getSearchSortingDefaultOrderBySortOptionName(string $sortOptionName = '', string $defaultIfEmpty = 'asc'): string
1292
    {
1293 5
        $sortOrderSpecificPath = 'plugin.tx_solr.search.sorting.options.' . $sortOptionName . '.defaultOrder';
1294 5
        $specificSortOrder = $this->getValueByPathOrDefaultValue($sortOrderSpecificPath, null);
1295
1296
        // if we have a concrete setting, use it
1297 5
        if ($specificSortOrder !== null) {
1298 2
            return mb_strtolower($specificSortOrder);
1299
        }
1300
1301
        // no specific setting, check common setting
1302 3
        $commonPath = 'plugin.tx_solr.search.sorting.defaultOrder';
1303 3
        $commonATagParamOrDefaultValue = $this->getValueByPathOrDefaultValue($commonPath, $defaultIfEmpty);
1304 3
        return mb_strtolower($commonATagParamOrDefaultValue);
1305
    }
1306
1307
    /**
1308
     * Returns the trusted fields configured for the search that do not need to be escaped.
1309
     *
1310
     * @param array $defaultIfEmpty
1311
     * @return array
1312
     */
1313 9
    public function getSearchTrustedFieldsArray(array $defaultIfEmpty = ['url']): array
1314
    {
1315 9
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.trustedFields', '');
1316
1317 9
        if (trim($result) === '') {
1318 3
            return $defaultIfEmpty;
1319
        }
1320
1321 6
        return GeneralUtility::trimExplode(',', $result);
1322
    }
1323
1324
    /**
1325
     * Indicates if the plugin arguments should be kept in the search form for a second submission.
1326
     *
1327
     * plugin.tx_solr.search.keepExistingParametersForNewSearches
1328
     *
1329
     * @param bool $defaultIfEmpty
1330
     * @return bool
1331
     */
1332 29
    public function getSearchKeepExistingParametersForNewSearches(bool $defaultIfEmpty = false): bool
1333
    {
1334 29
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.keepExistingParametersForNewSearches', $defaultIfEmpty);
1335 29
        return $this->getBool($result);
1336
    }
1337
1338
    /**
1339
     * Returns if an empty query is allowed on the query level.
1340
     *
1341
     * plugin.tx_solr.search.query.allowEmptyQuery
1342
     *
1343
     * @param string $defaultIfEmpty
1344
     * @return bool
1345
     */
1346 118
    public function getSearchQueryAllowEmptyQuery(string $defaultIfEmpty = ''): bool
1347
    {
1348 118
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.query.allowEmptyQuery', $defaultIfEmpty);
1349 118
        return $this->getBool($result);
1350
    }
1351
1352
    /**
1353
     * Returns the filter configuration array
1354
     *
1355
     * plugin.tx_solr.search.query.filter.
1356
     *
1357
     * @param array $defaultIfEmpty
1358
     * @return array
1359
     */
1360 126
    public function getSearchQueryFilterConfiguration(array $defaultIfEmpty = []): array
1361
    {
1362 126
        return $this->getObjectByPathOrDefault('plugin.tx_solr.search.query.filter.', $defaultIfEmpty);
1363
    }
1364
1365
    /**
1366
     * Can be used to overwrite the filterConfiguration.
1367
     *
1368
     * plugin.tx_solr.search.query.filter.
1369
     *
1370
     * @param array $configuration
1371
     */
1372 1
    public function setSearchQueryFilterConfiguration(array $configuration)
1373
    {
1374 1
        $this->configurationAccess->set('plugin.tx_solr.search.query.filter.', $configuration);
1375
    }
1376
1377
    /**
1378
     * Removes the pageSections filter setting.
1379
     */
1380 3
    public function removeSearchQueryFilterForPageSections()
1381
    {
1382 3
        $this->configurationAccess->reset('plugin.tx_solr.search.query.filter.__pageSections');
1383
    }
1384
1385
    /**
1386
     * Returns the configured queryFields from TypoScript
1387
     *
1388
     * plugin.tx_solr.search.query.queryFields
1389
     *
1390
     * @param string $defaultIfEmpty
1391
     * @return string
1392
     */
1393 121
    public function getSearchQueryQueryFields(string $defaultIfEmpty = ''): string
1394
    {
1395 121
        return (string)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.query.queryFields', $defaultIfEmpty);
1396
    }
1397
1398
    /**
1399
     * This method is used to check if a phrase search is enabled or not
1400
     *
1401
     * plugin.tx_solr.search.query.phrase = 1
1402
     *
1403
     * @param bool $defaultIfEmpty
1404
     * @return bool
1405
     */
1406 121
    public function getPhraseSearchIsEnabled(bool $defaultIfEmpty = false): bool
1407
    {
1408 121
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.query.phrase', $defaultIfEmpty);
1409 121
        return $this->getBool($result);
1410
    }
1411
1412
    /**
1413
     * Returns the configured phrase fields from TypoScript
1414
     *
1415
     * plugin.tx_solr.search.query.phrase.fields
1416
     *
1417
     * @param string $defaultIfEmpty
1418
     * @return string
1419
     */
1420 2
    public function getSearchQueryPhraseFields(string $defaultIfEmpty = ''): string
1421
    {
1422 2
        return (string)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.query.phrase.fields', $defaultIfEmpty);
1423
    }
1424
1425
    /**
1426
     * This method is used to check if a bigram phrase search is enabled or not
1427
     *
1428
     * plugin.tx_solr.search.query.bigramPhrase = 1
1429
     *
1430
     * @param bool $defaultIfEmpty
1431
     * @return bool
1432
     */
1433 121
    public function getBigramPhraseSearchIsEnabled(bool $defaultIfEmpty = false): bool
1434
    {
1435 121
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.query.bigramPhrase', $defaultIfEmpty);
1436 121
        return $this->getBool($result);
1437
    }
1438
1439
    /**
1440
     * Returns the configured phrase fields from TypoScript
1441
     *
1442
     * plugin.tx_solr.search.query.bigramPhrase.fields
1443
     *
1444
     * @param string $defaultIfEmpty
1445
     * @return string
1446
     */
1447 2
    public function getSearchQueryBigramPhraseFields(string $defaultIfEmpty = ''): string
1448
    {
1449 2
        return (string)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.query.bigramPhrase.fields', $defaultIfEmpty);
1450
    }
1451
1452
    /**
1453
     * This method is used to check if a trigram phrase search is enabled or not
1454
     *
1455
     * plugin.tx_solr.search.query.trigramPhrase = 1
1456
     *
1457
     * @param bool $defaultIfEmpty
1458
     * @return bool
1459
     */
1460 121
    public function getTrigramPhraseSearchIsEnabled(bool $defaultIfEmpty = false): bool
1461
    {
1462 121
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.query.trigramPhrase', $defaultIfEmpty);
1463 121
        return $this->getBool($result);
1464
    }
1465
1466
    /**
1467
     * Returns the configured trigram phrase fields from TypoScript
1468
     *
1469
     * plugin.tx_solr.search.query.trigramPhrase.fields
1470
     *
1471
     * @param string $defaultIfEmpty
1472
     * @return string
1473
     */
1474 2
    public function getSearchQueryTrigramPhraseFields(string $defaultIfEmpty = ''): string
1475
    {
1476 2
        return (string)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.query.trigramPhrase.fields', $defaultIfEmpty);
1477
    }
1478
1479
    /**
1480
     * Returns the configured returnFields as array.
1481
     *
1482
     * plugin.tx_solr.search.query.returnFields
1483
     *
1484
     * @param array $defaultIfEmpty
1485
     * @return array
1486
     */
1487 123
    public function getSearchQueryReturnFieldsAsArray(array $defaultIfEmpty = []): array
1488
    {
1489 123
        $returnFields = $this->getValueByPath('plugin.tx_solr.search.query.returnFields');
1490 123
        if (is_null($returnFields)) {
1491 86
            return $defaultIfEmpty;
1492
        }
1493
1494 37
        return GeneralUtility::trimExplode(',', $returnFields);
1495
    }
1496
1497
    /**
1498
     * Returns the configured target page for the search.
1499
     * By default, the contextPageId will be used
1500
     *
1501
     * plugin.tx_solr.search.targetPage
1502
     *
1503
     * @return int
1504
     */
1505 29
    public function getSearchTargetPage(): int
1506
    {
1507 29
        $targetPage = (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.targetPage', 0);
1508 29
        if ($targetPage === 0) {
1509
            // when no specific page was configured we use the contextPageId (which is usual $GLOBALS['TSFE']->id)
1510 29
            $targetPage = $this->contextPageId;
1511
        }
1512
1513 29
        return $targetPage;
1514
    }
1515
1516
    /**
1517
     * Retrieves the targetPage configuration.
1518
     *
1519
     * plugin.tx_solr.search.targetPage.
1520
     *
1521
     * @param array $defaultIfEmpty
1522
     * @return array
1523
     */
1524
    public function getSearchTargetPageConfiguration(array $defaultIfEmpty = []): array
1525
    {
1526
        return $this->getObjectByPathOrDefault('plugin.tx_solr.search.targetPage.', $defaultIfEmpty);
1527
    }
1528
1529
    /**
1530
     * Method to check if the site highlighting is enabled. When the siteHighlighting is enabled the
1531
     * sword_list parameter is added to the results link.
1532
     *
1533
     * plugin.tx_solr.search.results.siteHighlighting
1534
     *
1535
     * @param bool $defaultIfEmpty
1536
     * @return bool
1537
     */
1538 22
    public function getSearchResultsSiteHighlighting(bool $defaultIfEmpty = true): bool
1539
    {
1540 22
        $isSiteHighlightingEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.siteHighlighting', $defaultIfEmpty);
1541 22
        return $this->getBool($isSiteHighlightingEnabled);
1542
    }
1543
1544
    /**
1545
     * Can be used to check if the highlighting is enabled
1546
     *
1547
     * plugin.tx_solr.search.results.resultsHighlighting
1548
     *
1549
     * @param bool $defaultIfEmpty
1550
     * @return bool
1551
     */
1552 121
    public function getIsSearchResultsHighlightingEnabled(bool $defaultIfEmpty = false): bool
1553
    {
1554 121
        $isHighlightingEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.resultsHighlighting', $defaultIfEmpty);
1555 121
        return $this->getBool($isHighlightingEnabled);
1556
    }
1557
1558
    /**
1559
     * Returns the result highlighting fields.
1560
     *
1561
     * plugin.tx_solr.search.results.resultsHighlighting.highlightFields
1562
     *
1563
     * @param string $defaultIfEmpty
1564
     * @return string
1565
     */
1566 8
    public function getSearchResultsHighlightingFields(string $defaultIfEmpty = ''): string
1567
    {
1568 8
        return (string)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.resultsHighlighting.highlightFields', $defaultIfEmpty);
1569
    }
1570
1571
    /**
1572
     * Returns the result highlighting fields as array.
1573
     *
1574
     * plugin.tx_solr.search.results.resultsHighlighting.highlightFields
1575
     *
1576
     * @param array $defaultIfEmpty
1577
     * @return array
1578
     */
1579
    public function getSearchResultsHighlightingFieldsAsArray(array $defaultIfEmpty = []): array
1580
    {
1581
        $highlightingFields = $this->getSearchResultsHighlightingFields();
1582
1583
        if ($highlightingFields === '') {
1584
            return $defaultIfEmpty;
1585
        }
1586
1587
        return GeneralUtility::trimExplode(',', $highlightingFields, true);
1588
    }
1589
1590
    /**
1591
     * Returns the fragmentSize for highlighted segments.
1592
     *
1593
     * plugin.tx_solr.search.results.resultsHighlighting.fragmentSize
1594
     *
1595
     * @param int $defaultIfEmpty
1596
     * @return int
1597
     */
1598 8
    public function getSearchResultsHighlightingFragmentSize(int $defaultIfEmpty = 200): int
1599
    {
1600 8
        return (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.resultsHighlighting.fragmentSize', $defaultIfEmpty);
1601
    }
1602
1603
    /**
1604
     * Returns the fragmentSeparator for highlighted segments.
1605
     *
1606
     * plugin.tx_solr.search.results.resultsHighlighting.fragmentSeparator
1607
     *
1608
     * @param string $defaultIfEmpty
1609
     * @return string
1610
     */
1611 22
    public function getSearchResultsHighlightingFragmentSeparator(string $defaultIfEmpty = '[...]'): string
1612
    {
1613 22
        return (string)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.resultsHighlighting.fragmentSeparator', $defaultIfEmpty);
1614
    }
1615
1616
    /**
1617
     * Returns the number of results that should be shown per page.
1618
     *
1619
     * plugin.tx_solr.search.results.resultsPerPage
1620
     *
1621
     * @param int $defaultIfEmpty
1622
     * @return int
1623
     */
1624 33
    public function getSearchResultsPerPage(int $defaultIfEmpty = 10): int
1625
    {
1626 33
        return (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.resultsPerPage', $defaultIfEmpty);
1627
    }
1628
1629
    /**
1630
     * Returns the available options for the per page switch.
1631
     *
1632
     * plugin.tx_solr.search.results.resultsPerPageSwitchOptions
1633
     *
1634
     * @param array $defaultIfEmpty
1635
     * @return array
1636
     */
1637 33
    public function getSearchResultsPerPageSwitchOptionsAsArray(array $defaultIfEmpty = []): array
1638
    {
1639 33
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.resultsPerPageSwitchOptions', '');
1640
1641 33
        if (trim($result) === '') {
1642
            return $defaultIfEmpty;
1643
        }
1644
1645 33
        return GeneralUtility::intExplode(',', $result, true);
1646
    }
1647
1648
    /**
1649
     * Returns the maximum number of links shown in the paginator.
1650
     *
1651
     * plugin.tx_solr.search.results.maxPaginatorLinks
1652
     *
1653
     * @param int $defaultIfEmpty
1654
     * @return int
1655
     */
1656 33
    public function getMaxPaginatorLinks(int $defaultIfEmpty = 0): int
1657
    {
1658 33
        return (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.maxPaginatorLinks', $defaultIfEmpty);
1659
    }
1660
1661
    /**
1662
     * Returns the configured wrap for the resultHighlighting.
1663
     *
1664
     * plugin.tx_solr.search.results.resultsHighlighting.wrap
1665
     *
1666
     * @param string $defaultIfEmpty
1667
     * @return string
1668
     */
1669 30
    public function getSearchResultsHighlightingWrap(string $defaultIfEmpty = ''): string
1670
    {
1671 30
        return (string)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.resultsHighlighting.wrap', $defaultIfEmpty);
1672
    }
1673
1674
    /**
1675
     * Indicates if spellchecking is enabled or not.
1676
     *
1677
     * plugin.tx_solr.search.spellchecking
1678
     *
1679
     * @param bool $defaultIfEmpty
1680
     * @return bool
1681
     */
1682 3
    public function getSearchSpellchecking(bool $defaultIfEmpty = false): bool
1683
    {
1684 3
        $isFacetingEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.spellchecking', $defaultIfEmpty);
1685 3
        return $this->getBool($isFacetingEnabled);
1686
    }
1687
1688
    /**
1689
     * Returns the numberOfSuggestionsToTry that should be used for the spellchecking.
1690
     *
1691
     * plugin.tx_solr.search.spellchecking.numberOfSuggestionsToTry
1692
     *
1693
     * @param int $defaultIfEmpty
1694
     * @return int
1695
     */
1696 3
    public function getSearchSpellcheckingNumberOfSuggestionsToTry(int $defaultIfEmpty = 1): int
1697
    {
1698 3
        return (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.spellchecking.numberOfSuggestionsToTry', $defaultIfEmpty);
1699
    }
1700
1701
    /**
1702
     * Indicates if a second search should be fired from the spellchecking suggestion if no results could be found.
1703
     *
1704
     * plugin.tx_solr.search.spellchecking.searchUsingSpellCheckerSuggestion
1705
     *
1706
     * @param bool $defaultIfEmpty
1707
     * @return bool
1708
     */
1709 35
    public function getSearchSpellcheckingSearchUsingSpellCheckerSuggestion(bool $defaultIfEmpty = false): bool
1710
    {
1711 35
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.spellchecking.searchUsingSpellCheckerSuggestion', $defaultIfEmpty);
1712 35
        return $this->getBool($result);
1713
    }
1714
1715
    /**
1716
     * Indicates if faceting is enabled or not.
1717
     *
1718
     * plugin.tx_solr.search.faceting
1719
     *
1720
     * @param bool $defaultIfEmpty
1721
     * @return bool
1722
     */
1723 121
    public function getSearchFaceting(bool $defaultIfEmpty = false): bool
1724
    {
1725 121
        $isFacetingEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting', $defaultIfEmpty);
1726 121
        return $this->getBool($isFacetingEnabled);
1727
    }
1728
1729
    /**
1730
     * Retrieves the showEvenWhenEmpty for a facet by facet name. If nothing specific is configured
1731
     * the global showEmptyFacets with be returned.
1732
     *
1733
     * plugin.tx_solr.search.faceting.facets.<facetName>.showEvenWhenEmpty
1734
     *
1735
     * or
1736
     *
1737
     * plugin.tx_solr.search.faceting.showEmptyFacets
1738
     *
1739
     *
1740
     * @param string $facetName
1741
     * @param bool $defaultIfEmpty
1742
     * @return bool
1743
     */
1744 54
    public function getSearchFacetingShowEmptyFacetsByName(string $facetName = '', bool $defaultIfEmpty = false): bool
1745
    {
1746 54
        $facetSpecificPath = 'plugin.tx_solr.search.faceting.facets.' . $facetName . '.showEvenWhenEmpty';
1747 54
        $specificShowWhenEmpty = $this->getValueByPathOrDefaultValue($facetSpecificPath, null);
1748
1749
        // if we have a concrete setting, use it
1750 54
        if ($specificShowWhenEmpty !== null) {
1751 2
            return $this->getBool($specificShowWhenEmpty);
1752
        }
1753
1754
        // no specific setting, check common setting
1755 54
        $commonPath = 'plugin.tx_solr.search.faceting.showEmptyFacets';
1756 54
        return $this->getBool($this->getValueByPathOrDefaultValue($commonPath, $defaultIfEmpty));
1757
    }
1758
1759
    /**
1760
     * Returns the wrap for the faceting show all link
1761
     *
1762
     * plugin.tx_solr.search.faceting.showAllLink.wrap
1763
     *
1764
     * @param string $defaultIfEmpty
1765
     * @return string
1766
     */
1767
    public function getSearchFacetingShowAllLinkWrap(string $defaultIfEmpty = ''): string
1768
    {
1769
        return (string)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.showAllLink.wrap', $defaultIfEmpty);
1770
    }
1771
1772
    /**
1773
     * Returns the link url parameters that should be added to a facet.
1774
     *
1775
     * plugin.tx_solr.search.faceting.facetLinkUrlParameters
1776
     *
1777
     * @param string $defaultIfEmpty
1778
     * @return string
1779
     */
1780 16
    public function getSearchFacetingFacetLinkUrlParameters(string $defaultIfEmpty = ''): string
1781
    {
1782 16
        return trim($this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.facetLinkUrlParameters', $defaultIfEmpty));
1783
    }
1784
1785
    /**
1786
     * Returns if the facetLinkUrlsParameters should be included in the reset link.
1787
     *
1788
     * plugin.tx_solr.search.faceting.facetLinkUrlParameters.useForFacetResetLinkUrl
1789
     *
1790
     * @param bool $defaultIfEmpty
1791
     * @return bool
1792
     */
1793 4
    public function getSearchFacetingFacetLinkUrlParametersUseForFacetResetLinkUrl(bool $defaultIfEmpty = true): bool
1794
    {
1795 4
        $useForFacetResetLinkUrl = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.facetLinkUrlParameters.useForFacetResetLinkUrl', $defaultIfEmpty);
1796 4
        return $this->getBool($useForFacetResetLinkUrl);
1797
    }
1798
1799
    /**
1800
     * Returns the link url parameters that should be added to a facet as array.
1801
     *
1802
     * plugin.tx_solr.search.faceting.facetLinkUrlParameters
1803
     *
1804
     * @param array $defaultIfEmpty
1805
     * @return array
1806
     */
1807 16
    public function getSearchFacetingFacetLinkUrlParametersAsArray(array $defaultIfEmpty = []): array
1808
    {
1809 16
        $linkUrlParameters = $this->getSearchFacetingFacetLinkUrlParameters();
1810 16
        if ($linkUrlParameters === '') {
1811 16
            return $defaultIfEmpty;
1812
        }
1813
1814
        return GeneralUtility::explodeUrl2Array($linkUrlParameters);
1815
    }
1816
1817
    /**
1818
     * Return the configured minimumCount value for facets.
1819
     *
1820
     * plugin.tx_solr.search.faceting.minimumCount
1821
     *
1822
     * @param int $defaultIfEmpty
1823
     * @return int
1824
     */
1825 32
    public function getSearchFacetingMinimumCount(int $defaultIfEmpty = 1): int
1826
    {
1827 32
        return (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.minimumCount', $defaultIfEmpty);
1828
    }
1829
1830
    /**
1831
     * Return the configured limit value for facets, used for displaying.
1832
     *
1833
     * plugin.tx_solr.search.faceting.limit
1834
     *
1835
     * @param int $defaultIfEmpty
1836
     * @return int
1837
     */
1838
    public function getSearchFacetingLimit(int $defaultIfEmpty = 10): int
1839
    {
1840
        return (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.limit', $defaultIfEmpty);
1841
    }
1842
1843
    /**
1844
     * Return the configured limit value for facets, used for the response.
1845
     *
1846
     * plugin.tx_solr.search.faceting.facetLimit
1847
     *
1848
     * @param int $defaultIfEmpty
1849
     * @return int
1850
     */
1851 32
    public function getSearchFacetingFacetLimit(int $defaultIfEmpty = 100): int
1852
    {
1853 32
        return (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.facetLimit', $defaultIfEmpty);
1854
    }
1855
1856
    /**
1857
     * Return the configured url parameter style value for facets, used for building faceting parameters.
1858
     *
1859
     * plugin.tx_solr.search.faceting.urlParameterStyle
1860
     *
1861
     * @param string $defaultUrlParameterStyle
1862
     * @return string
1863
     */
1864 48
    public function getSearchFacetingUrlParameterStyle(string $defaultUrlParameterStyle = 'index'): string
1865
    {
1866 48
        return (string)$this->getValueByPathOrDefaultValue(
1867 48
            'plugin.tx_solr.search.faceting.urlParameterStyle',
1868 48
            $defaultUrlParameterStyle
1869 48
        );
1870
    }
1871
1872
    /**
1873
     * Return the configuration if the URL parameters should be sorted.
1874
     *
1875
     * plugin.tx_solr.search.faceting.urlParameterSort
1876
     *
1877
     * @param bool $defaultUrlParameterSort
1878
     * @return bool
1879
     */
1880 41
    public function getSearchFacetingUrlParameterSort(bool $defaultUrlParameterSort = false): bool
1881
    {
1882 41
        return (bool)$this->getValueByPathOrDefaultValue(
1883 41
            'plugin.tx_solr.search.faceting.urlParameterSort',
1884 41
            $defaultUrlParameterSort
1885 41
        );
1886
    }
1887
1888
    /**
1889
     * Return the configured faceting sortBy value.
1890
     *
1891
     * plugin.tx_solr.search.faceting.sortBy
1892
     *
1893
     * @param string $defaultIfEmpty
1894
     * @return string
1895
     */
1896 32
    public function getSearchFacetingSortBy(string $defaultIfEmpty = ''): string
1897
    {
1898 32
        return (string)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.sortBy', $defaultIfEmpty);
1899
    }
1900
1901
    /**
1902
     * Returns if a facets should be kept on selection. Global faceting setting
1903
     * can also be configured on facet level by using
1904
     * (plugin.tx_solr.search.faceting.facets.<fieldName>.keepAllOptionsOnSelection)
1905
     *
1906
     * plugin.tx_solr.search.faceting.keepAllFacetsOnSelection
1907
     *
1908
     * @param bool $defaultIfEmpty
1909
     * @return bool
1910
     */
1911 32
    public function getSearchFacetingKeepAllFacetsOnSelection(bool $defaultIfEmpty = false): bool
1912
    {
1913 32
        $keepAllOptionsOnSelection = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.keepAllFacetsOnSelection', $defaultIfEmpty);
1914 32
        return $this->getBool($keepAllOptionsOnSelection);
1915
    }
1916
1917
    /**
1918
     * Returns if the facet count should be calculated based on the facet selection when
1919
     * plugin.tx_solr.search.faceting.keepAllFacetsOnSelection has been enabled
1920
     *
1921
     * plugin.tx_solr.search.faceting.countAllFacetsForSelection
1922
     *
1923
     * @param bool $defaultIfEmpty
1924
     * @return bool
1925
     */
1926 5
    public function getSearchFacetingCountAllFacetsForSelection(bool $defaultIfEmpty = false): bool
1927
    {
1928 5
        $countAllFacetsForSelection = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.countAllFacetsForSelection', $defaultIfEmpty);
1929 5
        return $this->getBool($countAllFacetsForSelection);
1930
    }
1931
1932
    /**
1933
     * Returns the configured faceting configuration.
1934
     *
1935
     * plugin.tx_solr.search.faceting.facets
1936
     *
1937
     * @param array $defaultIfEmpty
1938
     * @return array
1939
     */
1940 59
    public function getSearchFacetingFacets(array $defaultIfEmpty = []): array
1941
    {
1942 59
        return $this->getObjectByPathOrDefault('plugin.tx_solr.search.faceting.facets.', $defaultIfEmpty);
1943
    }
1944
1945
    /**
1946
     * Returns the configuration of a single facet by facet name.
1947
     *
1948
     * plugin.tx_solr.search.faceting.facets.<facetName>
1949
     *
1950
     * @param string $facetName
1951
     * @param array $defaultIfEmpty
1952
     * @return array
1953
     */
1954 32
    public function getSearchFacetingFacetByName(string $facetName, array $defaultIfEmpty = []): array
1955
    {
1956 32
        return $this->getObjectByPathOrDefault('plugin.tx_solr.search.faceting.facets.' . $facetName . '.', $defaultIfEmpty);
1957
    }
1958
1959
    /**
1960
     * Indicates if statistics is enabled or not.
1961
     *
1962
     * plugin.tx_solr.statistics
1963
     *
1964
     * @param bool $defaultIfEmpty
1965
     * @return bool
1966
     */
1967 37
    public function getStatistics(bool $defaultIfEmpty = false): bool
1968
    {
1969 37
        $isStatisticsEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.statistics', $defaultIfEmpty);
1970 37
        return $this->getBool($isStatisticsEnabled);
1971
    }
1972
1973
    /**
1974
     * Indicates to which length an ip should be anonymized in the statistics
1975
     *
1976
     * plugin.tx_solr.statistics.anonymizeIP
1977
     *
1978
     * @param int $defaultIfEmpty
1979
     * @return int
1980
     */
1981
    public function getStatisticsAnonymizeIP(int $defaultIfEmpty = 0): int
1982
    {
1983
        $anonymizeToLength = $this->getValueByPathOrDefaultValue('plugin.tx_solr.statistics.anonymizeIP', $defaultIfEmpty);
1984
        return (int)$anonymizeToLength;
1985
    }
1986
1987
    /**
1988
     * Indicates if additional debug Data should be added to the statistics
1989
     *
1990
     * plugin.tx_solr.statistics.addDebugData
1991
     *
1992
     * @param bool $defaultIfEmpty
1993
     * @return bool
1994
     */
1995 2
    public function getStatisticsAddDebugData(bool $defaultIfEmpty = false): bool
1996
    {
1997 2
        $statisticsAddDebugDataEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.statistics.addDebugData', $defaultIfEmpty);
1998 2
        return $this->getBool($statisticsAddDebugDataEnabled);
1999
    }
2000
2001
    /**
2002
     * Indicates if suggestion is enabled or not.
2003
     *
2004
     * plugin.tx_solr.suggest
2005
     *
2006
     * @param bool $defaultIfEmpty
2007
     * @return bool
2008
     */
2009
    public function getSuggest(bool $defaultIfEmpty = false): bool
2010
    {
2011
        $isSuggestionEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.suggest', $defaultIfEmpty);
2012
        return $this->getBool($isSuggestionEnabled);
2013
    }
2014
2015
    /**
2016
     * Indicates if https should be used for the suggestions form.
2017
     *
2018
     * plugin.tx_solr.suggest.forceHttps
2019
     *
2020
     * @param bool $defaultIfEmpty
2021
     * @return bool
2022
     */
2023
    public function getSuggestForceHttps(bool $defaultIfEmpty = false): bool
2024
    {
2025
        $isHttpsForced = $this->getValueByPathOrDefaultValue('plugin.tx_solr.suggest.forceHttps', $defaultIfEmpty);
2026
        return $this->getBool($isHttpsForced);
2027
    }
2028
2029
    /**
2030
     * Returns the allowed number of suggestions.
2031
     *
2032
     * plugin.tx_solr.suggest.numberOfSuggestions
2033
     *
2034
     * @param int $defaultIfEmpty
2035
     * @return int
2036
     */
2037 3
    public function getSuggestNumberOfSuggestions(int $defaultIfEmpty = 10): int
2038
    {
2039 3
        $numberOfSuggestions = $this->getValueByPathOrDefaultValue('plugin.tx_solr.suggest.numberOfSuggestions', $defaultIfEmpty);
2040 3
        return (int)$numberOfSuggestions;
2041
    }
2042
2043
    /**
2044
     * Indicates if the topResults should be shown or not
2045
     *
2046
     * plugin.tx_solr.suggest.showTopResults
2047
     *
2048
     * @param bool $defaultIfEmpty
2049
     * @return bool
2050
     */
2051 3
    public function getSuggestShowTopResults(bool $defaultIfEmpty = true): bool
2052
    {
2053 3
        $showTopResults = $this->getValueByPathOrDefaultValue('plugin.tx_solr.suggest.showTopResults', $defaultIfEmpty);
2054 3
        return $this->getBool($showTopResults);
2055
    }
2056
2057
    /**
2058
     * Returns the configured number of top results to show
2059
     *
2060
     * plugin.tx_solr.suggest.numberOfTopResults
2061
     *
2062
     * @param int $defaultIfEmpty
2063
     * @return int
2064
     */
2065 3
    public function getSuggestNumberOfTopResults(int $defaultIfEmpty = 5): int
2066
    {
2067 3
        $numberOfTopResults = $this->getValueByPathOrDefaultValue('plugin.tx_solr.suggest.numberOfTopResults', $defaultIfEmpty);
2068 3
        return (int)$numberOfTopResults;
2069
    }
2070
2071
    /**
2072
     * Returns additional fields for the top results
2073
     *
2074
     * plugin.tx_solr.suggest.additionalTopResultsFields
2075
     *
2076
     * @param array $defaultIfEmpty
2077
     * @return array
2078
     */
2079 3
    public function getSuggestAdditionalTopResultsFields(array $defaultIfEmpty = []): array
2080
    {
2081 3
        $additionalTopResultsFields = $this->getValueByPathOrDefaultValue('plugin.tx_solr.suggest.additionalTopResultsFields', '');
2082 3
        if ($additionalTopResultsFields === '') {
2083 3
            return $defaultIfEmpty;
2084
        }
2085
2086
        return GeneralUtility::trimExplode(',', $additionalTopResultsFields, true);
2087
    }
2088
2089
    /**
2090
     * Returns the configured template for a specific template fileKey.
2091
     *
2092
     * plugin.tx_solr.view.templateFiles.<fileKey>
2093
     *
2094
     * @param string $fileKey
2095
     * @param string $defaultIfEmpty
2096
     * @return string
2097
     */
2098 35
    public function getViewTemplateByFileKey(string $fileKey, string $defaultIfEmpty = ''): string
2099
    {
2100 35
        $templateFileName = $this->getValueByPathOrDefaultValue('plugin.tx_solr.view.templateFiles.' . $fileKey, $defaultIfEmpty);
2101 35
        return (string)$templateFileName;
2102
    }
2103
2104
    /**
2105
     * Returns the configured available template files for the flexform.
2106
     *
2107
     * plugin.tx_solr.view.templateFiles.[fileKey].availableTemplates.
2108
     *
2109
     * @param string $fileKey
2110
     * @return array
2111
     */
2112
    public function getAvailableTemplatesByFileKey(string $fileKey): array
2113
    {
2114
        return $this->getObjectByPathOrDefault('plugin.tx_solr.view.templateFiles.' . $fileKey . '.availableTemplates.', []);
2115
    }
2116
2117
    /**
2118
     * Returns the configuration of the crop view helper.
2119
     *
2120
     * plugin.tx_solr.viewHelpers.crop.
2121
     *
2122
     * @param array $defaultIfEmpty
2123
     * @return array
2124
     */
2125
    public function getViewHelpersCropConfiguration(array $defaultIfEmpty = []): array
2126
    {
2127
        return $this->getObjectByPathOrDefault('plugin.tx_solr.viewHelpers.crop.', $defaultIfEmpty);
2128
    }
2129
2130
    /**
2131
     * Returns the configuration of the sorting view helper.
2132
     *
2133
     * plugin.tx_solr.viewHelpers.sortIndicator.
2134
     *
2135
     * @param array $defaultIfEmpty
2136
     * @return array
2137
     */
2138
    public function getViewHelpersSortIndicatorConfiguration(array $defaultIfEmpty = []): array
2139
    {
2140
        return $this->getObjectByPathOrDefault('plugin.tx_solr.viewHelpers.sortIndicator.', $defaultIfEmpty);
2141
    }
2142
2143
    /**
2144
     * Controls whether ext-solr will send commits to solr.
2145
     * Beware: If you disable this, you need to ensure
2146
     * that some other mechanism will commit your changes
2147
     * otherwise they will never be searchable.
2148
     * A good way to achieve this is enabling the solr
2149
     * daemons autoCommit feature.
2150
     *
2151
     * plugin.tx_solr.index.enableCommits
2152
     *
2153
     * @param bool $defaultIfEmpty
2154
     * @return bool
2155
     */
2156 23
    public function getEnableCommits(bool $defaultIfEmpty = true): bool
2157
    {
2158 23
        $enableCommits = $this->getValueByPathOrDefaultValue('plugin.tx_solr.index.enableCommits', $defaultIfEmpty);
2159 23
        return $this->getBool($enableCommits);
2160
    }
2161
2162
    /**
2163
     * Returns the url namespace that is used for the arguments.
2164
     *
2165
     * plugin.tx_solr.view.pluginNamespace
2166
     *
2167
     * @param string $defaultIfEmpty
2168
     * @return string
2169
     */
2170 42
    public function getSearchPluginNamespace(string $defaultIfEmpty = 'tx_solr'): string
2171
    {
2172 42
        return (string)$this->getValueByPathOrDefaultValue('plugin.tx_solr.view.pluginNamespace', $defaultIfEmpty);
2173
    }
2174
2175
    /**
2176
     * Returns true if the global url parameter q, that indicates the query should be used.
2177
     *
2178
     * Should be set to false, when multiple instance on the same page should have their querystring.
2179
     *
2180
     * plugin.tx_solr.search.ignoreGlobalQParameter
2181
     *
2182
     * @param bool $defaultIfEmpty
2183
     * @return bool
2184
     */
2185 1
    public function getSearchIgnoreGlobalQParameter(bool $defaultIfEmpty = false): bool
2186
    {
2187 1
        $enableQParameter = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.ignoreGlobalQParameter', $defaultIfEmpty);
2188 1
        return $this->getBool($enableQParameter);
2189
    }
2190
2191
    /**
2192
     * Returns the argument names, that should be added to the persistent arguments, as array.
2193
     *
2194
     * plugin.tx_solr.search.additionalPersistentArgumentNames
2195
     *
2196
     * @param array $defaultIfEmpty
2197
     * @return array
2198
     */
2199 43
    public function getSearchAdditionalPersistentArgumentNames(array $defaultIfEmpty = []): array
2200
    {
2201 43
        $additionalPersistentArgumentNames = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.additionalPersistentArgumentNames', '');
2202
2203 43
        if ($additionalPersistentArgumentNames === '') {
2204 42
            return $defaultIfEmpty;
2205
        }
2206
2207 1
        return GeneralUtility::trimExplode(',', $additionalPersistentArgumentNames, true);
2208
    }
2209
2210
    /**
2211
     * Method to check if grouping was enabled with typoscript.
2212
     *
2213
     * plugin.tx_solr.search.grouping
2214
     *
2215
     * @param bool $defaultIfEmpty
2216
     * @return bool
2217
     */
2218 123
    public function getIsSearchGroupingEnabled(bool $defaultIfEmpty = false): bool
2219
    {
2220 123
        $groupingEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.grouping', $defaultIfEmpty);
2221 123
        return $this->getBool($groupingEnabled);
2222
    }
2223
2224
    /**
2225
     * Returns the configured numberOfGroups.
2226
     *
2227
     * plugin.tx_solr.search.grouping.numberOfGroups
2228
     *
2229
     * @param int $defaultIfEmpty
2230
     * @return int
2231
     */
2232 1
    public function getSearchGroupingNumberOfGroups(int $defaultIfEmpty = 5): int
2233
    {
2234 1
        return (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.grouping.numberOfGroups', $defaultIfEmpty);
2235
    }
2236
2237
    /**
2238
     * Returns the sortBy configuration for the grouping.
2239
     *
2240
     * plugin.tx_solr.search.grouping.sortBy
2241
     *
2242
     * @param string $defaultIfEmpty
2243
     * @return string
2244
     */
2245 1
    public function getSearchGroupingSortBy(string $defaultIfEmpty = ''): string
2246
    {
2247 1
        return (string)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.grouping.sortBy', $defaultIfEmpty);
2248
    }
2249
2250
    /**
2251
     * Returns the highestValue of the numberOfResultsPerGroup configuration that is globally configured and
2252
     * for each group.
2253
     *
2254
     * plugin.tx_solr.search.grouping.
2255
     *
2256
     * @param ?int $defaultIfEmpty
2257
     * @return int
2258
     */
2259 3
    public function getSearchGroupingHighestGroupResultsLimit(?int $defaultIfEmpty = 1): int
2260
    {
2261 3
        $groupingConfiguration = $this->getObjectByPathOrDefault('plugin.tx_solr.search.grouping.', []);
2262 3
        $highestLimit = $defaultIfEmpty;
2263 3
        if (!empty($groupingConfiguration['numberOfResultsPerGroup'])) {
2264 2
            $highestLimit = $groupingConfiguration['numberOfResultsPerGroup'];
2265
        }
2266
2267 3
        if (!isset($groupingConfiguration['groups.']) || !is_array($groupingConfiguration['groups.'])) {
2268 1
            return $highestLimit;
2269
        }
2270
2271 2
        foreach ($groupingConfiguration['groups.'] as $groupConfiguration) {
2272 2
            if (!empty($groupConfiguration['numberOfResultsPerGroup']) && $groupConfiguration['numberOfResultsPerGroup'] > $highestLimit) {
2273 1
                $highestLimit = $groupConfiguration['numberOfResultsPerGroup'];
2274
            }
2275
        }
2276
2277 2
        return $highestLimit;
2278
    }
2279
2280
    /**
2281
     * Returns the valid numberOfResultsPerGroup value for a group.
2282
     *
2283
     * Returns:
2284
     *
2285
     * plugin.tx_solr.search.grouping.groups.<groupName>.numberOfResultsPerGroup if it is set otherwise
2286
     * plugin.tx_solr.search.grouping.numberOfResultsPerGroup
2287
     *
2288
     * @param string $groupName
2289
     * @param ?int $defaultIfEmpty
2290
     * @return int
2291
     */
2292
    public function getSearchGroupingResultLimit(string $groupName, ?int $defaultIfEmpty = 1): ?int
2293
    {
2294
        $specificPath = 'plugin.tx_solr.search.grouping.groups.' . $groupName . '.numberOfResultsPerGroup';
2295
        $specificResultsPerGroup = $this->getValueByPathOrDefaultValue($specificPath, null);
2296
2297
        if ($specificResultsPerGroup !== null) {
2298
            return (int)$specificResultsPerGroup;
2299
        }
2300
2301
        $commonPath = 'plugin.tx_solr.search.grouping.numberOfResultsPerGroup';
2302
        $commonValue = $this->getValueByPathOrDefaultValue($commonPath, null);
2303
        if ($commonValue !== null) {
2304
            return (int)$commonValue;
2305
        }
2306
2307
        return $defaultIfEmpty;
2308
    }
2309
2310
    /**
2311
     * Returns everything that is configured for the groups (plugin.tx_solr.search.grouping.groups.)
2312
     *
2313
     * plugin.tx_solr.search.grouping.groups.
2314
     *
2315
     * @param ?array $defaultIfEmpty
2316
     * @return array
2317
     */
2318 1
    public function getSearchGroupingGroupsConfiguration(?array $defaultIfEmpty = []): array
2319
    {
2320 1
        return $this->getObjectByPathOrDefault('plugin.tx_solr.search.grouping.groups.', $defaultIfEmpty);
2321
    }
2322
2323
    /*
2324
     * Applies the stdWrap if it is configured for the path, otherwise the unprocessed value will be returned.
2325
     *
2326
     * @param string $valuePath
2327
     * @param mixed $value
2328
     * @return mixed
2329
     */
2330
    protected function renderContentElementOfConfigured($valuePath, $value)
2331
    {
2332
        $configurationPath = $valuePath . '.';
2333
        $configuration = $this->getObjectByPath($configurationPath);
2334
2335
        if ($configuration == null) {
2336
            return $value;
2337
        }
2338
2339
        return $this->contentObjectService->renderSingleContentObject($value, $configuration);
2340
    }
2341
}
2342