2016-12-09 11:47:28 +01:00
|
|
|
<?php
|
2017-07-06 23:48:47 +02:00
|
|
|
namespace Codappix\SearchCore\Domain\Model;
|
2016-12-09 11:47:28 +01:00
|
|
|
|
|
|
|
/*
|
2016-12-09 13:19:35 +01:00
|
|
|
* Copyright (C) 2016 Daniel Siepmann <coding@daniel-siepmann.de>
|
2016-12-09 11:47:28 +01:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2017-08-08 17:07:23 +02:00
|
|
|
use Codappix\SearchCore\Connection\ConnectionInterface;
|
2017-07-06 23:48:47 +02:00
|
|
|
use Codappix\SearchCore\Connection\FacetRequestInterface;
|
|
|
|
use Codappix\SearchCore\Connection\SearchRequestInterface;
|
2016-12-09 11:47:28 +01:00
|
|
|
|
|
|
|
/**
|
2016-12-09 13:19:35 +01:00
|
|
|
* Represents a search request used to process an actual search.
|
2016-12-09 11:47:28 +01:00
|
|
|
*/
|
2016-12-09 13:19:35 +01:00
|
|
|
class SearchRequest implements SearchRequestInterface
|
2016-12-09 11:47:28 +01:00
|
|
|
{
|
2016-12-09 13:19:35 +01:00
|
|
|
/**
|
|
|
|
* The search string provided by the user, the actual term to search for.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2017-06-06 12:32:27 +02:00
|
|
|
protected $query = '';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $filter = [];
|
2016-12-09 13:19:35 +01:00
|
|
|
|
2017-07-06 12:03:52 +02:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $facets = [];
|
|
|
|
|
2017-08-08 17:07:23 +02:00
|
|
|
/**
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
protected $offset = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
protected $limit = 10;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used for QueryInterface implementation to allow execute method to work.
|
|
|
|
*
|
|
|
|
* @var ConnectionInterface
|
|
|
|
*/
|
|
|
|
protected $connection = null;
|
|
|
|
|
2016-12-09 13:19:35 +01:00
|
|
|
/**
|
|
|
|
* @param string $query
|
|
|
|
*/
|
2017-09-15 21:54:47 +02:00
|
|
|
public function __construct($query = '')
|
2016-12-09 13:19:35 +01:00
|
|
|
{
|
2017-06-08 08:38:14 +02:00
|
|
|
$this->query = (string) $query;
|
2016-12-09 13:19:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getQuery()
|
2016-12-09 11:47:28 +01:00
|
|
|
{
|
2016-12-09 13:19:35 +01:00
|
|
|
return $this->query;
|
2016-12-09 11:47:28 +01:00
|
|
|
}
|
|
|
|
|
2016-12-09 13:19:35 +01:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getSearchTerm()
|
2016-12-09 11:47:28 +01:00
|
|
|
{
|
2016-12-15 09:17:58 +01:00
|
|
|
return $this->query;
|
2016-12-09 11:47:28 +01:00
|
|
|
}
|
2017-06-06 12:32:27 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $filter
|
|
|
|
*/
|
|
|
|
public function setFilter(array $filter)
|
|
|
|
{
|
2017-10-23 16:35:38 +02:00
|
|
|
$filter = \TYPO3\CMS\Core\Utility\ArrayUtility::removeArrayEntryByValue($filter, '');
|
|
|
|
$this->filter = \TYPO3\CMS\Extbase\Utility\ArrayUtility::removeEmptyElementsRecursively($filter);
|
2017-06-06 12:32:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function hasFilter()
|
|
|
|
{
|
2017-06-06 15:33:06 +02:00
|
|
|
return count($this->filter) > 0;
|
2017-06-06 12:32:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getFilter()
|
|
|
|
{
|
|
|
|
return $this->filter;
|
|
|
|
}
|
2017-07-06 12:03:52 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a facet to gather in this search request.
|
|
|
|
*
|
|
|
|
* @param FacetRequestInterface $facet
|
|
|
|
*/
|
|
|
|
public function addFacet(FacetRequestInterface $facet)
|
|
|
|
{
|
|
|
|
$this->facets[$facet->getIdentifier()] = $facet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns all configured facets to fetch in this search request.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getFacets()
|
|
|
|
{
|
|
|
|
return $this->facets;
|
|
|
|
}
|
2017-07-18 10:44:39 +02:00
|
|
|
|
|
|
|
/**
|
2017-08-08 17:07:23 +02:00
|
|
|
* Define connection to use for this request.
|
|
|
|
* Necessary to allow implementation of execute for interface.
|
|
|
|
*
|
|
|
|
* @param ConnectionInterface $connection
|
2017-07-18 10:44:39 +02:00
|
|
|
*/
|
2017-08-08 17:07:23 +02:00
|
|
|
public function setConnection(ConnectionInterface $connection)
|
2017-07-18 10:44:39 +02:00
|
|
|
{
|
2017-08-08 17:07:23 +02:00
|
|
|
$this->connection = $connection;
|
2017-07-18 10:44:39 +02:00
|
|
|
}
|
|
|
|
|
2017-08-08 17:07:23 +02:00
|
|
|
// Extbase QueryInterface
|
|
|
|
// Current implementation covers only paginate widget support.
|
|
|
|
public function execute($returnRawQueryResult = false)
|
|
|
|
{
|
|
|
|
if ($this->connection instanceof ConnectionInterface) {
|
|
|
|
return $this->connection->search($this);
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new \InvalidArgumentException(
|
|
|
|
'Connection was not set before, therefore execute can not work. Use `setConnection` before.',
|
|
|
|
1502197732
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setLimit($limit)
|
|
|
|
{
|
|
|
|
$this->limit = (int) $limit;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setOffset($offset)
|
|
|
|
{
|
|
|
|
$this->offset = (int) $offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getLimit()
|
|
|
|
{
|
|
|
|
return $this->limit;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getOffset()
|
|
|
|
{
|
|
|
|
return $this->offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSource()
|
|
|
|
{
|
|
|
|
throw new \BadMethodCallException('Method is not implemented yet.', 1502196146);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setOrderings(array $orderings)
|
|
|
|
{
|
|
|
|
throw new \BadMethodCallException('Method is not implemented yet.', 1502196163);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function matching($constraint)
|
|
|
|
{
|
|
|
|
throw new \BadMethodCallException('Method is not implemented yet.', 1502196197);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function logicalAnd($constraint1)
|
|
|
|
{
|
|
|
|
throw new \BadMethodCallException('Method is not implemented yet.', 1502196166);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function logicalOr($constraint1)
|
|
|
|
{
|
|
|
|
throw new \BadMethodCallException('Method is not implemented yet.', 1502196198);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function logicalNot(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface $constraint)
|
|
|
|
{
|
|
|
|
throw new \BadMethodCallException('Method is not implemented yet.', 1502196166);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function equals($propertyName, $operand, $caseSensitive = true)
|
|
|
|
{
|
|
|
|
throw new \BadMethodCallException('Method is not implemented yet.', 1502196199);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function like($propertyName, $operand, $caseSensitive = true)
|
|
|
|
{
|
|
|
|
throw new \BadMethodCallException('Method is not implemented yet.', 1502196167);
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
throw new \BadMethodCallException('Method is not implemented yet.', 1502196201);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function lessThanOrEqual($propertyName, $operand)
|
|
|
|
{
|
|
|
|
throw new \BadMethodCallException('Method is not implemented yet.', 1502196168);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function greaterThan($propertyName, $operand)
|
|
|
|
{
|
|
|
|
throw new \BadMethodCallException('Method is not implemented yet.', 1502196202);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function greaterThanOrEqual($propertyName, $operand)
|
|
|
|
{
|
|
|
|
throw new \BadMethodCallException('Method is not implemented yet.', 1502196168);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getType()
|
|
|
|
{
|
|
|
|
throw new \BadMethodCallException('Method is not implemented yet.', 1502196203);
|
|
|
|
}
|
|
|
|
|
|
|
|
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()
|
2017-07-18 10:44:39 +02:00
|
|
|
{
|
2017-08-08 17:07:23 +02:00
|
|
|
throw new \BadMethodCallException('Method is not implemented yet.', 1502196208);
|
2017-07-18 10:44:39 +02:00
|
|
|
}
|
2016-12-09 11:47:28 +01:00
|
|
|
}
|