Hey Michael ~
Thanks for posting within the Site Search community.
First of all, I have fixed the wording within the sorting docs. It was not at all clear, and I think it's the source of the confusion. I have corrected it, but I think it could still use some more substance.
Sorting, by default, will use the _score
field. This is somewhat of a "hidden" field that represents the overall relevance.
To only use the score field, you can just use the sort_direction
parameter.
Feel free to run these example queries -- they use the same Engine as the documentation.
This would sort by LEAST to MOST relevant (lowest to highest `_score):
curl -XGET 'https://search-api.swiftype.com/api/v1/public/engines/search.json' \
-H 'Content-Type: application/json' \
-d '{
"engine_key": "5jZG1gmmCTFYbSSDjpqq",
"q":"meta",
"sort_direction":{"page":"asc"},
"page": 1,
"per_page": 2
}'
This would sort by MOST to LEAST relevant (highest to lowest _score
):
curl -XGET 'https://search-api.swiftype.com/api/v1/public/engines/search.json' \
-H 'Content-Type: application/json' \
-d '{
"engine_key": "5jZG1gmmCTFYbSSDjpqq",
"q":"meta",
"sort_direction":{"page":"desc"},
"page": 1,
"per_page": 2
}'
The sort_field
parameter would then allow you to use a field to sort, ascending or descending, depending on the type of data in the field.
- A number field will sort numerically.
- A date field will sort historically.
- ... etc.
This will override the _score
value.
Hope this helps.
I shall polish up those docs today.
Enjoy the week,
Kellen