first commit

This commit is contained in:
Sven Wappler
2021-04-17 00:26:33 +02:00
commit 866c63cc63
813 changed files with 100696 additions and 0 deletions

View File

@@ -0,0 +1,74 @@
<?php
namespace WapplerSystems\Meilisearch\Domain\Search\ResultSet\Facets\RangeBased;
/*
* 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;
/**
* Abstract class that is used as base class for range facet items
*
* @author Frans Saris <frans@beech.it>
* @author Timo Hund <timo.hund@dkd.de>
*/
abstract class AbstractRangeFacetItem extends AbstractFacetItem
{
/**
* @var array
*/
protected $rangeCounts;
/**
* @var string
*/
protected $gap;
/**
* @return string
*/
public function getUriValue()
{
return $this->getRangeString();
}
/**
* @return string
*/
public function getCollectionKey()
{
return $this->getRangeString();
}
/**
* @return array
*/
public function getRangeCounts()
{
return $this->rangeCounts;
}
/**
* @return string
*/
public function getGap()
{
return $this->gap;
}
/**
* @return string
*/
abstract protected function getRangeString();
}

View File

@@ -0,0 +1,107 @@
<?php
namespace WapplerSystems\Meilisearch\Domain\Search\ResultSet\Facets\RangeBased;
/*
* 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\AbstractFacetParser;
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\SearchResultSet;
use WapplerSystems\Meilisearch\System\Solr\ParsingUtil;
/**
* Class AbstractRangeFacetParser
*
* @author Frans Saris <frans@beech.it>
* @author Timo Hund <timo.hund@dkd.de>
*/
abstract class AbstractRangeFacetParser extends AbstractFacetParser
{
/**
* @param SearchResultSet $resultSet
* @param string $facetName
* @param array $facetConfiguration
* @param string $facetClass
* @param string $facetItemClass
* @param string $facetRangeCountClass
* @return AbstractRangeFacet|null
*/
protected function getParsedFacet(SearchResultSet $resultSet, $facetName, array $facetConfiguration, $facetClass, $facetItemClass, $facetRangeCountClass)
{
$fieldName = $facetConfiguration['field'];
$label = $this->getPlainLabelOrApplyCObject($facetConfiguration);
$activeValue = $this->getActiveFacetValuesFromRequest($resultSet, $facetName);
$response = $resultSet->getResponse();
$valuesFromResponse = isset($response->facet_counts->facet_ranges->{$fieldName}) ? get_object_vars($response->facet_counts->facet_ranges->{$fieldName}) : [];
$facet = $this->objectManager->get(
$facetClass,
$resultSet,
$facetName,
$fieldName,
$label,
$facetConfiguration
);
$facet->setIsAvailable(count($valuesFromResponse) > 0);
$facet->setIsUsed(count($activeValue) > 0);
if (is_array($valuesFromResponse)) {
$rangeCounts = [];
$allCount = 0;
$countsFromResponse = isset($valuesFromResponse['counts']) ? ParsingUtil::getMapArrayFromFlatArray($valuesFromResponse['counts']) : [];
foreach ($countsFromResponse as $rangeCountValue => $count) {
$rangeCountValue = $this->parseResponseValue($rangeCountValue);
$rangeCount = $this->objectManager->get($facetRangeCountClass, $rangeCountValue, $count);
$rangeCounts[] = $rangeCount;
$allCount += $count;
}
$fromInResponse = $this->parseResponseValue($valuesFromResponse['start']);
$toInResponse = $this->parseResponseValue($valuesFromResponse['end']);
if (preg_match('/(-?\d*?)-(-?\d*)/', $activeValue[0], $rawValues) == 1) {
$rawFrom = $rawValues[1];
$rawTo = $rawValues[2];
} else {
$rawFrom = 0;
$rawTo = 0;
}
$from = $this->parseRequestValue($rawFrom);
$to = $this->parseRequestValue($rawTo);
$type = isset($facetConfiguration['type']) ? $facetConfiguration['type'] : 'numericRange';
$gap = isset($facetConfiguration[$type . '.']['gap']) ? $facetConfiguration[$type . '.']['gap'] : 1;
$range = $this->objectManager->get($facetItemClass, $facet, $from, $to, $fromInResponse, $toInResponse, $gap, $allCount, $rangeCounts, true);
$facet->setRange($range);
}
return $facet;
}
/**
* @param string $requestValue
* @return mixed
*/
abstract protected function parseRequestValue($requestValue);
/**
* @param string $responseValue
* @return mixed
*/
abstract protected function parseResponseValue($responseValue);
}

