<?php
namespace Aqarmap\Bundle\SearchBundle\Services\ElasticListingSearch;
use Aqarmap\Bundle\SearchBundle\ScoreContainers\ListingsScoreContainer;
class DefaultListingSearch extends AbstractElasticListingSearch
{
protected function getResults(int $page = 1, int $limit = 20)
{
try {
$searchResults = [
'featuredListings' => [],
'searchResults' => $this->paginator,
'searchResultsIDs' => [],
];
$scoringContainer = new ListingsScoreContainer();
$scoreFunction = $scoringContainer->score($this->getScoreSettings());
$resultsQuery = $this->repository->getResultQueryWithScore($scoreFunction);
$results = $this->finder->createHybridPaginatorAdapter($resultsQuery);
/** @var \Knp\Component\Pager\Pagination\PaginationInterface $pagination */
$pagination = $this->paginator->paginate(
$results,
$page,
$limit
);
$items = $pagination->getItems();
$pagination->setItems($this->setListingsScoring($items));
$searchResults['searchResults'] = $pagination;
$searchResults['searchResultsIDs'] = $this->listingManager->getIdsFromPagination($pagination);
} catch (\Exception $e) {
$this->session->getFlashBag()->add(
'danger',
$this->translator->trans('layout.search_empty_results')
);
$searchResults['searchResults'] = $this->paginator->paginate([], 1, 10);
}
return $searchResults;
}
}