Skip to content

Commit 518219a

Browse files
manually parse special attributes that have no associated value
1 parent 7982f7d commit 518219a

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

redisvl/redis/connection.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,25 @@ 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', 'UNF', 'NOSTEM' don't have corresponding values.
102+
# Their presence indicates boolean True
103+
original = attrs.copy()
104+
parsed_attrs = {}
105+
if "NOSTEM" in attrs:
106+
parsed_attrs["no_stem"] = True
107+
attrs.remove("NOSTEM")
108+
for special_attr in ["SORTABLE", "UNF"]:
109+
if special_attr in attrs:
110+
parsed_attrs[special_attr.lower()] = True
111+
attrs.remove(special_attr)
112+
113+
try:
114+
parsed_attrs.update(
115+
{attrs[i].lower(): attrs[i + 1] for i in range(6, len(attrs), 2)}
116+
)
117+
except IndexError as e:
118+
raise IndexError(f"Error parsing index attributes {original}, {str(e)}")
119+
return parsed_attrs
102120

103121
schema_fields = []
104122

tests/integration/test_search_index.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@
66
from redisvl.redis.utils import convert_bytes
77
from redisvl.schema import IndexSchema, StorageType
88

9-
fields = [{"name": "test", "type": "tag"}]
9+
fields = [
10+
{"name": "test", "type": "tag"},
11+
{"name": "test_text", "type": "text"},
12+
{
13+
"name": "test_text_attrs",
14+
"type": "text",
15+
"attrs": {"no_stem": True, "sortable": True},
16+
},
17+
]
1018

1119

1220
@pytest.fixture
@@ -87,7 +95,7 @@ def test_search_index_from_existing_complex(client):
8795
"name": "age",
8896
"type": "numeric",
8997
"path": "$.metadata.age",
90-
"attrs": {"sortable": False},
98+
"attrs": {"sortable": True},
9199
},
92100
{
93101
"name": "user_embedding",

0 commit comments

Comments
 (0)