View File

@@ -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;
}
}

View File

@@ -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);
}
}

View File

@@ -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;
}
}

View File

@@ -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]);
}
}

View File

@@ -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));
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -0,0 +1,123 @@
<?php
namespace WapplerSystems\Meilisearch\Domain\Search\ResultSet\Facets\RangeBased\NumericRange;
/*
* 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;
/**
* Value object that represent an option of a numric range facet.
*
* @author Frans Saris <frans@beech.it>
* @author Timo Hund <timo.hund@dkd.de>
*/
class NumericRange extends AbstractRangeFacetItem
{
/**
* @var float
*/
protected $startRequested;
/**
* @var float
*/
protected $endRequested;
/**
* @var float
*/
protected $startInResponse;
/**
* @var float
*/
protected $endInResponse;
/**
* @param NumericRangeFacet $facet
* @param float|null $startRequested
* @param float|null $endRequested
* @param float|null $startInResponse
* @param float|null $endInResponse
* @param string $gap
* @param int $documentCount
* @param array $rangeCounts
* @param bool $selected
*/
public function __construct(NumericRangeFacet $facet, $startRequested = null, $endRequested = null, $startInResponse = null, $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 !== null && $endRequested !== null) {
$label = $this->getRangeString();
}
parent::__construct($facet, $label, $documentCount, $selected);
}
/**
* @return string
*/
protected function getRangeString()
{
return $this->startRequested . '-' . $this->endRequested;
}
/**
* Retrieves the end date that was requested by the user for this facet.
*
* @return float
*/
public function getEndRequested()
{
return $this->endRequested;
}
/**
* Retrieves the start date that was requested by the used for the facet.
*
* @return float
*/
public function getStartRequested()
{
return $this->startRequested;
}
/**
* Retrieves the end date that was received from solr for this facet.
*
* @return float
*/
public function getEndInResponse()
{
return $this->endInResponse;
}
/**
* Retrieves the start date that was received from solr for this facet.
*
* @return float
*/
public function getStartInResponse()
{
return $this->startInResponse;
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace WapplerSystems\Meilisearch\Domain\Search\ResultSet\Facets\RangeBased\NumericRange;
/*
* 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 NumericRangeCollection extends AbstractFacetItemCollection
{
/**
* @param NumericRange $numericRange
* @return NumericRangeCollection
*/
public function add($numericRange)
{
return parent::add($numericRange);
}
/**
* @param int $position
* @return NumericRange
*/
public function getByPosition($position)
{
return parent::getByPosition($position);
}
}

View File

@@ -0,0 +1,63 @@
<?php
namespace WapplerSystems\Meilisearch\Domain\Search\ResultSet\Facets\RangeBased\NumericRange;
/*
* 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 NumericRangeCount
{
/**
* @var float
*/
protected $rangeItem;
/**
* @var int
*/
protected $documentCount = 0;
/**
* @param float $rangeItem
* @param integer $documentCount
*/
public function __construct($rangeItem, $documentCount)
{
$this->rangeItem = $rangeItem;
$this->documentCount = $documentCount;
}
/**
* @return float
*/
public function getRangeItem()
{
return $this->rangeItem;
}
/**
* @return int
*/
public function getDocumentCount()
{
return $this->documentCount;
}
}

View File

@@ -0,0 +1,93 @@
<?php
namespace WapplerSystems\Meilisearch\Domain\Search\ResultSet\Facets\RangeBased\NumericRange;
/*
* 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 NumericRangeFacet extends AbstractFacet
{
const TYPE_NUMERIC_RANGE = 'numericRange';
/**
* String
* @var string
*/
protected static $type = self::TYPE_NUMERIC_RANGE;
/**
* @var NumericRange
*/
protected $numericRange;
/**
* 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 NumericRange $range
*/
public function setRange(NumericRange $range)
{
$this->numericRange = $range;
}
/**
* @return NumericRange
*/
public function getRange()
{
return $this->numericRange;
}
/**
* Get facet partial name used for rendering the facet
*
* @return string
*/
public function getPartialName()
{
return !empty($this->configuration['partialName']) ? $this->configuration['partialName'] : 'RangeNumeric.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 NumericRangeCollection([$this->numericRange]);
}
}

