Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix null numeric filter conditions #164

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions redisvl/query/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,8 @@ def __le__(self, other: int) -> "FilterExpression":

def __str__(self) -> str:
"""Return the Redis Query string for the Numeric filter"""
if not self._value:
if self._value is None:
return "*"

if self._operator == FilterOperator.EQ or self._operator == FilterOperator.NE:
return self.OPERATOR_MAP[self._operator] % (
self._field,
Expand Down
14 changes: 14 additions & 0 deletions tests/integration/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,3 +400,17 @@ def test_sort_vector_query(index, sorted_vector_query):
def test_sort_range_query(index, sorted_range_query):
t = Text("job") % ""
search(sorted_range_query, index, t, 7, sort=True)

def test_query_with_chunk_number_zero():
doc_base_id = "8675309"
file_id = "e9ffbac9ff6f67cc"
chunk_num = 0

filter_conditions = (
(Tag("doc_base_id") == doc_base_id) &
(Tag("file_id") == file_id) &
(Num("chunk_number") == chunk_num)
)

expected_query_str = '((@doc_base_id:{8675309} @file_id:{e9ffbac9ff6f67cc}) @chunk_number:[0 0])'
assert str(filter_conditions) == expected_query_str, "Query with chunk_number zero is incorrect"
4 changes: 4 additions & 0 deletions tests/unit/test_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,7 @@ def test_filters_combination():
tf3 = Text("text_field") == None
tf4 = Geo("geo_field") == GeoRadius(1.0, 2.0, 3, "km")
assert str(tf1 & tf2 & tf3 & tf4) == str(tf1 & tf4)

def test_num_filter_zero():
num_filter = Num("chunk_number") == 0
assert str(num_filter) == "@chunk_number:[0 0]", "Num filter should handle zero correctly"
Loading