Skip to content

Commit

Permalink
fix text queries with single integers
Browse files Browse the repository at this point in the history
  • Loading branch information
capjamesg committed Nov 18, 2024
1 parent d375644 commit 0e6879f
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions jamesql/rewriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,16 @@ def OPERATOR(self, items):

def strict_search_query(self, items):
return {
"or": {
field: {
self.get_query_strategy(value=items[0]): items[0],
"strict": True,
"or": [
{
field: {
self.get_query_strategy(value=items[0]): items[0],
"strict": True,
}
for field in self.query_keys
if self.indexing_strategies.get(field) not in {"NUMERIC", "DATE"}
}
for field in self.query_keys
if self.indexing_strategies.get(field) not in {"NUMERIC", "DATE"}
}
]
}

def TERM(self, items):
Expand Down Expand Up @@ -227,12 +229,22 @@ def word_query(self, items):
if self.indexing_strategies.get(field) == "NUMERIC":
continue

if self.get_query_strategy(field, value) == "contains":
# if value is float, convert to int
# this is because text queries can't be floats
if isinstance(value, float):
value = int(value)

value = str(value)

results = {
field: {
self.get_query_strategy(field, value): value,
}
}



if self.boosts.get(field):
results[field]["boost"] = self.boosts.get(field, boost)

Expand Down

0 comments on commit 0e6879f

Please sign in to comment.