Skip to content

Commit d743740

Browse files
author
Gerit Wagner
committed
Merge branch 'main' into cli
2 parents e1ed383 + a92589b commit d743740

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

search_query/constants.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ class QueryErrorCode(Enum):
467467
"W0006",
468468
"implicit-near-value",
469469
"The value of NEAR operator is implicit",
470-
"""**Typical fix**: The parser automatically sets implicit NEAR values to the default of 15.
470+
"""**Typical fix**: The parser automatically sets NEAR values to 15 (default).
471471
472472
**Problematic query**:
473473
@@ -486,7 +486,9 @@ class QueryErrorCode(Enum):
486486
["all", PLATFORM.PUBMED],
487487
"W0007",
488488
"implicit-precedence",
489-
"Operator changed at the same level (currently relying on implicit operator precedence, explicit parentheses are recommended)",
489+
"Operator changed at the same level "
490+
"(currently relying on implicit operator precedence, "
491+
"explicit parentheses are recommended)",
490492
"",
491493
)
492494

search_query/parser_base.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,6 @@ def add_artificial_parentheses_for_operator_precedence(
291291
art_par += 1
292292

293293
if index == len(self.tokens):
294-
print(output)
295294
output = self.flatten_redundant_artificial_nesting(output)
296295
self.tokens = output
297296

search_query/parser_ebsco.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,8 @@ def combine_subsequent_tokens(self) -> None:
7070
and self.tokens[i + 1].type == TokenTypes.SEARCH_TERM
7171
):
7272
# Iterate over subsequent search_terms and combine
73-
next_token, _, next_position = self.tokens[i + 1]
74-
combined_value += f" {next_token}"
75-
end_position = next_position[1]
73+
combined_value += f" {self.tokens[i + 1].value}"
74+
end_position = self.tokens[i + 1].position[1]
7675
i += 1
7776

7877
combined_tokens.append(
@@ -270,16 +269,21 @@ def parse_query_tree(
270269
current_operator: typing.Optional[Query] = None
271270

272271
while tokens:
273-
token, token_type, position = tokens.pop(0)
272+
token = tokens.pop(0)
274273

275-
if token_type == TokenTypes.FIELD:
274+
if token.type == TokenTypes.FIELD:
276275
# Create new search_field used by following search_terms
277-
search_field = SearchField(token, position=position)
276+
search_field = SearchField(token.value, position=token.position)
278277

279-
elif token_type == TokenTypes.SEARCH_TERM:
278+
elif token.type == TokenTypes.SEARCH_TERM:
280279
# Create new search_term and in case tree is empty, sets first root
281280
term_node = self.create_query_node(
282-
token, False, position, search_field, None, search_field_par
281+
token.value,
282+
False,
283+
token.position,
284+
search_field,
285+
None,
286+
search_field_par,
283287
)
284288

285289
# Append search_term to tree
@@ -289,22 +293,24 @@ def parse_query_tree(
289293

290294
search_field = None
291295

292-
elif token_type == TokenTypes.PROXIMITY_OPERATOR:
296+
elif token.type == TokenTypes.PROXIMITY_OPERATOR:
293297
# Split token into NEAR/WITHIN and distance
294-
token, distance = self.convert_proximity_operators(token, token_type)
298+
token.value, distance = self.convert_proximity_operators(
299+
token.value, token.type
300+
)
295301

296302
# Create new proximity_operator from token (N3, W1, N13, ...)
297303
proximity_node = self.create_query_node(
298-
token, True, position, search_field, distance
304+
token.value, True, token.position, search_field, distance
299305
)
300306

301307
# Set proximity_operator as tree node
302308
root, current_operator = self.append_operator(root, proximity_node)
303309

304-
elif token_type == TokenTypes.LOGIC_OPERATOR:
310+
elif token.type == TokenTypes.LOGIC_OPERATOR:
305311
# Create new operator node
306312
new_operator_node = self.create_query_node(
307-
token, True, position, search_field, None
313+
token.value, True, token.position, search_field, None
308314
)
309315

310316
if not current_operator:
@@ -313,7 +319,7 @@ def parse_query_tree(
313319
root, new_operator_node
314320
)
315321

316-
elif token_type == TokenTypes.PARENTHESIS_OPEN:
322+
elif token.type == TokenTypes.PARENTHESIS_OPEN:
317323
# Recursively parse the group inside parentheses
318324
# Set search_field_par as search field regarding the whole subtree
319325
# If subtree is done, reset search_field_par
@@ -327,7 +333,7 @@ def parse_query_tree(
327333
root, current_operator, subtree
328334
)
329335

330-
elif token_type == TokenTypes.PARENTHESIS_CLOSED:
336+
elif token.type == TokenTypes.PARENTHESIS_CLOSED:
331337
# Return subtree
332338
root = self.check_for_none(root)
333339
return root

0 commit comments

Comments
 (0)