Sorting Facet Information

You can use the facet-FIELD-sort parameter to control how the facet information is sorted in the search results. ASN Search supports four sorting options:

  • alpha—sort the facet values alphabetically. The facet values are always sorted ascending order when using the alpha option.
  • count—sort the facet values by their counts. The facet values are always sorted in descending order when using the count option.
  • max—sort the facet values according to the maximum values in the specified field. This option is specified as max(FIELD). By default, the facet values are sorted in ascending order. To sort in descending order, prefix the max option with a - (minus sign): -max(FIELD).
  • sum—sort the facet values according to the sum of the values in the specified field (in ascending order). This option is specified as sum(FIELD). By default, the facet values are sorted in ascending order. To sort in descending order, prefix the sum option with a - (minus sign): -sum(FIELD).

By default, facet information is sorted by facet counts. The - (minus) prefix cannot be used to reverse the sort order when using the alpha or count options.

To sort values for a facet field alphabetically

Specify facet-FIELD-sort=alpha:

../search?bq=description:'read'&facet=fct_jurisdiction&facet-fct_jurisdiction-sort=alpha

To sort values for a facet field using the value of a uint field or rank expression

Specify facet-FIELD-sort=max(FIELD). When you use the max option, the score used for sorting is the maximum value in the specified field across all matching documents with that facet value. By default, the values are sorted in ascending order. You can prefix the max option with a - (minus sign) to reverse the order.

For example, you could use the default text_relevance score to sort the facet values. In the following request, the facet value that has the matching document with the highest text_relevance score is listed first:

../search?bq=description:'read'&facet=fct_jurisdiction&facet-fct_jurisdiction-sort=-max(text_relevance)

The maximum text_relevance score for each facet value is displayed in the facet information:

"facets":
    {"fct_jurisdiction":
        {"constraints":[
            {"value":"Washington","count":836,"score":234},
            {"value":"West Virginia","count":519,"score":233},
            {"value":"New York","count":1473,"score":232},
            {"value":"Kansas","count":479,"score":228},
            ...
        ]
    }
}

To sum the values in a field and use the resulting score to sort the facet values

Specify facet-FIELD-sort=sum(FIELD) . When you use the sum option, the score used for sorting is the sum of the values in the specified field for all matching documents with that facet value. By default, the values are listed in ascending order. For example:

../search?bq='read'&facet=fct_jurisdictionf&facet-fct_jurisdiction-sort=sum(text_relevance)

The sum is displayed in the facet information as the score for the facet value:

facets": {
    "fct_jurisdiction": {
        "constraints: [
            {"value": "North Carolina","count":1,"score":200},
            ...
            {"value": "Arizona",count":37,"score":7391}
        ]
    }
}

Note
You can prefix the sum option with a - (minus sign) to list the values in descending order.