FEATURE: Allow filter mode by not forcing a search term

This commit is contained in:
Daniel Siepmann 2017-09-15 21:54:47 +02:00
parent 4de1828905
commit 13004e86f2
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
3 changed files with 24 additions and 1 deletions

View file

@ -66,7 +66,7 @@ class SearchRequest implements SearchRequestInterface
/**
* @param string $query
*/
public function __construct($query)
public function __construct($query = '')
{
$this->query = (string) $query;
}

View file

@ -105,6 +105,10 @@ class QueryFactory
*/
protected function addSearch(SearchRequestInterface $searchRequest, array &$query)
{
if (trim($searchRequest->getSearchTerm()) === '') {
return;
}
$query = ArrayUtility::setValueByPath(
$query,
'query.bool.must.0.match._all.query',

View file

@ -324,4 +324,23 @@ class QueryFactoryTest extends AbstractUnitTestCase
'Boosts were not added to query.'
);
}
/**
* @test
*/
public function emptySearchStringWillNotAddSearchToQuery()
{
$searchRequest = new SearchRequest();
$this->configuration->expects($this->any())
->method('get')
->will($this->throwException(new InvalidArgumentException));
$query = $this->subject->create($searchRequest);
$this->assertInstanceOf(
stdClass,
$query->toArray()['query']['match_all'],
'Empty search request does not create expected query.'
);
}
}