View File

@@ -0,0 +1,77 @@
<?php
namespace WapplerSystems\Meilisearch\Domain\Search\ResultSet\Facets\RangeBased\NumericRange;
/*
* 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;
/**
* Class NumericRangeFacetParser
*
* @author Frans Saris <frans@beech.it>
* @author Timo Hund <timo.hund@dkd.de>
*/
class NumericRangeFacetParser extends AbstractRangeFacetParser
{
/**
* @var string
*/
protected $facetClass = NumericRangeFacet::class;
/**
* @var string
*/
protected $facetItemClass = NumericRange::class;
/**
* @var string
*/
protected $facetRangeCountClass = NumericRangeCount::class;
/**
* @param SearchResultSet $resultSet
* @param string $facetName
* @param array $facetConfiguration
* @return NumericRangeFacet|null
*/
public function parse(SearchResultSet $resultSet, $facetName, array $facetConfiguration)
{
return $this->getParsedFacet(
$resultSet,
$facetName,
$facetConfiguration,
$this->facetClass,
$this->facetItemClass,
$this->facetRangeCountClass
);
}
/**
* @param mixed $rawValue
* @return mixed (numeric value)
*/
protected function parseRequestValue($rawValue)
{
return is_numeric($rawValue) ? $rawValue : 0;
}
/**
* @param $rawValue
* @return mixed (numeric value)
*/
protected function parseResponseValue($rawValue)
{
return is_numeric($rawValue) ? $rawValue : 0;
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace WapplerSystems\Meilisearch\Domain\Search\ResultSet\Facets\RangeBased\NumericRange;
/*
* 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 NumericRangeFacetQueryBuilder 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'];
$facetParameters['f.' . $facetConfiguration['field'] . '.facet.range.start'] = $facetConfiguration['numericRange.']['start'];
$facetParameters['f.' . $facetConfiguration['field'] . '.facet.range.end'] = $facetConfiguration['numericRange.']['end'];
$facetParameters['f.' . $facetConfiguration['field'] . '.facet.range.gap'] = $facetConfiguration['numericRange.']['gap'];
return $facetParameters;
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace WapplerSystems\Meilisearch\Domain\Search\ResultSet\Facets\RangeBased\NumericRange;
/*
* 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 NumericRangePackage
*/
class NumericRangePackage extends AbstractFacetPackage {
/**
* @return string
*/
public function getParserClassName() {
return (string)NumericRangeFacetParser::class;
}
/**
* @return string
*/
public function getQueryBuilderClassName()
{
return (string)NumericRangeFacetQueryBuilder::class;
}
/**
* @return string
*/
public function getUrlDecoderClassName()
{
return (string)NumericRangeUrlDecoder::class;
}
}

View File

@@ -0,0 +1,69 @@
<?php
namespace WapplerSystems\Meilisearch\Domain\Search\ResultSet\Facets\RangeBased\NumericRange;
/***************************************************************
* Copyright notice
*
* (c) 2010-2011 Markus Goldbach <markus.goldbach@dkd.de>
* (c) 2012-2015 Ingo Renner <ingo@typo3.org>
* (c) 2016 Markus Friedrich <markus.friedrich@dkd.de>
* 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;
/**
* Parser to build Solr range queries from tx_meilisearch[filter]
*
* @author Markus Goldbach <markus.goldbach@dkd.de>
* @author Ingo Renner <ingo@typo3.org>
* @author Markus Friedrich <markus.friedrich@dkd.de>
*/
class NumericRangeUrlDecoder implements FacetUrlDecoderInterface
{
/**
* Delimiter for ranges in the URL.
*
* @var string
*/
const DELIMITER = '-';
/**
* Parses the given range from a GET parameter and returns a Solr range
* filter.
*
* @param string $range The range filter from the URL.
* @param array $configuration Facet configuration
* @return string Lucene query language filter to be used for querying Solr
* @throws \InvalidArgumentException
*/
public function decode($range, array $configuration = [])
{
preg_match('/(-?\d*?)' . self::DELIMITER . '(-?\d*)/', $range, $filterParts);
if ($filterParts[1] == '' || $filterParts[2] == '') {
throw new \InvalidArgumentException(
'Invalid numeric range given',
1466062730
);
}
return '[' . (int)$filterParts[1] . ' TO ' . (int)$filterParts[2] . ']';
}
}