mirror of
https://github.com/Codappix/search_core.git
synced 2024-11-22 13:16:17 +01:00
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:
parent
5dd0759bb6
commit
3a2523e1d2
2 changed files with 55 additions and 3 deletions
|
@ -146,12 +146,35 @@ class Elasticsearch implements Singleton, ConnectionInterface
|
|||
{
|
||||
$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->addIndex('typo3content');
|
||||
|
||||
$search->setQuery(new \Elastica\Query(['query' => $query]));
|
||||
// TODO: Return wrapped result to implement our interface.
|
||||
// Also update php doc to reflect the change.
|
||||
return $search->search('"' . $searchRequest->getSearchTerm() . '"');
|
||||
return $search->search();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -32,7 +32,12 @@ class SearchRequest implements SearchRequestInterface
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $query;
|
||||
protected $query = '';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $filter = [];
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
|
@ -57,4 +62,28 @@ class SearchRequest implements SearchRequestInterface
|
|||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue