Skip to content

Commit

Permalink
changes for elastic search to be able to have paginated results (#71)
Browse files Browse the repository at this point in the history
* changes for elastic search to be able to have paginated results

* bump

* fix test
  • Loading branch information
rayzor65 authored Sep 19, 2016
1 parent 4059e75 commit 02276be
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Controllers/EntityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,6 @@ protected function convertQueryToElasticsearchRequest($query, $limit = null, $of
{
/* @var ElasticquentTrait $model */
$model = $this->getModel();

// Complex query
if (is_array($query)) {
$params = [
Expand All @@ -446,6 +445,14 @@ protected function convertQueryToElasticsearchRequest($query, $limit = null, $of
'body' => $this->translateQuery($query),
];

if (is_numeric($limit)) {
$params = array_merge($params, ['size' => $limit]);
}

if (is_numeric($offset)) {
$params = array_merge($params, ['from' => $offset]);
}

// Simple query
} else {
$params = $model->getBasicEsParams(true, true, true, $limit, $offset);
Expand Down
4 changes: 4 additions & 0 deletions tests/integration/EntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ public function testGetAllPaginatedComplexSearch($path)
'index' => 'defaultIndex',
'type' => 'someTypeName',
'body' => ['query' => ['bool' => ['must' => [['match_phrase_prefix' => ['_all' => 'search term']], ['match_phrase_prefix' => ['author_id' => 'some UUID']], ['nested' => ['path' => '_tags', 'query' => ['bool' => ['must' => ['match_phrase_prefix' => ['_tags.tag_id' => 'tag ID 1']]]]]], ['nested' => ['path' => '_tags', 'query' => ['bool' => ['must' => ['match_phrase_prefix' => ['_tags.tag_id' => 'tag ID 2']]]]]]]]]],
'size' => 10,
'from' => 0,
])
->andReturn($resultsMock);

Expand Down Expand Up @@ -352,6 +354,8 @@ public function testGetAllPaginatedComplexSearchMatchAll($path)
'index' => 'defaultIndex',
'type' => 'someTypeName',
'body' => ['query' => ['match_all' => []]],
'size' => 10,
'from' => 0,
])
->andReturn($resultsMock);

Expand Down

0 comments on commit 02276be

Please sign in to comment.