Passed
Push — master ( ae02be...f196a8 )
by Timo
21:07
created

DefaultFacetQueryBuilder::build()   B

Complexity

Conditions 5
Paths 6

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 25
ccs 14
cts 14
cp 1
rs 8.439
c 0
b 0
f 0
cc 5
eloc 15
nc 6
nop 2
crap 5
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 29
    public function build($facetName, TypoScriptConfiguration $configuration)
27
    {
28 29
        $facetParameters = [];
29 29
        $facetConfiguration = $configuration->getSearchFacetingFacetByName($facetName);
30
31
        // simple for now, may add overrides f.<field_name>.facet.* later
32 29
        if ($configuration->getSearchFacetingKeepAllFacetsOnSelection()) {
33 2
            $facets = [];
34 2
            foreach ($configuration->getSearchFacetingFacets() as $facet) {
35 2
                $facets[] = $facet['field'];
36
            }
37
38 2
            $facetParameters['facet.field'][] = '{!ex=' . implode(',', $facets) . '}' . $facetConfiguration['field'];
39 27
        } elseif ($facetConfiguration['keepAllOptionsOnSelection'] == 1) {
40 24
            $facetParameters['facet.field'][] = '{!ex=' . $facetConfiguration['field'] . '}' . $facetConfiguration['field'];
41
        } else {
42 27
            $facetParameters['facet.field'][] = $facetConfiguration['field'];
43
        }
44
45 29
        if (in_array($facetConfiguration['sortBy'], ['alpha', 'index', 'lex'])) {
46 2
            $facetParameters['f.' . $facetConfiguration['field'] . '.facet.sort'] = 'lex';
47
        }
48
49 29
        return $facetParameters;
50
    }
51
}
52
53