|
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
|
|
|
public function build($facetName, TypoScriptConfiguration $configuration) |
|
27
|
|
|
{ |
|
28
|
|
|
$facetParameters = []; |
|
29
|
|
|
$facetConfiguration = $configuration->getSearchFacetingFacetByName($facetName); |
|
30
|
|
|
|
|
31
|
|
|
// simple for now, may add overrides f.<field_name>.facet.* later |
|
32
|
|
|
if ($configuration->getSearchFacetingKeepAllFacetsOnSelection()) { |
|
33
|
|
|
$facets = []; |
|
34
|
|
|
foreach ($configuration->getSearchFacetingFacets() as $facet) { |
|
35
|
|
|
$facets[] = $facet['field']; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
$facetParameters['facet.field'][] = '{!ex=' . implode(',', $facets) . '}' . $facetConfiguration['field']; |
|
39
|
|
|
} elseif ($facetConfiguration['keepAllOptionsOnSelection'] == 1) { |
|
40
|
|
|
$facetParameters['facet.field'][] = '{!ex=' . $facetConfiguration['field'] . '}' . $facetConfiguration['field']; |
|
41
|
|
|
} else { |
|
42
|
|
|
$facetParameters['facet.field'][] = $facetConfiguration['field']; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
if (in_array($facetConfiguration['sortBy'], ['alpha', 'index', 'lex'])) { |
|
46
|
|
|
$facetParameters['f.' . $facetConfiguration['field'] . '.facet.sort'] = 'lex'; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
return $facetParameters; |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
|