0

I'm trying to do some searching with haystack with the whoosh backend.

In my document i have string 1234-567

and my search could look like this

SearchQuerySet().filter(content="1234567)

Haystack does not find the object because of the hyphen between 1234 and 567.

Anyone know how i should solve this? Should i remove the hyphen when generating the document? Also other characters like "." and "/" could cause the same problem.

nikora
  • 817
  • 1
  • 14
  • 29

1 Answers1

0

I'd say to do it when generating the document. This can be done by defining a preparation method: http://django-haystack.readthedocs.org/en/latest/searchindex_api.html#advanced-data-preparation

So maybe for your case, something like:

content = indexes.CharField()

def prepare_content(self, obj):
    return ''.join(obj.content.split('-'))

If it's more than just a single char, you might wanna use regular expressions to clean up the string.

Matt
  • 1