Skip to content

Commit

Permalink
Merge pull request #14 from yswery/master
Browse files Browse the repository at this point in the history
Adding ability to set a sort query on the search
  • Loading branch information
adamfairholm committed Jan 22, 2015
2 parents d35bb24 + e91951f commit 4d16e2d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ Here's the list of available paramers:
- `sourceFields` - Limits returned set to the selected fields only
- `limit` - Number of records to return
- `offset` - Sets the record offset (use for paging results)
- `sort` - Your sort query

### Search Collections

Expand Down
6 changes: 5 additions & 1 deletion src/ElasticquentTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public static function reindex()
* @param int $offset
* @return ResultCollection
*/
public static function searchByQuery($query = null, $aggregations = null, $sourceFields = null, $limit = null, $offset = null)
public static function searchByQuery($query = null, $aggregations = null, $sourceFields = null, $limit = null, $offset = null, $sort = null)
{
$instance = new static;

Expand All @@ -258,6 +258,10 @@ public static function searchByQuery($query = null, $aggregations = null, $sourc
if ($aggregations) {
$params['body']['aggs'] = $aggregations;
}

if ($sort) {
$params['body']['sort'] = $sort;
}

$result = $instance->getElasticSearchClient()->search($params);

Expand Down

0 comments on commit 4d16e2d

Please sign in to comment.