Skip to content

Instantly share code, notes, and snippets.

@timbroder
Last active December 11, 2015 04:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timbroder/4547825 to your computer and use it in GitHub Desktop.
Save timbroder/4547825 to your computer and use it in GitHub Desktop.
adding facet.mincount to django-haystack
#the backend
class MySolrBackend(SolrSearchBackend):
def build_search_kwargs(self, *args, **kwargs):
facet_mincount = kwargs.pop('facet_mincount', None)
search_kwargs = super(AiSolrBackend, self).build_search_kwargs(*args, **kwargs)
if facet_mincount is not None:
search_kwargs['facet'] = 'on'
search_kwargs['facet.mincount'] = facet_mincount
class MyEngine(SolrEngine):
backend = MySolrBackend
#in settings
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'search.backends.MyEngine',
'URL': 'http://127.0.0.1:8983/solr'
},
}
#custom queryset
class MySearchQuerySet(SearchQuerySet):
def facet_mincount(self, mincount):
"""Sets mincount for facet result."""
clone = self._clone()
clone.query.set_facet_mincount(mincount)
return clone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment