search_core/Classes/Domain/Model/SearchRequest.php

322 lines
8.5 KiB
PHP
Raw Normal View History

<?php
namespace Codappix\SearchCore\Domain\Model;
/*
2016-12-09 13:19:35 +01:00
* Copyright (C) 2016 Daniel Siepmann <coding@daniel-siepmann.de>
*
* This program 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 2
* of the License, or (at your option) any later version.
*
* This program 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
use Codappix\SearchCore\Connection\ConnectionInterface;
use Codappix\SearchCore\Connection\FacetRequestInterface;
use Codappix\SearchCore\Connection\SearchRequestInterface;
use Codappix\SearchCore\Domain\Search\SearchService;
/**
2016-12-09 13:19:35 +01:00
* Represents a search request used to process an actual search.
*/
2016-12-09 13:19:35 +01:00
class SearchRequest implements SearchRequestInterface
{
2019-06-06 15:25:41 +02:00
use QueryResultInterfaceStub;
2016-12-09 13:19:35 +01:00
/**
* The search string provided by the user, the actual term to search for.
*
* @var string
*/
2019-06-06 15:25:41 +02:00
protected $query = '';
/**
* @var array
*/
protected $filter = [];
2016-12-09 13:19:35 +01:00
/**
* @var array
*/
protected $facets = [];
/**
2019-06-06 15:25:41 +02:00
* @var int
*/
protected $offset = 0;
/**
* @var int
*/
2019-06-06 15:25:41 +02:00
protected $limit = 10;
/**
* Used for QueryInterface implementation to allow execute method to work.
*
* @var ConnectionInterface
*/
protected $connection = null;
/**
* @var SearchService
*/
protected $searchService = null;
2016-12-09 13:19:35 +01:00
/**
* @param string $query
*/
2019-06-06 15:25:41 +02:00
public function __construct(string $query = '')
2016-12-09 13:19:35 +01:00
{
2019-06-06 15:25:41 +02:00
$this->query = $query;
}
public function getQuery() : string
{
return $this->query;
}
public function getSearchTerm() : string
{
2019-06-06 15:25:41 +02:00
return $this->query;
}
/**
* @param array $filter
*/
public function setFilter(array $filter)
{
$filter = \TYPO3\CMS\Core\Utility\ArrayUtility::removeArrayEntryByValue($filter, '');
2018-10-17 15:54:54 +02:00
$this->filter = \TYPO3\CMS\Core\Utility\ArrayUtility::filterRecursive($filter, function ($value) {
2019-06-06 15:25:41 +02:00
return !empty($value);
2018-10-17 15:54:54 +02:00
});
}
public function hasFilter() : bool
{
return count($this->filter) > 0;
}
public function getFilter() : array
{
return $this->filter;
}
/**
* Add a facet to gather in this search request.
*/
public function addFacet(FacetRequestInterface $facet)
{
$this->facets[$facet->getIdentifier()] = $facet;
}
/**
* Returns all configured facets to fetch in this search request.
*/
public function getFacets() : array
{
return $this->facets;
}
/**
* Define connection to use for this request.
* Necessary to allow implementation of execute for interface.
*/
public function setConnection(ConnectionInterface $connection)
{
$this->connection = $connection;
}
public function setSearchService(SearchService $searchService)
{
$this->searchService = $searchService;
}
2019-06-06 15:25:41 +02:00
// Extbase QueryInterface
// Current implementation covers only paginate widget support.
public function execute($returnRawQueryResult = false)
{
if (! ($this->connection instanceof ConnectionInterface)) {
throw new \InvalidArgumentException(
'Connection was not set before, therefore execute can not work. Use `setConnection` before.',
1502197732
);
}
if (! ($this->searchService instanceof SearchService)) {
throw new \InvalidArgumentException(
'SearchService was not set before, therefore execute can not work. Use `setSearchService` before.',
1520325175
);
}
return $this->searchService->processResult($this->connection->search($this));
}
public function setLimit($limit)
{
2019-06-06 15:25:41 +02:00
$this->limit = (int) $limit;
return $this;
}
2019-06-06 15:25:41 +02:00
public function setOffset($offset)
{
2019-06-06 15:25:41 +02:00
$this->offset = (int) $offset;
return $this;
}
2019-06-06 15:25:41 +02:00
public function getLimit(): int
{
2019-06-06 15:25:41 +02:00
return $this->limit;
}
2019-06-06 15:25:41 +02:00
public function getOffset(): int
{
2019-06-06 15:25:41 +02:00
return $this->offset;
}
2019-06-06 15:25:41 +02:00
public function getSource()
{
throw new \BadMethodCallException('Method is not implemented yet.', 1502196146);
}
2019-06-06 15:25:41 +02:00
public function setOrderings(array $orderings)
{
2019-06-06 15:25:41 +02:00
throw new \BadMethodCallException('Method is not implemented yet.', 1502196163);
}
2019-06-06 15:25:41 +02:00
public function matching($constraint)
{
2019-06-06 15:25:41 +02:00
throw new \BadMethodCallException('Method is not implemented yet.', 1502196197);
}
2019-06-06 15:25:41 +02:00
public function logicalAnd($constraint1)
{
2019-06-06 15:25:41 +02:00
throw new \BadMethodCallException('Method is not implemented yet.', 1502196166);
}
2019-06-06 15:25:41 +02:00
public function logicalOr($constraint1)
{
2019-06-06 15:25:41 +02:00
throw new \BadMethodCallException('Method is not implemented yet.', 1502196198);
}
2019-06-06 15:25:41 +02:00
public function logicalNot(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface $constraint)
{
2019-06-06 15:25:41 +02:00
throw new \BadMethodCallException('Method is not implemented yet.', 1502196166);
}
2019-06-06 15:25:41 +02:00
public function equals($propertyName, $operand, $caseSensitive = true)
{
throw new \BadMethodCallException('Method is not implemented yet.', 1502196199);
}
public function contains($propertyName, $operand)
{
throw new \BadMethodCallException('Method is not implemented yet.', 1502196200);
}
public function in($propertyName, $operand)
{
throw new \BadMethodCallException('Method is not implemented yet.', 1502196167);
}
public function lessThan($propertyName, $operand)
{
2019-06-06 15:25:41 +02:00
throw new \BadMethodCallException('Method is not implemented yet.', 1502196201);
}
2019-06-06 15:25:41 +02:00
public function lessThanOrEqual($propertyName, $operand)
{
2019-06-06 15:25:41 +02:00
throw new \BadMethodCallException('Method is not implemented yet.', 1502196168);
}
2019-06-06 15:25:41 +02:00
public function greaterThan($propertyName, $operand)
{
2019-06-06 15:25:41 +02:00
throw new \BadMethodCallException('Method is not implemented yet.', 1502196202);
}
2019-06-06 15:25:41 +02:00
public function greaterThanOrEqual($propertyName, $operand)
{
2019-06-06 15:25:41 +02:00
throw new \BadMethodCallException('Method is not implemented yet.', 1502196168);
}
2019-06-06 15:25:41 +02:00
public function getType()
{
2019-06-06 15:25:41 +02:00
throw new \BadMethodCallException('Method is not implemented yet.', 1502196203);
}
2019-06-06 15:25:41 +02:00
public function setQuerySettings(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings)
{
throw new \BadMethodCallException('Method is not implemented yet.', 1502196168);
}
public function getQuerySettings()
{
throw new \BadMethodCallException('Method is not implemented yet.', 1502196205);
}
public function count()
{
throw new \BadMethodCallException('Method is not implemented yet.', 1502196169);
}
public function getOrderings()
{
throw new \BadMethodCallException('Method is not implemented yet.', 1502196206);
}
public function getConstraint()
{
throw new \BadMethodCallException('Method is not implemented yet.', 1502196171);
}
public function isEmpty($propertyName)
{
throw new \BadMethodCallException('Method is not implemented yet.', 1502196207);
}
public function setSource(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface $source)
{
throw new \BadMethodCallException('Method is not implemented yet.', 1502196172);
}
public function getStatement()
{
throw new \BadMethodCallException('Method is not implemented yet.', 1502196208);
}
public function current()
{
throw new \BadMethodCallException('Method is not implemented yet.', 1502196208);
}
public function next()
{
throw new \BadMethodCallException('Method is not implemented yet.', 1502196208);
}
public function key()
{
2019-06-06 15:25:41 +02:00
throw new \BadMethodCallException('Method is not implemented yet.', 1502196208);
}
2019-06-06 15:25:41 +02:00
public function valid()
{
2019-06-06 15:25:41 +02:00
throw new \BadMethodCallException('Method is not implemented yet.', 1502196208);
}
2019-06-06 15:25:41 +02:00
public function rewind()
{
2019-06-06 15:25:41 +02:00
throw new \BadMethodCallException('Method is not implemented yet.', 1502196208);
}
}