WIP|FEATURE: First basic implementation of filter

* Working version without further architecture.
* Manually tested.
* Still need to move to new architecture and cover with tests.
This commit is contained in:
Daniel Siepmann 2017-06-06 12:32:27 +02:00
parent 5dd0759bb6
commit 3a2523e1d2
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
2 changed files with 55 additions and 3 deletions

View file

@ -146,12 +146,35 @@ class Elasticsearch implements Singleton, ConnectionInterface
{ {
$this->logger->debug('Search for', [$searchRequest->getSearchTerm()]); $this->logger->debug('Search for', [$searchRequest->getSearchTerm()]);
$query = [
'bool' => [
'must' => [
[
'match' => [
'_all' => $searchRequest->getSearchTerm()
],
],
],
],
];
if ($searchRequest->hasFilter()) {
$queryFilter = [];
foreach ($searchRequest->getFilter() as $field => $value) {
$queryFilter[$field] = $value;
}
$query['bool']['filter'] = [
'term' => $queryFilter,
];
}
$search = new \Elastica\Search($this->connection->getClient()); $search = new \Elastica\Search($this->connection->getClient());
$search->addIndex('typo3content'); $search->addIndex('typo3content');
$search->setQuery(new \Elastica\Query(['query' => $query]));
// TODO: Return wrapped result to implement our interface. // TODO: Return wrapped result to implement our interface.
// Also update php doc to reflect the change. // Also update php doc to reflect the change.
return $search->search('"' . $searchRequest->getSearchTerm() . '"'); return $search->search();
} }
/** /**

View file

@ -32,7 +32,12 @@ class SearchRequest implements SearchRequestInterface
* *
* @var string * @var string
*/ */
protected $query; protected $query = '';
/**
* @var array
*/
protected $filter = [];
/** /**
* @param string $query * @param string $query
@ -57,4 +62,28 @@ class SearchRequest implements SearchRequestInterface
{ {
return $this->query; return $this->query;
} }
/**
* @param array $filter
*/
public function setFilter(array $filter)
{
$this->filter = $filter;
}
/**
* @return bool
*/
public function hasFilter()
{
return count($this->filter);
}
/**
* @return array
*/
public function getFilter()
{
return $this->filter;
}
} }