fixing field based parser
@@ -238,14 +238,14 @@ class ParseSQ(object):
mat = re.search(self.Pattern_Quoted_Text, self.query)
if mat:
text_in_quotes = mat.group(1)
- if (search_operator != ':'):
+ if search_operator != ':':
raise InequalityNotAllowedError(
"Inequality is not meaningful for quoted text \"{}\"."
.format(text_in_quotes))
self.sq = self.apply_operand(SQ(**{search_field: Exact(text_in_quotes)}))
# remove quoted text from query
self.query = re.sub(self.Pattern_Quoted_Text, '', self.query, 1)
- else: # no quotes
+ elif self.query: # no quotes
word = head(self.query) # This has no field specifier
# Append __lt, __lte, etc to query as needed
@@ -277,8 +277,11 @@ class ParseSQ(object):
SQ(**{search_field+inequality_qualifier: thisday}))
else:
self.sq = self.apply_operand(SQ(**{search_field+inequality_qualifier: word}))
- # remove unquoted text from query
- self.query = tail(self.query)
+
+ # remove unquoted text from query which we processed as head
+ remaining_query_string_to_process = tail(self.query)
+ # add back the search field to the query
+ self.query = f"{search_field}:{remaining_query_string_to_process}"
self.current = self.Default_Operator
@@ -330,6 +333,9 @@ class ParseSQ(object):
This can raise ValueError if the values passed are not valid.
"""
self.query = query
+ # print(f">> query string in parse method {query}")
+ # if self.query.endswith('"'):
+ # print("query string has quotes in parse method")
self.sq = SQ()
self.current = self.Default_Operator
while self.query:
