Skip to content

Commit c078b37

Browse files
committed
Merge branch 'fix/tsquery' of github.com:neurostuff/neurostore into staging
2 parents 8e19d95 + cd4a65c commit c078b37

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

store/neurostore/resources/utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ def validate_search_query(query: str) -> bool:
6565
if not validate_query_end(query):
6666
raise errors.SyntaxError("Query cannot end with an operator")
6767

68+
if not validate_multiple_operators(query):
69+
raise errors.SyntaxError("Consecutive operators are not allowed")
70+
6871
return True
6972

7073

@@ -98,6 +101,16 @@ def validate_query_end(query: str) -> bool:
98101
return True
99102

100103

104+
def validate_multiple_operators(query: str) -> bool:
105+
"""Validate that there are no consecutive operators in a query."""
106+
operators = ("AND", "OR", "NOT", "&", "|", "&!")
107+
query = query.strip().split(" ")
108+
for i in range(len(query) - 1):
109+
if query[i] in operators and query[i + 1] in operators:
110+
return False
111+
return True
112+
113+
101114
def count_chars(target, query: str) -> int:
102115
"""Count the number of chars in a query string.
103116
Excluding those in quoted phrases."""

store/neurostore/tests/conftest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,9 @@ def simple_neurosynth_annotation(session, ingest_neurosynth):
602602
'OR ("ASD")) AND (("decision*" OR "Dec',
603603
"Unmatched parentheses",
604604
),
605+
(
606+
'smoking AND NOT memory', "Consecutive operators are not allowed"
607+
)
605608
]
606609

607610
valid_queries = [

0 commit comments

Comments
 (0)