Getting Facet Information for Particular Values

The facet-FIELD-constraints parameter controls which facet values are returned for the specified facet. You specify the facet values you want to count as a comma-separated list. The values must be enclosed within single quotes. Note that the facet values are case sensitive: facet-fct_subject-constraints='math' is not the same as facet-fct_subject-constraints='Math'.

Note

If commas occur in a facet value you want to use as a constraint, the comma must be escaped with a backslash. For example,
facet-fct_statement_notation-constraints='101\,134','101\,135'.

For example, to find out how many items have Math or Science in the subject field, you'd set facet-fct_subject-constraints='Math','Science':

../search?q=read&facet=fct_subject&facet-fct_subject-constraints='Math','Science'

In the response, the counts are only shown for the specified constraints:

facets":{"fct_subject":
    {"constraints":[
        {"value":"Math","count":745},
        {"value":"Science","count":104}
    ]}
}

The facet-FIELD-constraints parameter can also be used with uint fields. You can specify individual values, as well as ranges of values, which enables you to do range-based binning. You can use the min and max values returned when you don't specify any constraints to calculate the ranges, and then get facet counts for each of those ranges with a subsequent search.

The values and ranges are specified as a comma-separated list. For example, the following request gets facet counts for items with a date valid value of 2003, 2006 through 2010, and all documents with year greater than or equal to 2011:

&facet=date_valid&facet-date_valid-constraints=2003,2006..2010,2011..

By default, the response shows the constraints with the highest counts first:

"facets":{
    "date_valid":{"min":1993,"max":2012,
        "constraints":[
            {"value":"2006..2010","count":54},
            {"value":"2003","count":13},
            {"value":"2011","count":12}
        ]
    }
}