From 061aaea601020fb8fefb468acf1cd0abd3acee12 Mon Sep 17 00:00:00 2001 From: Zev Benjamin Date: Fri, 15 Feb 2013 15:24:58 -0500 Subject: [PATCH] Use plainto_tsquery instead of to_tsquery This will discard punctuation symbols in the Postgres search and also prevent syntax errors when users try to submit queries with symbols that to_tsquery interprets as special syntax (such as '|' and '&'). Fixes #906 (imported from commit 3e3a0d6ae3d4a516beb8a5846f06065294ca9457) --- zephyr/views.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/zephyr/views.py b/zephyr/views.py index 0225cdabcb..c195d2d0e5 100644 --- a/zephyr/views.py +++ b/zephyr/views.py @@ -568,12 +568,11 @@ class NarrowBuilder(object): (Q(sender=self.user_profile) & Q(recipient=narrow_recipient))) def do_search(self, query, operand): - words = operand.split() if "postgres" in settings.DATABASES["default"]["ENGINE"]: - sql = "search_tsvector @@ to_tsquery('pg_catalog.english', %s)" - return query.extra(where=[sql], params=[" & ".join(words)]) + sql = "search_tsvector @@ plainto_tsquery('pg_catalog.english', %s)" + return query.extra(where=[sql], params=[operand]) else: - for word in words: + for word in operand.split(): query = query.filter(Q(content__icontains=word) | Q(subject__icontains=word)) return query