Skip to content

Commit 2bd23c7

Browse files
committed
refactor: Improve code organization and extend stopwords validation
Three improvements: 1. Rename test class for clarity - TestMultipleCommandsScenarioIntegration → TestFieldModifierIntegration - test_mlp_commands_index_creation → test_index_creation_with_multiple_modifiers - Use general naming instead of MLP-specific terminology for open-source 2. Move imports to file level - Moved FilterQuery import from inside test function to top of file - Follows standard Python convention 3. Extend stopwords validation to AggregateHybridQuery - Added AggregateHybridQuery to stopwords warning in _validate_query() - Both TextQuery and AggregateHybridQuery now warn when using query-time stopwords with index-level STOPWORDS 0 - Warning message now includes the specific query type for clarity
1 parent 4d70be5 commit 2bd23c7

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

redisvl/index/index.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
FilterQuery,
8282
TextQuery,
8383
)
84+
from redisvl.query.aggregate import AggregateHybridQuery
8485
from redisvl.query.filter import FilterExpression
8586
from redisvl.redis.connection import (
8687
RedisConnectionFactory,
@@ -250,24 +251,25 @@ def _validate_query(self, query: BaseQuery) -> None:
250251
)
251252

252253
# Warn if using query-time stopwords with index-level STOPWORDS 0
253-
if isinstance(query, TextQuery):
254+
if isinstance(query, (TextQuery, AggregateHybridQuery)):
254255
index_stopwords = self.schema.index.stopwords
255256
query_stopwords = query.stopwords
256257

257258
# Check if index has STOPWORDS 0 (empty list) and query has stopwords configured
258-
# Note: query.stopwords is a set, and when stopwords=None is passed to TextQuery,
259+
# Note: query.stopwords is a set, and when stopwords=None is passed to TextQuery/AggregateHybridQuery,
259260
# it becomes an empty set. So we check if the set is non-empty.
260261
if (
261262
index_stopwords is not None
262263
and len(index_stopwords) == 0
263264
and len(query_stopwords) > 0
264265
):
266+
query_type = "TextQuery" if isinstance(query, TextQuery) else "AggregateHybridQuery"
265267
warnings.warn(
266-
"Query-time stopwords are configured but the index has STOPWORDS 0 (stopwords = []). "
268+
f"Query-time stopwords are configured but the index has STOPWORDS 0 (stopwords = []). "
267269
"This is counterproductive: all words including common words like 'of', 'the', 'a' are indexed, "
268270
"but your query-time stopwords will filter them from the search query. "
269271
"This makes your search less precise than it could be. "
270-
"Consider setting stopwords=None in TextQuery to search for all indexed words. "
272+
f"Consider setting stopwords=None in {query_type} to search for all indexed words. "
271273
"See docs/stopwords_interaction_guide.md for more information.",
272274
UserWarning,
273275
stacklevel=3,

tests/integration/test_field_modifier_ordering_integration.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,10 @@ def test_mixed_field_types_with_modifiers(self, client, redis_url, worker_id):
304304
index.delete(drop=True)
305305

306306

307-
class TestMultipleCommandsScenarioIntegration:
308-
"""Integration tests for mlp_commands.txt scenario."""
307+
class TestFieldModifierIntegration:
308+
"""Integration tests for complex field modifier combinations."""
309309

310-
def test_mlp_commands_index_creation(self, client, redis_url, worker_id):
310+
def test_index_creation_with_multiple_modifiers(self, client, redis_url, worker_id):
311311
"""Test creating index with INDEXMISSING SORTABLE UNF modifiers.
312312
313313
This test verifies that an index with all three modifiers

tests/integration/test_stopwords_integration.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import pytest
44

55
from redisvl.index import SearchIndex
6+
from redisvl.query import FilterQuery
67
from redisvl.schema import IndexSchema
78

89

@@ -180,8 +181,6 @@ def test_stopwords_disabled_allows_searching_common_words(
180181
client.hset(key, mapping=data)
181182

182183
# Search for "of" - should find "Bank of America"
183-
from redisvl.query import FilterQuery
184-
185184
query = FilterQuery(
186185
filter_expression="@title:(of)",
187186
return_fields=["title"],

0 commit comments

Comments
 (0)