From 472300c6c83dcc45423daeb07711c55cfa36c994 Mon Sep 17 00:00:00 2001 From: Dan LaManna Date: Mon, 30 Oct 2023 13:15:59 -0400 Subject: [PATCH] Support exists/missing DSL for number searches --- isic/core/dsl.py | 14 +++++++++++--- isic/core/tests/test_dsl.py | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/isic/core/dsl.py b/isic/core/dsl.py index c3a1298f..82d27dec 100644 --- a/isic/core/dsl.py +++ b/isic/core/dsl.py @@ -61,7 +61,10 @@ def to_q(self, key: SearchTermKey) -> Q: class NumberValue(Value): def __init__(self, toks) -> None: - self.value = toks[0] + if toks[0] == "*": + self.value = "*" + else: + self.value = toks[0] class NumberRangeValue(Value): @@ -124,9 +127,14 @@ def q_or(s, loc, toks): # asterisks for wildcard, _ for ISIC ID search, - for license types str_value = (Word(alphas + nums + "*" + "_" + "-") | QuotedString('"')).add_parse_action(StrValue) -number_value = pyparsing_common.number.add_parse_action(NumberValue) +number_value = (pyparsing_common.number.copy() | EXISTS).add_parse_action(NumberValue) +concrete_number_value = pyparsing_common.number.copy().add_parse_action(NumberValue) number_range_value = ( - one_of("[ {") + number_value + Suppress(Literal("TO")) + number_value + one_of("] }") + one_of("[ {") + + concrete_number_value + + Suppress(Literal("TO")) + + concrete_number_value + + one_of("] }") ).add_parse_action(NumberRangeValue) bool_value = one_of("true false *").add_parse_action(BoolValue) diff --git a/isic/core/tests/test_dsl.py b/isic/core/tests/test_dsl.py index c940a8f7..74558687 100644 --- a/isic/core/tests/test_dsl.py +++ b/isic/core/tests/test_dsl.py @@ -13,6 +13,7 @@ # test negation and present/missing values ["-isic_id:*", ~Q(isic__id__isnull=False)], ["-lesion_id:*", ~Q(accession__lesion__id__isnull=False)], + ["-mel_thick_mm:*", ~Q(accession__metadata__mel_thick_mm__isnull=False)], [ "-diagnosis:* OR diagnosis:foobar", ~Q(accession__metadata__diagnosis__isnull=False)