Skip to content

Commit

Permalink
minor cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
emlunde committed Nov 29, 2024
1 parent ebb104e commit 673d2d4
Showing 1 changed file with 4 additions and 29 deletions.
33 changes: 4 additions & 29 deletions web/src/SAP/src/services/search/transpiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 673d2d4

Please sign in to comment.