mirror of
https://github.com/zulip/zulip.git
synced 2026-07-18 21:04:19 +08:00
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)
This commit is contained in:
parent
a1234afc4b
commit
061aaea601
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user