Skip to content

Commit

Permalink
fix text query expansion into numeric fields
Browse files Browse the repository at this point in the history
  • Loading branch information
capjamesg committed Aug 24, 2024
1 parent 5469dde commit 19b7dcd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion jamesql/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def _compute_string_query(self, query: str, query_keys: list = []) -> List[str]:
if not query_keys:
query_keys = list(self.gsis.keys())

indexing_strategies = {}
indexing_strategies = {name: gsi["strategy"] for name, gsi in self.gsis.items()}

query = string_query_to_jamesql(
query, query_keys=query_keys, default_strategies=indexing_strategies
Expand Down
8 changes: 6 additions & 2 deletions jamesql/rewriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@

class QueryRewriter(Transformer):
def __init__(self, default_strategies=None, query_keys=None):
self.default_strategies = default_strategies
self.indexing_strategies = default_strategies
self.query_keys = query_keys

def get_query_strategy(self, key="", value=""):
default = "contains"

if isinstance(value, str) and "*" in value:
return "wildcard"

Expand Down Expand Up @@ -71,6 +71,7 @@ def strict_search_query(self, items):
"strict": True,
}
for field in self.query_keys
if self.indexing_strategies.get(field) != "NUMERIC"
}
}

Expand Down Expand Up @@ -107,6 +108,9 @@ def word_query(self, items):
field = key
value = items[0]

if self.indexing_strategies.get(field) == "NUMERIC":
continue

result.append({field: {self.get_query_strategy(field, value): value}})

return {"or": result}
Expand Down

0 comments on commit 19b7dcd

Please sign in to comment.