Django Haystack exact filtering

Posted by blackrobot on Stack Overflow See other posts from Stack Overflow or by blackrobot
Published on 2010-01-28T17:35:54Z Indexed on 2010/06/07 14:42 UTC
Read the original article Hit count: 400

Filed under:
|
|
|

I have a haystack search which has the following SearchIndex:

class GrantIndex(indexes.SearchIndex):
    """
    This provides the search index for the Grant application.
    """
    text = indexes.CharField(document=True, use_template=True)
    year = indexes.IntegerField(model_attr='year__year')
    date = indexes.DateField(model_attr='date')
    program = indexes.CharField(model_attr='program__area')
    grantee = indexes.CharField(model_attr='grantee')
    amount = indexes.IntegerField(model_attr='amount')
site.register(Grant, GrantIndex)

If I want to search filtering out any programs that ARE NOT 'Health', I run the following query:

from haystack.query import SearchQuerySet

sqs = SearchQuerySet()
sqs = sqs.filter(program='Health')

Unfortunately, this also produces objects from the program 'Health\Other' and 'Health\Cardiovascular'. How do I stop the search from allowing those other programs in?

I run Ubuntu 9.10 with Xapian as my search back-end.

© Stack Overflow or respective owner

Related posts about python

Related posts about django