mirror of
https://github.com/Codappix/search_core.git
synced 2024-11-22 08:36:10 +01:00
Merge pull request #93 from Codappix/hotfix/allow-empty-filter
BUGFIX: Do not remove submitted filter if configured one is empty
This commit is contained in:
commit
43ec410eb5
2 changed files with 36 additions and 4 deletions
|
@ -26,6 +26,7 @@ use Codappix\SearchCore\Connection\ConnectionInterface;
|
||||||
use Codappix\SearchCore\Connection\SearchRequestInterface;
|
use Codappix\SearchCore\Connection\SearchRequestInterface;
|
||||||
use Codappix\SearchCore\Connection\SearchResultInterface;
|
use Codappix\SearchCore\Connection\SearchResultInterface;
|
||||||
use Codappix\SearchCore\Domain\Model\FacetRequest;
|
use Codappix\SearchCore\Domain\Model\FacetRequest;
|
||||||
|
use TYPO3\CMS\Core\Utility\ArrayUtility;
|
||||||
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
|
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -123,10 +124,16 @@ class SearchService
|
||||||
protected function addConfiguredFilters(SearchRequestInterface $searchRequest)
|
protected function addConfiguredFilters(SearchRequestInterface $searchRequest)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$searchRequest->setFilter(array_merge(
|
$filter = $searchRequest->getFilter();
|
||||||
$searchRequest->getFilter(),
|
|
||||||
$this->configuration->get('searching.filter')
|
ArrayUtility::mergeRecursiveWithOverrule(
|
||||||
));
|
$filter,
|
||||||
|
$this->configuration->get('searching.filter'),
|
||||||
|
true,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
$searchRequest->setFilter($filter);
|
||||||
} catch (InvalidArgumentException $e) {
|
} catch (InvalidArgumentException $e) {
|
||||||
// Nothing todo, no filter configured.
|
// Nothing todo, no filter configured.
|
||||||
}
|
}
|
||||||
|
|
|
@ -178,4 +178,29 @@ class SearchServiceTest extends AbstractUnitTestCase
|
||||||
$searchRequest->setFilter(['anotherProperty' => 'anything']);
|
$searchRequest->setFilter(['anotherProperty' => 'anything']);
|
||||||
$this->subject->search($searchRequest);
|
$this->subject->search($searchRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function emptyConfiguredFilterIsNotChangingRequestWithExistingFilter()
|
||||||
|
{
|
||||||
|
$this->configuration->expects($this->exactly(2))
|
||||||
|
->method('getIfExists')
|
||||||
|
->withConsecutive(['searching.size'], ['searching.facets'])
|
||||||
|
->will($this->onConsecutiveCalls(null, null));
|
||||||
|
$this->configuration->expects($this->exactly(1))
|
||||||
|
->method('get')
|
||||||
|
->with('searching.filter')
|
||||||
|
->willReturn(['anotherProperty' => '']);
|
||||||
|
|
||||||
|
$this->connection->expects($this->once())
|
||||||
|
->method('search')
|
||||||
|
->with($this->callback(function ($searchRequest) {
|
||||||
|
return $searchRequest->getFilter() === ['anotherProperty' => 'anything'];
|
||||||
|
}));
|
||||||
|
|
||||||
|
$searchRequest = new SearchRequest('SearchWord');
|
||||||
|
$searchRequest->setFilter(['anotherProperty' => 'anything']);
|
||||||
|
$this->subject->search($searchRequest);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue