Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/ElasticquentResultCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ public function getHits()
return $this->hits;
}

/**
* Get Items
*
* @return array
*/
public function getItems()
{
return $this->items;
}

/**
* Get aggregations
*
Expand Down
23 changes: 23 additions & 0 deletions src/ElasticquentTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,29 @@ public static function complexSearch($params)
return new \Elasticquent\ElasticquentResultCollection($result, $instance = new static);
}

/**
* Perform a "complex" or custom search and paginate result collection.
*
* Using this method, a custom query can be sent to Elasticsearch.
*
* @param $params
* @return ElasticquentResultCollection
*/
public static function complexSearchAndPaginate($params, $size = 10)
{
$instance = new static;

$page = \Elasticquent\ElasticquentPaginator::resolveCurrentPage() ?: 1;

$params["body"]["size"] = $size;
$params["body"]["from"] = ($page - 1) * $size;

$result = $instance->getElasticSearchClient()->search($params);
$collection = new \Elasticquent\ElasticquentResultCollection($result, $instance = new static);

return new \Elasticquent\ElasticquentPaginator($collection->getItems(), $collection->getHits(), $collection->totalHits(), $size, $page, ['path' => \Elasticquent\ElasticquentPaginator::resolveCurrentPath()]);
}

/**
* Search
*
Expand Down