1

I would like to implement a search box which returns all the results which are associated with at least one of the terms. In other words, a query with the terms separated by OR.

For instance:

Input: tomatoes potatoes watermelons
Query: tomatoes OR potatoes OR watermelons in db
Output: corresponding results

Preferably, but not necessarily, if a term is contained in all the results, it should be first or in the group of firsts.

I looked it up on Google but I could not modify an example that I found. If I replace the last row in get_query with query = query | or_query, I get an error in the template. I guess it is because of the lazy evaluation of the queries that Django performs, since the template works if I use verbatim the code in the link.

1
  • providing real code (sanitized as necessary) will help you get real answers. There are at least 4 or 5 different things that you could be trying to do, and the answer to the question is dependent on which of them you're attempting. Commented Aug 19, 2011 at 2:07

1 Answer 1

1

I'd guess you're looking for Q objects. Really though, you should try django-haystack, if you're doing anything related to searching.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.