The sorting specification is specified with the sort
query parameter. The default is score desc
. Here, score
is not a field but a special reference to a relevancy number, described in detail in the next chapter. Whereas, desc
means descending order; use asc
for ascending order. Before Solr 4.2, it needed to be lowercase. In the following example, suppose we search for artists that are not individuals (a previous example in the chapter), and then we might want to ensure that those that are surely bands get top placement ahead of those that are unknown. Secondly, we want the typical descending score search. This would simply be:
sort=a_type desc,score desc
Note
Pay attention to the field types and text analysis you're using in your schema for fields that you sort on. Basically, fields need to be single valued, indexed, and not tokenized. Some, but not all, support sortMissingFirst
and sortMissingLast
options. See the section on sorting in Chapter 2, Schema Design, for further information...