1
|
|
|
<?php |
2
|
|
|
namespace ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\RangeBased; |
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\Domain\Search\ResultSet\Facets\AbstractFacetParser; |
18
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSet; |
19
|
|
|
use ApacheSolrForTypo3\Solr\System\Solr\ParsingUtil; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class AbstractRangeFacetParser |
23
|
|
|
* |
24
|
|
|
* @author Frans Saris <[email protected]> |
25
|
|
|
* @author Timo Hund <[email protected]> |
26
|
|
|
*/ |
27
|
|
|
abstract class AbstractRangeFacetParser extends AbstractFacetParser |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @param SearchResultSet $resultSet |
31
|
|
|
* @param string $facetName |
32
|
|
|
* @param array $facetConfiguration |
33
|
|
|
* @param string $facetClass |
34
|
|
|
* @param string $facetItemClass |
35
|
|
|
* @param string $facetRangeCountClass |
36
|
|
|
* @return AbstractRangeFacet|null |
37
|
|
|
*/ |
38
|
1 |
|
protected function getParsedFacet(SearchResultSet $resultSet, $facetName, array $facetConfiguration, $facetClass, $facetItemClass, $facetRangeCountClass) |
39
|
|
|
{ |
40
|
1 |
|
$fieldName = $facetConfiguration['field']; |
41
|
1 |
|
$label = $this->getPlainLabelOrApplyCObject($facetConfiguration); |
42
|
1 |
|
$activeValue = $this->getActiveFacetValuesFromRequest($resultSet, $facetName); |
43
|
1 |
|
$response = $resultSet->getResponse(); |
44
|
|
|
|
45
|
1 |
|
$valuesFromResponse = isset($response->facet_counts->facet_ranges->{$fieldName}) ? get_object_vars($response->facet_counts->facet_ranges->{$fieldName}) : []; |
46
|
|
|
|
47
|
1 |
|
$facet = $this->objectManager->get( |
|
|
|
|
48
|
1 |
|
$facetClass, |
49
|
1 |
|
$resultSet, |
50
|
1 |
|
$facetName, |
51
|
1 |
|
$fieldName, |
52
|
1 |
|
$label, |
53
|
1 |
|
$facetConfiguration |
54
|
|
|
); |
55
|
|
|
|
56
|
1 |
|
$facet->setIsAvailable(count($valuesFromResponse) > 0); |
57
|
1 |
|
$facet->setIsUsed(count($activeValue) > 0); |
58
|
|
|
|
59
|
1 |
|
if (is_array($valuesFromResponse)) { |
|
|
|
|
60
|
1 |
|
$rangeCounts = []; |
61
|
1 |
|
$allCount = 0; |
62
|
|
|
|
63
|
1 |
|
$countsFromResponse = isset($valuesFromResponse['counts']) ? ParsingUtil::getMapArrayFromFlatArray($valuesFromResponse['counts']) : []; |
64
|
|
|
|
65
|
1 |
|
foreach ($countsFromResponse as $rangeCountValue => $count) { |
66
|
|
|
$rangeCountValue = $this->parseResponseValue($rangeCountValue); |
67
|
|
|
$rangeCount = $this->objectManager->get($facetRangeCountClass, $rangeCountValue, $count); |
|
|
|
|
68
|
|
|
$rangeCounts[] = $rangeCount; |
69
|
|
|
$allCount += $count; |
70
|
|
|
} |
71
|
|
|
|
72
|
1 |
|
$fromInResponse = $this->parseResponseValue($valuesFromResponse['start']); |
73
|
1 |
|
$toInResponse = $this->parseResponseValue($valuesFromResponse['end']); |
74
|
|
|
|
75
|
1 |
|
if (preg_match('/(-?\d*?)-(-?\d*)/', $activeValue[0], $rawValues) == 1) { |
76
|
|
|
$rawFrom = $rawValues[1]; |
77
|
|
|
$rawTo = $rawValues[2]; |
78
|
|
|
} else { |
79
|
1 |
|
$rawFrom = 0; |
80
|
1 |
|
$rawTo = 0; |
81
|
|
|
} |
82
|
|
|
|
83
|
1 |
|
$from = $this->parseRequestValue($rawFrom); |
84
|
1 |
|
$to = $this->parseRequestValue($rawTo); |
85
|
|
|
|
86
|
1 |
|
$type = isset($facetConfiguration['type']) ? $facetConfiguration['type'] : 'numericRange'; |
87
|
1 |
|
$gap = isset($facetConfiguration[$type . '.']['gap']) ? $facetConfiguration[$type . '.']['gap'] : 1; |
88
|
|
|
|
89
|
1 |
|
$range = $this->objectManager->get($facetItemClass, $facet, $from, $to, $fromInResponse, $toInResponse, $gap, $allCount, $rangeCounts, true); |
|
|
|
|
90
|
1 |
|
$facet->setRange($range); |
91
|
|
|
} |
92
|
|
|
|
93
|
1 |
|
return $facet; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param string $requestValue |
98
|
|
|
* @return mixed |
99
|
|
|
*/ |
100
|
|
|
abstract protected function parseRequestValue($requestValue); |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @param string $responseValue |
104
|
|
|
* @return mixed |
105
|
|
|
*/ |
106
|
|
|
abstract protected function parseResponseValue($responseValue); |
107
|
|
|
} |
108
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.