Browse Source

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
merge-requests/85/head
Deimos 5 years ago
parent
commit
20de7cd0fe
  1. 4
      tildes/tildes/models/comment/comment_query.py
  2. 2
      tildes/tildes/models/topic/topic_query.py

4
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)."""

2
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)."""

Loading…
Cancel
Save