first commit
This commit is contained in:
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
namespace WapplerSystems\Meilisearch\Domain\Search\ResultSet\Facets\RangeBased\DateRange;
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\Facets\RangeBased\AbstractRangeFacetItem;
|
||||
use DateTime;
|
||||
|
||||
/**
|
||||
* Value object that represent an option of a options facet.
|
||||
*
|
||||
* @author Frans Saris <frans@beech.it>
|
||||
* @author Timo Hund <timo.hund@dkd.de>
|
||||
*/
|
||||
class DateRange extends AbstractRangeFacetItem
|
||||
{
|
||||
/**
|
||||
* @var DateTime
|
||||
*/
|
||||
protected $startRequested;
|
||||
|
||||
/**
|
||||
* @var DateTime
|
||||
*/
|
||||
protected $endRequested;
|
||||
|
||||
/**
|
||||
* @var DateTime
|
||||
*/
|
||||
protected $startInResponse;
|
||||
|
||||
/**
|
||||
* @var DateTime
|
||||
*/
|
||||
protected $endInResponse;
|
||||
|
||||
/**
|
||||
* @param DateRangeFacet $facet
|
||||
* @param DateTime|null $startRequested
|
||||
* @param DateTime|null $endRequested
|
||||
* @param DateTime|null $startInResponse
|
||||
* @param DateTime|null $endInResponse
|
||||
* @param string $gap
|
||||
* @param int $documentCount
|
||||
* @param array $rangeCounts
|
||||
* @param bool $selected
|
||||
*/
|
||||
public function __construct(DateRangeFacet $facet, DateTime $startRequested = null, DateTime $endRequested = null, DateTime $startInResponse = null, DateTime $endInResponse = null, $gap = '', $documentCount = 0, $rangeCounts, $selected = false)
|
||||
{
|
||||
$this->startInResponse = $startInResponse;
|
||||
$this->endInResponse = $endInResponse;
|
||||
$this->startRequested = $startRequested;
|
||||
$this->endRequested = $endRequested;
|
||||
$this->rangeCounts = $rangeCounts;
|
||||
$this->gap = $gap;
|
||||
|
||||
$label = '';
|
||||
if ($startRequested instanceof DateTime && $endRequested instanceof DateTime) {
|
||||
$label = $this->getRangeString();
|
||||
}
|
||||
|
||||
|
||||
parent::__construct($facet, $label, $documentCount, $selected);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getRangeString()
|
||||
{
|
||||
return $this->startRequested->format('Ymd') . '0000-' . $this->endRequested->format('Ymd') . '0000';
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the end date that was requested by the user for this facet.
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getEndRequested()
|
||||
{
|
||||
return $this->endRequested;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the start date that was requested by the used for the facet.
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getStartRequested()
|
||||
{
|
||||
return $this->startRequested;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the end date that was received from solr for this facet.
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getEndInResponse()
|
||||
{
|
||||
return $this->endInResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the start date that was received from solr for this facet.
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getStartInResponse()
|
||||
{
|
||||
return $this->startInResponse;
|
||||
}
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
namespace WapplerSystems\Meilisearch\Domain\Search\ResultSet\Facets\RangeBased\DateRange;
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\Facets\AbstractFacetItemCollection;
|
||||
|
||||
/**
|
||||
* Collection for facet options.
|
||||
*
|
||||
* @author Frans Saris <frans@beech.it>
|
||||
* @author Timo Hund <timo.hund@dkd.de>
|
||||
*/
|
||||
class DateRangeCollection extends AbstractFacetItemCollection
|
||||
{
|
||||
|
||||
/**
|
||||
* @param DateRange $dateRange
|
||||
* @return DateRangeCollection
|
||||
*/
|
||||
public function add($dateRange)
|
||||
{
|
||||
return parent::add($dateRange);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $position
|
||||
* @return DateRange
|
||||
*/
|
||||
public function getByPosition($position)
|
||||
{
|
||||
return parent::getByPosition($position);
|
||||
}
|
||||
}
|
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
namespace WapplerSystems\Meilisearch\Domain\Search\ResultSet\Facets\RangeBased\DateRange;
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\Facets\AbstractFacetItem;
|
||||
use DateTime;
|
||||
|
||||
/**
|
||||
* Value object that represent an date range count. The count has a date and the count of documents
|
||||
*
|
||||
* @author Frans Saris <frans@beech.it>
|
||||
* @author Timo Hund <timo.hund@dkd.de>
|
||||
*/
|
||||
class DateRangeCount
|
||||
{
|
||||
|
||||
/**
|
||||
* @var DateTime
|
||||
*/
|
||||
protected $date;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $documentCount = 0;
|
||||
|
||||
/**
|
||||
* @param $date
|
||||
* @param $documentCount
|
||||
*/
|
||||
public function __construct($date, $documentCount)
|
||||
{
|
||||
$this->date = $date;
|
||||
$this->documentCount = $documentCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getDate()
|
||||
{
|
||||
return $this->date;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getDocumentCount()
|
||||
{
|
||||
return $this->documentCount;
|
||||
}
|
||||
}
|
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
namespace WapplerSystems\Meilisearch\Domain\Search\ResultSet\Facets\RangeBased\DateRange;
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\Facets\AbstractFacet;
|
||||
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\Facets\AbstractFacetItemCollection;
|
||||
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\SearchResultSet;
|
||||
|
||||
/**
|
||||
* Value object that represent a date range facet.
|
||||
*
|
||||
* @author Frans Saris <frans@beech.it>
|
||||
* @author Timo Hund <timo.hund@dkd.de>
|
||||
*/
|
||||
class DateRangeFacet extends AbstractFacet
|
||||
{
|
||||
const TYPE_DATE_RANGE = 'dateRange';
|
||||
|
||||
/**
|
||||
* String
|
||||
* @var string
|
||||
*/
|
||||
protected static $type = self::TYPE_DATE_RANGE;
|
||||
|
||||
/**
|
||||
* @var DateRange
|
||||
*/
|
||||
protected $range;
|
||||
|
||||
/**
|
||||
* OptionsFacet constructor
|
||||
*
|
||||
* @param SearchResultSet $resultSet
|
||||
* @param string $name
|
||||
* @param string $field
|
||||
* @param string $label
|
||||
* @param array $configuration Facet configuration passed from typoscript
|
||||
*/
|
||||
public function __construct(SearchResultSet $resultSet, $name, $field, $label = '', array $configuration = [])
|
||||
{
|
||||
parent::__construct($resultSet, $name, $field, $label, $configuration);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DateRange $range
|
||||
*/
|
||||
public function setRange(DateRange $range)
|
||||
{
|
||||
$this->range = $range;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DateRange
|
||||
*/
|
||||
public function getRange()
|
||||
{
|
||||
return $this->range;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get facet partial name used for rendering the facet
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPartialName()
|
||||
{
|
||||
return !empty($this->configuration['partialName']) ? $this->configuration['partialName'] : 'RangeDate.html';
|
||||
}
|
||||
|
||||
/**
|
||||
* Since the DateRange contains only one or two items when return a collection with the range only to
|
||||
* allow to render the date range as other facet items.
|
||||
*
|
||||
* @return AbstractFacetItemCollection
|
||||
*/
|
||||
public function getAllFacetItems()
|
||||
{
|
||||
return new DateRangeCollection([$this->range]);
|
||||
}
|
||||
}
|
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
namespace WapplerSystems\Meilisearch\Domain\Search\ResultSet\Facets\RangeBased\DateRange;
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\Facets\RangeBased\AbstractRangeFacetParser;
|
||||
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\SearchResultSet;
|
||||
use WapplerSystems\Meilisearch\System\Data\DateTime;
|
||||
|
||||
/**
|
||||
* Class DateRangeFacetParser
|
||||
*
|
||||
* @author Frans Saris <frans@beech.it>
|
||||
* @author Timo Hund <timo.hund@dkd.de>
|
||||
*/
|
||||
class DateRangeFacetParser extends AbstractRangeFacetParser
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $facetClass = DateRangeFacet::class;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $facetItemClass = DateRange::class;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $facetRangeCountClass = DateRangeCount::class;
|
||||
|
||||
/**
|
||||
* @param SearchResultSet $resultSet
|
||||
* @param string $facetName
|
||||
* @param array $facetConfiguration
|
||||
* @return DateRangeFacet|null
|
||||
*/
|
||||
public function parse(SearchResultSet $resultSet, $facetName, array $facetConfiguration)
|
||||
{
|
||||
return $this->getParsedFacet(
|
||||
$resultSet,
|
||||
$facetName,
|
||||
$facetConfiguration,
|
||||
$this->facetClass,
|
||||
$this->facetItemClass,
|
||||
$this->facetRangeCountClass
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $rawDate
|
||||
* @return DateTime|null
|
||||
*/
|
||||
protected function parseRequestValue($rawDate)
|
||||
{
|
||||
$rawDate = \DateTime::createFromFormat('Ymd', substr($rawDate, 0, 8));
|
||||
if ($rawDate === false) {
|
||||
return null;
|
||||
}
|
||||
$date = new DateTime($rawDate->format(DateTime::ISO8601));
|
||||
return $date;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $isoDateString
|
||||
* @return DateTime
|
||||
*/
|
||||
protected function parseResponseValue($isoDateString)
|
||||
{
|
||||
$rawDate = \DateTime::createFromFormat(\DateTime::ISO8601, $isoDateString);
|
||||
return new DateTime($rawDate->format(DateTime::ISO8601));
|
||||
}
|
||||
}
|
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
namespace WapplerSystems\Meilisearch\Domain\Search\ResultSet\Facets\RangeBased\DateRange;
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\Facets\FacetQueryBuilderInterface;
|
||||
use WapplerSystems\Meilisearch\System\Configuration\TypoScriptConfiguration;
|
||||
|
||||
class DateRangeFacetQueryBuilder implements FacetQueryBuilderInterface {
|
||||
|
||||
/**
|
||||
* @param string $facetName
|
||||
* @param TypoScriptConfiguration $configuration
|
||||
* @return array
|
||||
*/
|
||||
public function build($facetName, TypoScriptConfiguration $configuration)
|
||||
{
|
||||
$facetParameters = [];
|
||||
$facetConfiguration = $configuration->getSearchFacetingFacetByName($facetName);
|
||||
|
||||
$tag = '';
|
||||
if ($facetConfiguration['keepAllOptionsOnSelection'] == 1) {
|
||||
$tag = '{!ex=' . $facetConfiguration['field'] . '}';
|
||||
}
|
||||
$facetParameters['facet.range'][] = $tag . $facetConfiguration['field'];
|
||||
|
||||
$start = 'NOW/DAY-1YEAR';
|
||||
if ($facetConfiguration['dateRange.']['start']) {
|
||||
$start = $facetConfiguration['dateRange.']['start'];
|
||||
}
|
||||
$facetParameters['f.' . $facetConfiguration['field'] . '.facet.range.start'] = $start;
|
||||
|
||||
$end = 'NOW/DAY+1YEAR';
|
||||
if ($facetConfiguration['dateRange.']['end']) {
|
||||
$end = $facetConfiguration['dateRange.']['end'];
|
||||
}
|
||||
$facetParameters['f.' . $facetConfiguration['field'] . '.facet.range.end'] = $end;
|
||||
|
||||
$gap = '+1DAY';
|
||||
if ($facetConfiguration['dateRange.']['gap']) {
|
||||
$gap = $facetConfiguration['dateRange.']['gap'];
|
||||
}
|
||||
$facetParameters['f.' . $facetConfiguration['field'] . '.facet.range.gap'] = $gap;
|
||||
|
||||
return $facetParameters;
|
||||
}
|
||||
}
|
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
namespace WapplerSystems\Meilisearch\Domain\Search\ResultSet\Facets\RangeBased\DateRange;
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\Facets\AbstractFacetPackage;
|
||||
|
||||
/**
|
||||
* Class DateRangePackage
|
||||
*/
|
||||
class DateRangePackage extends AbstractFacetPackage {
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getParserClassName() {
|
||||
return (string)DateRangeFacetParser::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getQueryBuilderClassName()
|
||||
{
|
||||
return (string)DateRangeFacetQueryBuilder::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getUrlDecoderClassName()
|
||||
{
|
||||
return (string)DateRangeUrlDecoder::class;
|
||||
}
|
||||
}
|
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
namespace WapplerSystems\Meilisearch\Domain\Search\ResultSet\Facets\RangeBased\DateRange;
|
||||
|
||||
/***************************************************************
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2010-2011 Markus Goldbach <markus.goldbach@dkd.de>
|
||||
* (c) 2012-2015 Ingo Renner <ingo@typo3.org>
|
||||
* All rights reserved
|
||||
*
|
||||
* This script is part of the TYPO3 project. The TYPO3 project is
|
||||
* free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* The GNU General Public License can be found at
|
||||
* http://www.gnu.org/copyleft/gpl.html.
|
||||
*
|
||||
* This script is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* This copyright notice MUST APPEAR in all copies of the script!
|
||||
***************************************************************/
|
||||
|
||||
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\Facets\FacetUrlDecoderInterface;
|
||||
use WapplerSystems\Meilisearch\System\DateTime\FormatService;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
/**
|
||||
* Parser to build solr range queries from tx_meilisearch[filter]
|
||||
*
|
||||
* @author Markus Goldbach <markus.goldbach@dkd.de>
|
||||
*/
|
||||
class DateRangeUrlDecoder implements FacetUrlDecoderInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Delimiter for date parts in the URL.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const DELIMITER = '-';
|
||||
|
||||
/**
|
||||
* Parses the given date range from a GET parameter and returns a Solr
|
||||
* date range filter.
|
||||
*
|
||||
* @param string $dateRange The range filter query string from the query URL
|
||||
* @param array $configuration Facet configuration
|
||||
* @return string Lucene query language filter to be used for querying Solr
|
||||
*/
|
||||
public function decode($dateRange, array $configuration = [])
|
||||
{
|
||||
list($dateRangeStart, $dateRangeEnd) = explode(self::DELIMITER, $dateRange);
|
||||
|
||||
$formatService = GeneralUtility::makeInstance(FormatService::class);
|
||||
$fromPart = '*';
|
||||
if($dateRangeStart !== ''){
|
||||
$fromPart = $formatService->timestampToIso(strtotime($dateRangeStart));
|
||||
}
|
||||
|
||||
$toPart = '*';
|
||||
if($dateRangeEnd !== ''){
|
||||
$dateRangeEnd .= '59'; // adding 59 seconds
|
||||
$toPart = $formatService->timestampToIso(strtotime($dateRangeEnd));
|
||||
}
|
||||
|
||||
$dateRangeFilter = '[' . $fromPart . ' TO ' . $toPart . ']';
|
||||
return $dateRangeFilter;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user