Skip to content

Commit

Permalink
#243: Add ilike and nilike operators
Browse files Browse the repository at this point in the history
  • Loading branch information
MRichards99 committed Oct 15, 2021
1 parent a6156e3 commit e352812
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion datagateway_api/common/icat/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,20 @@ def create_filter(self):
where_filter = self.create_condition(self.field, "!=", self.value)
elif self.operation == "like":
where_filter = self.create_condition(self.field, "like", f"%{self.value}%")
elif self.operation == "ilike":
self.field = f"UPPER({self.field})"
where_filter = self.create_condition(
self.field, "like", f"UPPER('%{self.value}%')",
)
elif self.operation == "nlike":
where_filter = self.create_condition(
self.field, "not like", f"%{self.value}%",
)
elif self.operation == "nilike":
self.field = f"UPPER({self.field})"
where_filter = self.create_condition(
self.field, "not like", f"UPPER('%{self.value}%')",
)
elif self.operation == "lt":
where_filter = self.create_condition(self.field, "<", self.value)
elif self.operation == "lte":
Expand Down Expand Up @@ -101,7 +111,10 @@ def create_condition(attribute_name, operator, value):
# distinct filter is used in a request
jpql_value = (
f"{value}"
if operator == "in" or operator == "!=" or "o." in str(value)
if operator == "in"
or operator == "!="
or str(value).startswith("UPPER")
or "o." in str(value)
else f"'{value}'"
)

Expand Down

0 comments on commit e352812

Please sign in to comment.