diff --git a/pyproject.toml b/pyproject.toml index 5e64b6f..9aca632 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "sql-redis" -version = "0.1.0" +version = "0.1.1" description = "SQL to Redis command translation utility" authors = [{ name = "Redis Inc.", email = "applied.ai@redis.com" }] requires-python = ">=3.9,<3.14" diff --git a/sql_redis/__init__.py b/sql_redis/__init__.py index 8d6d947..1eacaf4 100644 --- a/sql_redis/__init__.py +++ b/sql_redis/__init__.py @@ -1,5 +1,6 @@ """SQL to Redis command translation utility.""" from sql_redis.translator import TranslatedQuery, Translator +from sql_redis.version import __version__ -__all__ = ["Translator", "TranslatedQuery"] +__all__ = ["Translator", "TranslatedQuery", "__version__"] diff --git a/sql_redis/query_builder.py b/sql_redis/query_builder.py index 68db63a..1b1a1f7 100644 --- a/sql_redis/query_builder.py +++ b/sql_redis/query_builder.py @@ -2,6 +2,48 @@ from __future__ import annotations +import warnings + +# Redis default stopwords - these are not indexed by default +# See: https://redis.io/docs/latest/develop/ai/search-and-query/advanced-concepts/stopwords/ +REDIS_DEFAULT_STOPWORDS = frozenset( + { + "a", + "is", + "the", + "an", + "and", + "are", + "as", + "at", + "be", + "but", + "by", + "for", + "if", + "in", + "into", + "it", + "no", + "not", + "of", + "on", + "or", + "such", + "that", + "their", + "then", + "there", + "these", + "they", + "this", + "to", + "was", + "will", + "with", + } +) + class QueryBuilder: """Builds RediSearch query syntax from conditions.""" @@ -42,8 +84,27 @@ def build_text_condition( # Wrap with % for fuzzy matching search_value = f"%{value}%" elif " " in value: - # Phrase search - wrap in quotes - search_value = f'"{value}"' + # Phrase search - filter stopwords and wrap in quotes + words = value.split() + removed_stopwords = [ + w for w in words if w.lower() in REDIS_DEFAULT_STOPWORDS + ] + filtered_words = [ + w for w in words if w.lower() not in REDIS_DEFAULT_STOPWORDS + ] + + if removed_stopwords: + warnings.warn( + f"Stopwords {removed_stopwords} were removed from phrase search '{value}'. " + "By default, Redis does not index stopwords. " + "To include stopwords in your index, create it with STOPWORDS 0.", + UserWarning, + stacklevel=2, + ) + + # Use filtered phrase, or original if all words were stopwords + phrase = " ".join(filtered_words) if filtered_words else value + search_value = f'"{phrase}"' else: search_value = value diff --git a/sql_redis/version.py b/sql_redis/version.py new file mode 100644 index 0000000..8a79f95 --- /dev/null +++ b/sql_redis/version.py @@ -0,0 +1,11 @@ +try: + from importlib.metadata import PackageNotFoundError, version +except ImportError: + # Python < 3.8 fallback + from importlib_metadata import PackageNotFoundError, version # type: ignore + +try: + __version__ = version("sql-redis") +except PackageNotFoundError: + # Package is not installed (e.g., during development) + __version__ = "0.0.0.dev" diff --git a/uv.lock b/uv.lock index 2e8b0ca..914c7bf 100644 --- a/uv.lock +++ b/uv.lock @@ -1014,7 +1014,7 @@ wheels = [ [[package]] name = "sql-redis" -version = "0.1.0" +version = "0.1.1" source = { editable = "." } dependencies = [ { name = "redis", version = "7.0.1", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.10'" },