Last active
December 11, 2015 04:48
-
-
Save timbroder/4547825 to your computer and use it in GitHub Desktop.
adding facet.mincount to django-haystack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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