afs:sort - AFS

AFS Integration Guide

Reference Guide


Sets the sorting order with a list of criteria of type facet or facet,order :

  • order specifies the sort order. It can be set to either ASC or DESC (for ascending and descending sort order respectively). When omitted, the default order is DESC.
  • Multiple, cascading criteria. It can be used with the and keyword or the ; sign (semi-colon) to separate them.

When afs:sort is omitted, replies are sorted according to full-text search relevance.

The following built-in facets are available:

  • afs:words is the number of the query words found in the document. Example: if the query is composed of three different words, and all those words are present in the matched document, afs:words value will be 3. If one of the query words is not present in the matched document, afs:word value will be 2, etc.
  • afs:pathlen is the minimal distance between query words in the document.
  • afs:weight is the importance of the words in the document between 1 and 100, where 100 means very important and 1 not important.
  • afs:fieldMatch criterion allows replies containing exactly the keywords in an item to be more relevant. afs:fieldMatch is a boolean holding true if the FTS match matches a whole item, and false otherwise. afs:fieldMatch must be sorted in DESC order in order to have best matches first. afs:fieldMatch behavior is undefined in case of multiple FTS.
  • afs:relevance is the shortcut for afs:words,DESC and afs:fieldMatch,DESC and afs:pathlen,ASC and afs:weight,DESC
  • afs:docId is the docId of the document.
  • afs:uri is the URI of the document.
  • afs:lang is the language of the document.
  • afs:size is the size (in kb) of the document.
  • afs:doctype is the type of the document.

Note that some built-in facets have to be activated in the PaF configuration, otherwise they are not available at query time. For more information , see Built-in Facets topic of the AFS Configuration Guide.

In addition, the following pseudo facets are available:

  • random for random sort order. See afs:sort=random topic for more details about this pseudo facet.

They are called pseudo facets because they are not specific to each document.

When two replies are found to be equal once every criterion has been evaluated, the replies are sorted by descending docId (meaning that the newest document appears first).


Optional. It can be used several times, in which case the sorting criteria are evaluated in order in an and fashion.


Sort by built-in relevance facet, then by user-specific "price" facet starting with the lowest values:

afs:sort=afs:relevance,DESC and price,ASC

Alternative syntaxes:



Focus on afs:sort=fieldMatch vs. afs:ftsMatch=field.

Example: a bookshop.

Search for "le petit prince" with afs:ftsMatch=field returns only one book: "Le petit prince"

Search for "le petit prince" with afs:sort=fieldMatch returns many books: "le petit prince" is first, then "le petit prince II", "analyse du petit prince", ...