From 20de7cd0fe5420fb89c3949c07dbd6004cadd5b7 Mon Sep 17 00:00:00 2001 From: Deimos Date: Mon, 21 Oct 2019 11:58:12 -0600 Subject: [PATCH] Search: Use PostgreSQL websearch_to_tsquery Now that PostgreSQL has been upgraded to version 12 (from 10), the websearch_to_tsquery() function is available. This is much better for general search purposes, and will add multiple capabilities. I'm not sure if there's a full specification of what it supports anywhere, but this is the main relevant section in the docs: https://www.postgresql.org/docs/12/textsearch-controls.html --- tildes/tildes/models/comment/comment_query.py | 4 +++- tildes/tildes/models/topic/topic_query.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tildes/tildes/models/comment/comment_query.py b/tildes/tildes/models/comment/comment_query.py index 509c623..ff5b01b 100644 --- a/tildes/tildes/models/comment/comment_query.py +++ b/tildes/tildes/models/comment/comment_query.py @@ -96,7 +96,9 @@ class CommentQuery(PaginatedQuery): def search(self, query: str) -> "CommentQuery": """Restrict the comments to ones that match a search query (generative).""" - return self.filter(Comment.search_tsv.op("@@")(func.plainto_tsquery(query))) + return self.filter( + Comment.search_tsv.op("@@")(func.websearch_to_tsquery(query)) + ) def only_bookmarked(self) -> "CommentQuery": """Restrict the comments to ones that the user has bookmarked (generative).""" diff --git a/tildes/tildes/models/topic/topic_query.py b/tildes/tildes/models/topic/topic_query.py index 0609170..1f0bea6 100644 --- a/tildes/tildes/models/topic/topic_query.py +++ b/tildes/tildes/models/topic/topic_query.py @@ -175,7 +175,7 @@ class TopicQuery(PaginatedQuery): def search(self, query: str) -> "TopicQuery": """Restrict the topics to ones that match a search query (generative).""" - return self.filter(Topic.search_tsv.op("@@")(func.plainto_tsquery(query))) + return self.filter(Topic.search_tsv.op("@@")(func.websearch_to_tsquery(query))) def only_bookmarked(self) -> "TopicQuery": """Restrict the topics to ones that the user has bookmarked (generative)."""