From fe063f54cfc3ca3869155b926bdc43c7d3bd3829 Mon Sep 17 00:00:00 2001 From: Jay Hemnani <193022578+jayhemnani9910@users.noreply.github.com> Date: Fri, 13 Nov 2026 03:12:45 +0530 Subject: [PATCH] fix(search): apply a constraint prefix only to its own term --- src/tagstudio/core/query_lang/parser.py | 7 +++---- tests/core/library/test_search.py | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/tagstudio/core/query_lang/parser.py b/src/tagstudio/core/query_lang/parser.py index 1dc336c5c4..e1e6893d1d 100644 --- a/src/tagstudio/core/query_lang/parser.py +++ b/src/tagstudio/core/query_lang/parser.py @@ -20,8 +20,6 @@ class Parser: tokenizer: Tokenizer next_token: Token - last_constraint_type: ConstraintType = ConstraintType.Tag - def __init__(self, text: str) -> None: self.text = text self.tokenizer = Tokenizer(self.text) @@ -92,11 +90,12 @@ def __is_next_not(self) -> bool: return self.next_token.type == TokenType.ULITERAL and self.next_token.value.upper() == "NOT" # pyright: ignore def __constraint(self) -> Constraint: + constraint_type = ConstraintType.Tag if self.next_token.type == TokenType.CONSTRAINTTYPE: constraint = self.__eat(TokenType.CONSTRAINTTYPE).value if not isinstance(constraint, ConstraintType): raise self.__syntax_error() - self.last_constraint_type = constraint + constraint_type = constraint value = self.__literal() @@ -111,7 +110,7 @@ def __constraint(self) -> Constraint: self.__eat(TokenType.SBRACKETC) - return Constraint(self.last_constraint_type, value, properties) + return Constraint(constraint_type, value, properties) def __property(self) -> Property: key = self.__eat(TokenType.ULITERAL).value diff --git a/tests/core/library/test_search.py b/tests/core/library/test_search.py index ee36af1e98..76a5bb61b1 100644 --- a/tests/core/library/test_search.py +++ b/tests/core/library/test_search.py @@ -60,6 +60,7 @@ def test_single_constraint(search_library: Library, query: str, count: int): ("square and filetype:jpg", 2), ("orange filetype:png", 5), ("green path:*inherit*", 4), + ("filetype:png orange", 5), ], ) def test_and(search_library: Library, query: str, count: int):