Skip to content

Commit 4ab6493

Browse files
manually parse special attributes that have no associated value (#239)
When converting existing index info into a schema certain attributes have a name and value, and others are indicated as True/False only by their presence in the attributes list. These are removed and parsed manually before the remaining items.
1 parent 6aa0111 commit 4ab6493

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

redisvl/redis/connection.py

+24-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,30 @@ def parse_vector_attrs(attrs):
9898
return vector_attrs
9999

100100
def parse_attrs(attrs):
101-
return {attrs[i].lower(): attrs[i + 1] for i in range(6, len(attrs), 2)}
101+
# 'SORTABLE', 'NOSTEM' don't have corresponding values.
102+
# Their presence indicates boolean True
103+
# TODO 'WITHSUFFIXTRIE' is another boolean attr, but is not returned by ft.info
104+
original = attrs.copy()
105+
parsed_attrs = {}
106+
if "NOSTEM" in attrs:
107+
parsed_attrs["no_stem"] = True
108+
attrs.remove("NOSTEM")
109+
if "CASESENSITIVE" in attrs:
110+
parsed_attrs["case_sensitive"] = True
111+
attrs.remove("CASESENSITIVE")
112+
if "SORTABLE" in attrs:
113+
parsed_attrs["sortable"] = True
114+
attrs.remove("SORTABLE")
115+
if "UNF" in attrs:
116+
attrs.remove("UNF") # UNF present on sortable numeric fields only
117+
118+
try:
119+
parsed_attrs.update(
120+
{attrs[i].lower(): attrs[i + 1] for i in range(6, len(attrs), 2)}
121+
)
122+
except IndexError as e:
123+
raise IndexError(f"Error parsing index attributes {original}, {str(e)}")
124+
return parsed_attrs
102125

103126
schema_fields = []
104127

tests/integration/test_search_index.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,18 @@
77
from redisvl.redis.utils import convert_bytes
88
from redisvl.schema import IndexSchema, StorageType
99

10-
fields = [{"name": "test", "type": "tag"}]
10+
fields = [
11+
{"name": "test", "type": "tag"},
12+
{"name": "test_text", "type": "text"},
13+
{
14+
"name": "test_text_attrs",
15+
"type": "text",
16+
"attrs": {"no_stem": True, "sortable": True},
17+
},
18+
{"name": "test_tag", "type": "tag", "attrs": {"case_sensitive": True}},
19+
{"name": "test_numeric", "type": "numeric"},
20+
{"name": "test_numeric_attrs", "type": "numeric", "attrs": {"sortable": True}},
21+
]
1122

1223

1324
@pytest.fixture
@@ -88,7 +99,7 @@ def test_search_index_from_existing_complex(client):
8899
"name": "age",
89100
"type": "numeric",
90101
"path": "$.metadata.age",
91-
"attrs": {"sortable": False},
102+
"attrs": {"sortable": True},
92103
},
93104
{
94105
"name": "user_embedding",

0 commit comments

Comments
 (0)