Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions services/search/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ def build_search_query(query: str):
if re.fullmatch(r"'+", and_operand):
# Skip any operands that are just repeating single-quotes
continue
if not and_operand.strip():
# Skip empty operands to prevent invalid tsquery syntax like ":*"
continue
if expression:
expression += f" & {and_operand}:*"
else:
Expand Down
10 changes: 10 additions & 0 deletions services/search/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,16 @@ def test_search_with_vertical_bar_in_query(api_client, units):
("a, &&& , & b || || |||| |c,,,, d", "a:* & b:* | c:* & d:*"),
# Expression with repeating single-quotes
("','','''',a,b'c,d''e,f'''g,','','''", "a:* & b'c:* & d''e:* & f'''g:*"),
# Empty operands should be skipped to prevent invalid ":*" syntax
(" ", ""),
(" | ", ""),
(" & ", ""),
(" , ", ""),
("a | | b", "a:* | b:*"),
("a & & b", "a:* & b:*"),
("a, ,b", "a:* & b:*"),
(" | a", "a:*"),
("a | ", "a:*"),
],
)
def test_build_search_query(query, expected):
Expand Down
Loading