Skip to content

Commit 71fc418

Browse files
committed
add tests and update class
1 parent 9dd1aab commit 71fc418

File tree

5 files changed

+71
-5
lines changed

5 files changed

+71
-5
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "redisvl"
3-
version = "0.8.1"
3+
version = "0.8.2"
44
description = "Python client library and CLI for using Redis as a vector database"
55
authors = [{ name = "Redis Inc.", email = "[email protected]" }]
66
requires-python = ">=3.9,<3.14"

redisvl/query/query.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -939,8 +939,6 @@ def _build_query_string(self) -> str:
939939
filter_expression = self._filter_expression
940940
if isinstance(filter_expression, FilterExpression):
941941
filter_expression = str(filter_expression)
942-
else:
943-
filter_expression = ""
944942

945943
text = (
946944
f"@{self._text_field_name}:({self._tokenize_and_escape_query(self._text)})"

redisvl/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.8.0"
1+
__version__ = "0.8.2"

tests/unit/test_query_types.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,74 @@ def test_text_query():
280280
text_query = TextQuery(text_string, text_field_name, stopwords=[1, 2, 3])
281281

282282

283+
def test_text_query_with_string_filter():
284+
"""Test that TextQuery correctly includes string filter expressions in query string.
285+
286+
This test ensures that when a string filter expression is passed to TextQuery,
287+
it's properly included in the generated query string and not set to empty.
288+
Regression test for bug where string filters were being ignored.
289+
"""
290+
text = "search for document 12345"
291+
text_field_name = "description"
292+
293+
# Test with string filter expression - should include filter in query string
294+
string_filter = "@category:{tech|science|engineering}"
295+
text_query = TextQuery(
296+
text=text,
297+
text_field_name=text_field_name,
298+
filter_expression=string_filter,
299+
)
300+
301+
# Check that filter is stored correctly
302+
assert text_query.filter == string_filter
303+
304+
# Check that the generated query string includes both text search and filter
305+
query_string = str(text_query)
306+
assert f"@{text_field_name}:(search | document | 12345)" in query_string
307+
assert f"AND {string_filter}" in query_string
308+
assert string_filter in query_string
309+
310+
# Test with FilterExpression - should also work (existing functionality)
311+
filter_expression = Tag("category") == "tech"
312+
text_query_with_filter_expr = TextQuery(
313+
text=text,
314+
text_field_name=text_field_name,
315+
filter_expression=filter_expression,
316+
)
317+
318+
# Check that filter is stored correctly
319+
assert text_query_with_filter_expr.filter == filter_expression
320+
321+
# Check that the generated query string includes both text search and filter
322+
query_string_with_filter_expr = str(text_query_with_filter_expr)
323+
assert (
324+
f"@{text_field_name}:(search | document | 12345)"
325+
in query_string_with_filter_expr
326+
)
327+
assert "AND @category:{tech}" in query_string_with_filter_expr
328+
329+
# Test with no filter - should only have text search
330+
text_query_no_filter = TextQuery(
331+
text=text,
332+
text_field_name=text_field_name,
333+
)
334+
335+
query_string_no_filter = str(text_query_no_filter)
336+
assert f"@{text_field_name}:(search | document | 12345)" in query_string_no_filter
337+
assert "AND" not in query_string_no_filter
338+
339+
# Test with wildcard filter - should only have text search (no AND clause)
340+
text_query_wildcard = TextQuery(
341+
text=text,
342+
text_field_name=text_field_name,
343+
filter_expression="*",
344+
)
345+
346+
query_string_wildcard = str(text_query_wildcard)
347+
assert f"@{text_field_name}:(search | document | 12345)" in query_string_wildcard
348+
assert "AND" not in query_string_wildcard
349+
350+
283351
@pytest.mark.parametrize(
284352
"query",
285353
[

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)