Skip to content

Instantly share code, notes, and snippets.

@atkinson
Created October 25, 2011 11:09
Show Gist options
  • Save atkinson/1312323 to your computer and use it in GitHub Desktop.
Save atkinson/1312323 to your computer and use it in GitHub Desktop.
Keep top level facet counts when drilling down in haystack
from haystack.views import FacetedSearchView
class StickyFacetedSearchView (FacetedSearchView):
def top_level_facets(self):
"""
When selecting a facet to drill down the results,
we need to keep the top level facet counts
"""
stored_query = self.request.session.get('query', None)
if stored_query != self.query:
self.request.session['query'] = self.query
self.request.session['facet_counts'] = self.results.facet_counts()
return self.request.session['facet_counts'] # Fail loudly
def extra_context(self):
""" add base_facets to extra_context"""
extra = super(StickyFacetedSearchView, self).extra_context()
extra['base_facets'] = self.top_level_facets()
return extra
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment