Skip to content

Commit 30c0132

Browse files
committed
add version, drop stop words in phrase
1 parent cdd8212 commit 30c0132

5 files changed

Lines changed: 78 additions & 5 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "sql-redis"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
description = "SQL to Redis command translation utility"
55
authors = [{ name = "Redis Inc.", email = "applied.ai@redis.com" }]
66
requires-python = ">=3.9,<3.14"

sql_redis/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""SQL to Redis command translation utility."""
22

33
from sql_redis.translator import TranslatedQuery, Translator
4+
from sql_redis.version import __version__
45

5-
__all__ = ["Translator", "TranslatedQuery"]
6+
__all__ = ["Translator", "TranslatedQuery", "__version__"]

sql_redis/query_builder.py

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,48 @@
22

33
from __future__ import annotations
44

5+
import warnings
6+
7+
# Redis default stopwords - these are not indexed by default
8+
# See: https://redis.io/docs/latest/develop/ai/search-and-query/advanced-concepts/stopwords/
9+
REDIS_DEFAULT_STOPWORDS = frozenset(
10+
{
11+
"a",
12+
"is",
13+
"the",
14+
"an",
15+
"and",
16+
"are",
17+
"as",
18+
"at",
19+
"be",
20+
"but",
21+
"by",
22+
"for",
23+
"if",
24+
"in",
25+
"into",
26+
"it",
27+
"no",
28+
"not",
29+
"of",
30+
"on",
31+
"or",
32+
"such",
33+
"that",
34+
"their",
35+
"then",
36+
"there",
37+
"these",
38+
"they",
39+
"this",
40+
"to",
41+
"was",
42+
"will",
43+
"with",
44+
}
45+
)
46+
547

648
class QueryBuilder:
749
"""Builds RediSearch query syntax from conditions."""
@@ -42,8 +84,27 @@ def build_text_condition(
4284
# Wrap with % for fuzzy matching
4385
search_value = f"%{value}%"
4486
elif " " in value:
45-
# Phrase search - wrap in quotes
46-
search_value = f'"{value}"'
87+
# Phrase search - filter stopwords and wrap in quotes
88+
words = value.split()
89+
removed_stopwords = [
90+
w for w in words if w.lower() in REDIS_DEFAULT_STOPWORDS
91+
]
92+
filtered_words = [
93+
w for w in words if w.lower() not in REDIS_DEFAULT_STOPWORDS
94+
]
95+
96+
if removed_stopwords:
97+
warnings.warn(
98+
f"Stopwords {removed_stopwords} were removed from phrase search '{value}'. "
99+
"By default, Redis does not index stopwords. "
100+
"To include stopwords in your index, create it with STOPWORDS 0.",
101+
UserWarning,
102+
stacklevel=2,
103+
)
104+
105+
# Use filtered phrase, or original if all words were stopwords
106+
phrase = " ".join(filtered_words) if filtered_words else value
107+
search_value = f'"{phrase}"'
47108
else:
48109
search_value = value
49110

sql_redis/version.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
try:
2+
from importlib.metadata import PackageNotFoundError, version
3+
except ImportError:
4+
# Python < 3.8 fallback
5+
from importlib_metadata import PackageNotFoundError, version # type: ignore
6+
7+
try:
8+
__version__ = version("sql-redis")
9+
except PackageNotFoundError:
10+
# Package is not installed (e.g., during development)
11+
__version__ = "0.0.0.dev"

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)