From eaa7a0a34b1467c5ac25e6d4fe576d8037a9ed11 Mon Sep 17 00:00:00 2001 From: Andrew Shu Date: Wed, 15 Jul 2020 00:14:06 -0700 Subject: [PATCH] Include "inner" subpath tags when tag filtering --- tildes/tildes/lib/database.py | 2 +- tildes/tildes/models/topic/topic_query.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tildes/tildes/lib/database.py b/tildes/tildes/lib/database.py index ca32573..6faa98d 100644 --- a/tildes/tildes/lib/database.py +++ b/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): diff --git a/tildes/tildes/models/topic/topic_query.py b/tildes/tildes/models/topic/topic_query.py index 66b1599..0d96767 100644 --- a/tildes/tildes/models/topic/topic_query.py +++ b/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)."""