Skip to content

Commit

Permalink
Merge branch 'fix/tsquery' of github.com:neurostuff/neurostore into s…
Browse files Browse the repository at this point in the history
…taging
  • Loading branch information
jdkent committed Nov 18, 2024
2 parents 8e19d95 + cd4a65c commit c078b37
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
13 changes: 13 additions & 0 deletions store/neurostore/resources/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ def validate_search_query(query: str) -> bool:
if not validate_query_end(query):
raise errors.SyntaxError("Query cannot end with an operator")

if not validate_multiple_operators(query):
raise errors.SyntaxError("Consecutive operators are not allowed")

return True


Expand Down Expand Up @@ -98,6 +101,16 @@ def validate_query_end(query: str) -> bool:
return True


def validate_multiple_operators(query: str) -> bool:
"""Validate that there are no consecutive operators in a query."""
operators = ("AND", "OR", "NOT", "&", "|", "&!")
query = query.strip().split(" ")
for i in range(len(query) - 1):
if query[i] in operators and query[i + 1] in operators:
return False
return True


def count_chars(target, query: str) -> int:
"""Count the number of chars in a query string.
Excluding those in quoted phrases."""
Expand Down
3 changes: 3 additions & 0 deletions store/neurostore/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,9 @@ def simple_neurosynth_annotation(session, ingest_neurosynth):
'OR ("ASD")) AND (("decision*" OR "Dec',
"Unmatched parentheses",
),
(
'smoking AND NOT memory', "Consecutive operators are not allowed"
)
]

valid_queries = [
Expand Down

0 comments on commit c078b37

Please sign in to comment.