@@ -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 [
0 commit comments