django-haystack icon indicating copy to clipboard operation
django-haystack copied to clipboard

Updated: Added logic to implement Interval Faceting (Solr only).

Open dwasyl opened this issue 5 months ago • 5 comments

This is just a re-based version of #1510

Per stmos' original notes: This currently only works with Solr backend (>4.10).

More details about interval faceting can be found at: Solr - Interval Faceting

Example: intervals = ['[0,100]', '(100, *]'] sqs = SearchQuerySet() sqs.interval_facet('price', intervals=intervals)

Key replacement is supported as well: sqs.interval_facet('price', intervals=['{!key=cheap}[0, 100]', '{!key=expensive}[100, *)']).facet_counts()

Output: {u'dates': {}, u'fields': {}, u'intervals': {'price': {u'cheap': 4, u'expensive': 47}}, u'queries': {}}

Syntax is explained at the URL posted above. There is no need to specify the "facet=true" when defining the search index for the fields you want to use for interval faceting.

Only requirement is that fields used for Interval Faceting must have “docValues” enabled (not required for Solr 5.20 and above) @stmos

dwasyl avatar Jan 07 '24 05:01 dwasyl