Sorting
The default behavior is to sort results by relevance, with the highest scoring results first.
The simple API adds a method to the SearchRequest. Here is an example which sorts by the field age
.
There are two special fields defined for use:
- - refers to the relevance score computed by Bleve
Here is a more complex example:
searchRequest.SortBy([]string{"age", "-_score", "_id"})
Advanced API
The simple API works for most cases, but there are some which require the advanced API. In these cases you must import the bleve search
sub-package, and build a search.SortOrder
object. This is a slice of objects. Today there are three implementations available, SortField, SortScore, and SortDocID.
By building these structures manually, you can avoid ambiguities and limitations of the simple API.
- Sort by fields which happen to conflict with
_id
or_score
- Control whether documents missing a field value should sort first or last
- Force handling field values as a particular type (defaults to auto)