Amazon CloudSearch
Developer Guide (API Version 2011-02-01)
« PreviousNext »
View the PDF for this guide.Go to the AWS Discussion Forum for this product.Go to the Kindle Store to download this guide in Kindle format.Did this page help you?  Yes | No |  Tell us about it...

Sorting Results in Amazon CloudSearch

By default, results are sorted according to their text_relevance scores, with the highest-scoring documents listed first. You can use the rank parameter in your search requests to sort results alphabetically, numerically, or using your own custom rank expressions. If you specify a comma separated list of fields or rank expressions, the first field or rank expression is used as the primary sort criteria, the second is used as the secondary sort criteria, and so on.

You can use any result-enabled text or literal field to sort results alphabetically. For example, rank=actor is specified in the following query to sort the results alphabetically by actor:

search?q=star+wars&return-fields=title&rank=actor

By default, results are listed in an ascending order. To sort in descending order, prefix the field name with - (minus sign):

search?q=star+wars&rank=-actor

You can use any uint field to sort results numerically. For example, specifying rank=-year will sort the results by year with the most recent year listed first:

search?q=star+wars&return-fields=title,year&rank=-year

Note

If you don't specify the rank option, it is set to -text_relevance by default so the highest-scoring documents are listed first.

You can also define custom rank expressions and use them to sort results. For more information about creating and using your own rank expressions, see Customizing Result Ranking with Amazon CloudSearch.