mirror of
https://github.com/Codappix/search_core.git
synced 2024-11-22 09:16:21 +01:00
FEATURE: Allow filter mode by not forcing a search term
This commit is contained in:
parent
4de1828905
commit
13004e86f2
3 changed files with 24 additions and 1 deletions
|
@ -66,7 +66,7 @@ class SearchRequest implements SearchRequestInterface
|
|||
/**
|
||||
* @param string $query
|
||||
*/
|
||||
public function __construct($query)
|
||||
public function __construct($query = '')
|
||||
{
|
||||
$this->query = (string) $query;
|
||||
}
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue