|
1
|
|
|
<?php |
|
2
|
|
|
namespace ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\RangeBased\DateRange; |
|
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\FacetQueryBuilderInterface; |
|
18
|
|
|
use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration; |
|
19
|
|
|
|
|
20
|
|
|
class DateRangeFacetQueryBuilder implements FacetQueryBuilderInterface { |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @param string $facetName |
|
24
|
|
|
* @param TypoScriptConfiguration $configuration |
|
25
|
|
|
* @return array |
|
26
|
|
|
*/ |
|
27
|
|
|
public function build($facetName, TypoScriptConfiguration $configuration) |
|
28
|
|
|
{ |
|
29
|
|
|
$facetParameters = []; |
|
30
|
|
|
$facetConfiguration = $configuration->getSearchFacetingFacetByName($facetName); |
|
31
|
|
|
|
|
32
|
|
|
$tag = ''; |
|
33
|
|
|
if ($facetConfiguration['keepAllOptionsOnSelection'] == 1) { |
|
34
|
|
|
$tag = '{!ex=' . $facetConfiguration['field'] . '}'; |
|
35
|
|
|
} |
|
36
|
|
|
$facetParameters['facet.range'][] = $tag . $facetConfiguration['field']; |
|
37
|
|
|
|
|
38
|
|
|
$start = 'NOW/DAY-1YEAR'; |
|
39
|
|
|
if ($facetConfiguration['dateRange.']['start']) { |
|
40
|
|
|
$start = $facetConfiguration['dateRange.']['start']; |
|
41
|
|
|
} |
|
42
|
|
|
$facetParameters['f.' . $facetConfiguration['field'] . '.facet.range.start'] = $start; |
|
43
|
|
|
|
|
44
|
|
|
$end = 'NOW/DAY+1YEAR'; |
|
45
|
|
|
if ($facetConfiguration['dateRange.']['end']) { |
|
46
|
|
|
$end = $facetConfiguration['dateRange.']['end']; |
|
47
|
|
|
} |
|
48
|
|
|
$facetParameters['f.' . $facetConfiguration['field'] . '.facet.range.end'] = $end; |
|
49
|
|
|
|
|
50
|
|
|
$gap = '+1DAY'; |
|
51
|
|
|
if ($facetConfiguration['dateRange.']['gap']) { |
|
52
|
|
|
$gap = $facetConfiguration['dateRange.']['gap']; |
|
53
|
|
|
} |
|
54
|
|
|
$facetParameters['f.' . $facetConfiguration['field'] . '.facet.range.gap'] = $gap; |
|
55
|
|
|
|
|
56
|
|
|
return $facetParameters; |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|