protected function _renderFiltersBefore()
{
$searchRequest = $this->prepareRequest();
$this->queryResponse = $this->searchEngine->search($searchRequest);
// Update the product count.
$this->_totalRecords = $this->queryResponse->count();
// Filter search results. The pagination has to be resetted since it is managed by the engine itself.
$docIds = array_map(function (\Magento\Framework\Api\Search\Document $doc) {
return (int) $doc->getId();
}, $this->queryResponse->getIterator()->getArrayCopy());
if (empty($docIds)) {
$docIds[] = 0;
}
$this->getSelect()->where('e.entity_id IN (?)', ['in' => $docIds]);
$this->_pageSize = false;
$this->isSpellchecked = $searchRequest->isSpellchecked();
return parent::_renderFiltersBefore();
}