Skip to content

Commit

Permalink
add numeric tests
Browse files Browse the repository at this point in the history
  • Loading branch information
capjamesg committed Oct 18, 2024
1 parent df1d416 commit 92c0dcd
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
4 changes: 1 addition & 3 deletions jamesql/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -870,8 +870,6 @@ def search(self, query: dict) -> List[str]:

document["_score"] = transformer.transform(tree)

print(document["_score"])

results = sorted(results, key=lambda x: x.get("_score", 0), reverse=True)

if query.get("skip"):
Expand Down Expand Up @@ -1254,7 +1252,7 @@ def _run(self, query: dict, query_field: str) -> List[str]:

matching_highlights.update(matches_with_context)
else:
for word in query_term.split(" "):
for word in str(query_term).split(" "):
word = word.lower()

if gsi.get(word) is None:
Expand Down
7 changes: 7 additions & 0 deletions tests/query_simplification.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ def create_indices(request):
"",
DoesNotRaise(),
), # test negation simplification with empty string result
(
"100 100",
"100",
0,
"",
DoesNotRaise(),
), # test numeric query simplification
(
"screaming -sky",
"screaming -sky",
Expand Down
30 changes: 30 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,36 @@ def create_indices(request):
"tolerate it",
DoesNotRaise(),
), # test starts_with
(
{
"query": {"lyric": {"contains": "100"}},
"limit": 10,
"sort_by": "lyric"
},
0,
"",
DoesNotRaise(),
), # test numeric query
(
{
"query": {"lyric": {"contains": 100}},
"limit": 10,
"sort_by": "lyric"
},
0,
"",
DoesNotRaise(),
), # test numeric query cast as int
(
{
"query": {"lyric": {"contains": 100.001}},
"limit": 10,
"sort_by": "lyric"
},
0,
"",
DoesNotRaise(),
), # test numeric query cast as float
(
{
"query": {"lyric": {"starts_with": "started with"}},
Expand Down

0 comments on commit 92c0dcd

Please sign in to comment.