Browse Source

Include "inner" subpath tags when tag filtering

merge-requests/116/head
Andrew Shu 4 years ago
parent
commit
eaa7a0a34b
  1. 2
      tildes/tildes/lib/database.py
  2. 8
      tildes/tildes/models/topic/topic_query.py

2
tildes/tildes/lib/database.py

@ -147,7 +147,7 @@ class ArrayOfLtree(ARRAY):
if isinstance(other, list):
return self.op("?")(cast(other, ARRAY(LQUERY)))
else:
return self.op("~")(other)
return self.op("~")(cast(other, LQUERY))
class RecurrenceRule(TypeDecorator):

8
tildes/tildes/models/topic/topic_query.py

@ -206,13 +206,13 @@ class TopicQuery(PaginatedQuery):
def has_tag(self, tag: str) -> "TopicQuery":
"""Restrict the topics to ones with a specific tag (generative).
Note that this method searches for topics that have any tag that either starts
or ends with the specified tag, not only exact/full matches.
Note that this method searches for topics that have any tag that contains
the specified tag as a subpath, not only exact/full matches.
"""
queries = [f"{tag}.*", f"*.{tag}"]
query = f"*.{tag}.*"
# pylint: disable=protected-access
return self.filter(Topic.tags.lquery(queries)) # type: ignore
return self.filter(Topic.tags.lquery(query)) # type: ignore
def search(self, query: str) -> "TopicQuery":
"""Restrict the topics to ones that match a search query (generative)."""

Loading…
Cancel
Save