Passed
Pull Request — master (#1328)
by Timo
20:51
created

QueryGroupFacetQueryBuilder   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 71.43%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 33
ccs 10
cts 14
cp 0.7143
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B build() 0 25 5
1
<?php
2
namespace ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\OptionBased\QueryGroup;
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
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\FacetQueryBuilderInterface;
17
use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration;
18
19
class QueryGroupFacetQueryBuilder implements FacetQueryBuilderInterface {
20
21
    /**
22
     * @param string $facetName
23
     * @param TypoScriptConfiguration $configuration
24
     * @return array
25
     */
26 23
    public function build($facetName, TypoScriptConfiguration $configuration)
27
    {
28 23
        $facetParameters = [];
29 23
        $facetConfiguration = $configuration->getSearchFacetingFacetByName($facetName);
30
31 23
        foreach ($facetConfiguration['queryGroup.'] as $queryName => $queryConfiguration) {
32 23
            $tag = '';
33 23
            if ($configuration->getSearchFacetingKeepAllFacetsOnSelection()) {
34
                // TODO This code is duplicated from "Query/Modifier/Faceting.php"
35
                // Eventually the "exclude fields" should get passed to this method beforehand instead
36
                // of generating them in each different "buildFacetParameters" implementation
37
                $facets = [];
38
                foreach ($configuration->getSearchFacetingFacets() as $facet) {
39
                    $facets[] = $facet['field'];
40
                }
41
                $tag = '{!ex=' . implode(',', $facets) . '}';
42 23
            } elseif ($facetConfiguration['keepAllOptionsOnSelection'] == 1) {
43 1
                $tag = '{!ex=' . $facetConfiguration['field'] . '}';
44
            }
45
46 23
            $facetParameters['facet.query'][] = $tag . $facetConfiguration['field'] . ':' . $queryConfiguration['query'];
47
        }
48
49 23
        return $facetParameters;
50
    }
51
}
52