I'm working on an existing Django project which uses Haystack-Xapian for a global search feature. However the search seems to fail while I search with some special characters like & and '. I tried but could not find a way to fix it.
Is there a way I can escape these characters and make the search work? I'm using PostgreSQL at the back-end. Any pointers will be very helpful.
Escaping depends on how you are using Haystack, however, the haystack.inputs.Clean
class may be what you are looking for. Just pass in whatever you are searching for:
q = "amp & sand"
q_clean = haystack.inputs.Clean(q)
sqs = SearchQuerySet().filter(content=q_clean)
See the docs here: http://django-haystack.readthedocs.org/en/latest/inputtypes.html#clean
I'm working on an existing Django project which uses Haystack-Xapian for a global search feature. However the search seems to fail while I search with some special characters like & and '. I tried but could not find a way to fix it.
Is there a way I can escape these characters and make the search work? I'm using PostgreSQL at the back-end. Any pointers will be very helpful.
Escaping depends on how you are using Haystack, however, the haystack.inputs.Clean
class may be what you are looking for. Just pass in whatever you are searching for:
q = "amp & sand"
q_clean = haystack.inputs.Clean(q)
sqs = SearchQuerySet().filter(content=q_clean)
See the docs here: http://django-haystack.readthedocs.org/en/latest/inputtypes.html#clean
0 commentaires:
Enregistrer un commentaire