Skip to content

Instantly share code, notes, and snippets.

@toastdriven
Created February 21, 2011 19:12
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toastdriven/837538 to your computer and use it in GitHub Desktop.
Save toastdriven/837538 to your computer and use it in GitHub Desktop.
How to make multiple word autocomplete work in Haystack.
import operator
from haystack.query import SearchQuerySet, SQ
query = 'lil way'
sqs = SearchQuerySet().filter(reduce(operator.__and__, [SQ(name=word.strip()) for word in query.split(' ')]))
@toastdriven
Copy link
Author

What this code ends up doing is sqs = SearchQuerySet().filter(SQ(name='lil') & SQ(name='way')), but builds the SQ tree dynamically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment