Skip to content

manually parse special attributes that have no associated value #239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 30, 2024
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
25 changes: 24 additions & 1 deletion redisvl/redis/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,30 @@ def parse_vector_attrs(attrs):
return vector_attrs

def parse_attrs(attrs):
return {attrs[i].lower(): attrs[i + 1] for i in range(6, len(attrs), 2)}
# 'SORTABLE', 'NOSTEM' don't have corresponding values.
# Their presence indicates boolean True
# TODO 'WITHSUFFIXTRIE' is another boolean attr, but is not returned by ft.info
original = attrs.copy()
parsed_attrs = {}
if "NOSTEM" in attrs:
parsed_attrs["no_stem"] = True
attrs.remove("NOSTEM")
if "CASESENSITIVE" in attrs:
parsed_attrs["case_sensitive"] = True
attrs.remove("CASESENSITIVE")
if "SORTABLE" in attrs:
parsed_attrs["sortable"] = True
attrs.remove("SORTABLE")
if "UNF" in attrs:
attrs.remove("UNF") # UNF present on sortable numeric fields only

try:
parsed_attrs.update(
{attrs[i].lower(): attrs[i + 1] for i in range(6, len(attrs), 2)}
)
except IndexError as e:
raise IndexError(f"Error parsing index attributes {original}, {str(e)}")
return parsed_attrs

schema_fields = []

Expand Down
15 changes: 13 additions & 2 deletions tests/integration/test_search_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,18 @@
from redisvl.redis.utils import convert_bytes
from redisvl.schema import IndexSchema, StorageType

fields = [{"name": "test", "type": "tag"}]
fields = [
{"name": "test", "type": "tag"},
{"name": "test_text", "type": "text"},
{
"name": "test_text_attrs",
"type": "text",
"attrs": {"no_stem": True, "sortable": True},
},
{"name": "test_tag", "type": "tag", "attrs": {"case_sensitive": True}},
{"name": "test_numeric", "type": "numeric"},
{"name": "test_numeric_attrs", "type": "numeric", "attrs": {"sortable": True}},
]


@pytest.fixture
Expand Down Expand Up @@ -87,7 +98,7 @@ def test_search_index_from_existing_complex(client):
"name": "age",
"type": "numeric",
"path": "$.metadata.age",
"attrs": {"sortable": False},
"attrs": {"sortable": True},
},
{
"name": "user_embedding",
Expand Down
Loading