Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
3 changes: 2 additions & 1 deletion sql_redis/__init__.py
Original file line number Diff line number Diff line change
@@ -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__"]
65 changes: 63 additions & 2 deletions sql_redis/query_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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

Expand Down
11 changes: 11 additions & 0 deletions sql_redis/version.py
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.