1
|
|
|
<?php |
2
|
|
|
namespace ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets; |
3
|
|
|
|
4
|
|
|
/* |
5
|
|
|
* This file is part of the TYPO3 CMS project. |
6
|
|
|
* |
7
|
|
|
* It is free software; you can redistribute it and/or modify it under |
8
|
|
|
* the terms of the GNU General Public License, either version 2 |
9
|
|
|
* of the License, or any later version. |
10
|
|
|
* |
11
|
|
|
* For the full copyright and license information, please read the |
12
|
|
|
* LICENSE.txt file that was distributed with this source code. |
13
|
|
|
* |
14
|
|
|
* The TYPO3 project - inspiring people to share! |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration; |
18
|
|
|
|
19
|
|
|
class DefaultFacetQueryBuilder implements FacetQueryBuilderInterface { |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @param string $facetName |
23
|
|
|
* @param TypoScriptConfiguration $configuration |
24
|
|
|
* @return array |
25
|
|
|
*/ |
26
|
34 |
|
public function build($facetName, TypoScriptConfiguration $configuration) |
27
|
|
|
{ |
28
|
34 |
|
$facetParameters = []; |
29
|
34 |
|
$facetConfiguration = $configuration->getSearchFacetingFacetByName($facetName); |
30
|
|
|
|
31
|
|
|
$tags = $this->buildExcludeTags($facetConfiguration, $configuration); |
32
|
34 |
|
$facetParameters['facet.field'][] = $tags . $facetConfiguration['field']; |
33
|
2 |
|
|
34
|
2 |
|
if (in_array($facetConfiguration['sortBy'], ['alpha', 'index', 'lex'])) { |
35
|
2 |
|
$facetParameters['f.' . $facetConfiguration['field'] . '.facet.sort'] = 'lex'; |
36
|
|
|
} |
37
|
|
|
|
38
|
2 |
|
return $facetParameters; |
39
|
32 |
|
} |
40
|
29 |
|
|
41
|
|
|
/** |
42
|
32 |
|
* @param array $facetConfiguration |
43
|
|
|
* @param TypoScriptConfiguration $configuration |
44
|
|
|
* @return string |
45
|
34 |
|
*/ |
46
|
2 |
|
protected function buildExcludeTags(array $facetConfiguration, TypoScriptConfiguration $configuration) |
47
|
|
|
{ |
48
|
|
|
// simple for now, may add overrides f.<field_name>.facet.* later |
49
|
34 |
|
if ($configuration->getSearchFacetingKeepAllFacetsOnSelection()) { |
50
|
|
|
$facets = []; |
51
|
|
|
foreach ($configuration->getSearchFacetingFacets() as $facet) { |
52
|
|
|
$facets[] = $facet['field']; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
return '{!ex=' . implode(',', $facets) . '}'; |
56
|
|
|
} elseif ($facetConfiguration['keepAllOptionsOnSelection'] == 1) { |
57
|
|
|
return '{!ex=' . $facetConfiguration['field'] . '}'; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return ''; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
|