diff --git a/web/src/SAP/src/services/search/transpiler.py b/web/src/SAP/src/services/search/transpiler.py index 9945326..a3b08bc 100644 --- a/web/src/SAP/src/services/search/transpiler.py +++ b/web/src/SAP/src/services/search/transpiler.py @@ -82,47 +82,22 @@ def structure_wildcard(field, node): return {"$in": [coerced, node.term]} -def is_date_string(value): - try: - datetime.fromisoformat(value) - return True - except ValueError: - return False - -def is_float_string(value): - try: - float(value) - return True - except ValueError: - return False - -def convert_type(value): - if value.isdigit(): - return int(value) - elif is_float_string(value): - return float(value) - elif value.isdigit(): - return int(value) - elif is_date_string(value): - return datetime.fromisoformat(value) - return value - - def structure_ranged(field, node): min_op = "$gte" if node.inclusive == "left" or node.inclusive == "both" else "$gt" max_op = "$lte" if node.inclusive == "right" or node.inclusive == "both" else "$lt" + #if the hours, minutes and seconds are not in the search like this 2022-04-08T09:01:07 it is assumed that the entire day is intended to be included #default with the specific time of day not specified it is as if they are 00, which would exclude all records from during that day, which is not the behavior we expect is wanted - max_term = convert_type(node.term_max) + max_term = coerce_term(node.term_max) if type(max_term) == datetime and max_op =="$lte" and max_term.hour == 0 and max_term.minute == 0 and max_term.second == 0: max_term = max_term + timedelta(days = 1 ) - timedelta(seconds = 1) if node.term_min == "*": return {max_op: max_term} if node.term_max == "*": - return {min_op: convert_type(node.term_min)} + return {min_op: coerce_term(node.term_min)} - return {min_op: convert_type(node.term_min), max_op: max_term} + return {min_op: coerce_term(node.term_min), max_op: max_term} def structure_leaf(node, is_negated):