Skip to content

Commit fe6b8be

Browse files
authored
Filter expression as native string (#367)
Bug fix: Solves problem if you pass a native string as a filter_expression not to set to blank string.
1 parent 9dd1aab commit fe6b8be

File tree

6 files changed

+77
-11
lines changed

6 files changed

+77
-11
lines changed

docs/overview/cli.ipynb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"name": "stdout",
2525
"output_type": "stream",
2626
"text": [
27-
"12:42:18 [RedisVL] INFO RedisVL version 0.8.0\n"
27+
"11:20:38 [RedisVL] INFO RedisVL version 0.8.2\n"
2828
]
2929
}
3030
],
@@ -300,7 +300,7 @@
300300
"\n",
301301
"| Argument | Description | Default |\n",
302302
"|----------------|-------------|---------|\n",
303-
"| `-u --url` | The full Redis URL to connec to | `redis://localhost:6379` |\n",
303+
"| `-u --url` | The full Redis URL to connect to | `redis://localhost:6379` |\n",
304304
"| `--host` | Redis host to connect to | `localhost` |\n",
305305
"| `-p --port` | Redis port to connect to. Must be an integer | `6379` |\n",
306306
"| `--user` | Redis username, if one is required | `default` |\n",
@@ -339,8 +339,8 @@
339339
"cell_type": "markdown",
340340
"metadata": {},
341341
"source": [
342-
"### Using SSL encription\n",
343-
"If your Redis instance is configured to use SSL encription then set the `--ssl` flag.\n",
342+
"### Using SSL encryption\n",
343+
"If your Redis instance is configured to use SSL encryption then set the `--ssl` flag.\n",
344344
"You can similarly specify the username and password to construct the full Redis URL"
345345
]
346346
},
@@ -374,7 +374,7 @@
374374
],
375375
"metadata": {
376376
"kernelspec": {
377-
"display_name": ".venv",
377+
"display_name": "redisvl-56gG2io_-py3.11",
378378
"language": "python",
379379
"name": "python3"
380380
},
@@ -388,7 +388,7 @@
388388
"name": "python",
389389
"nbconvert_exporter": "python",
390390
"pygments_lexer": "ipython3",
391-
"version": "3.13.2"
391+
"version": "3.11.9"
392392
}
393393
},
394394
"nbformat": 4,

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)