Skip to content

Commit

Permalink
Merge pull request #47 from spira/hotfix/refactor-search-all-entities
Browse files Browse the repository at this point in the history
Refactoring searchAllEntities to restore perlocated search functionality
  • Loading branch information
cmsx committed Mar 22, 2016
2 parents 8430dc6 + 26ed2d2 commit 0bc0e8d
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions Controllers/EntityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,13 @@ protected function searchAllEntities($query, $limit = null, $offset = null, &$to
{
/* @var ElasticquentTrait $model */
$model = $this->getModel();
$params = $this->convertQueryToElasticsearchRequest($query, $limit, $offset);
$searchResults = $model->complexSearch($params);

if (isset($query['percolate']) && $query['percolate']) {
$searchResults = $this->percolatedSearch($query);
} else {
$params = $this->convertQueryToElasticsearchRequest($query, $limit, $offset);
$searchResults = $model->complexSearch($params);
}

if ($searchResults instanceof ElasticquentResultCollection) {
$totalHits = $searchResults->totalHits();
Expand All @@ -411,6 +416,15 @@ protected function searchAllEntities($query, $limit = null, $offset = null, &$to
return $searchResults;
}

/**
* @param $query
* @return \Illuminate\Database\Eloquent\Collection|static[]
*/
protected function percolatedSearch($query)
{
throw new BadRequestException('Percolated Search not available for this entity');
}

protected function convertQueryToElasticsearchRequest($query, $limit = null, $offset = null)
{
/* @var ElasticquentTrait $model */
Expand Down

0 comments on commit 0bc0e8d

Please sign in to comment.