Skip to content

Commit 0c24240

Browse files
DOC-5107 added hash examples for index/query intro page (#3609)
* DOC-5107 added hash examples for index/query intro page * DOC-5107 restored old index_definition import
1 parent 950a462 commit 0c24240

9 files changed

+61
-10
lines changed

Diff for: doctests/home_json.py

+53-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import redis.commands.search.aggregation as aggregations
1111
import redis.commands.search.reducers as reducers
1212
from redis.commands.search.field import TextField, NumericField, TagField
13-
from redis.commands.search.indexDefinition import IndexDefinition, IndexType
13+
from redis.commands.search.index_definition import IndexDefinition, IndexType
1414
from redis.commands.search.query import Query
1515
import redis.exceptions
1616
# STEP_END
@@ -25,7 +25,12 @@
2525
except redis.exceptions.ResponseError:
2626
pass
2727

28-
r.delete("user:1", "user:2", "user:3")
28+
try:
29+
r.ft("hash-idx:users").dropindex(True)
30+
except redis.exceptions.ResponseError:
31+
pass
32+
33+
r.delete("user:1", "user:2", "user:3", "huser:1", "huser:2", "huser:3")
2934
# REMOVE_END
3035
# STEP_START create_data
3136
user1 = {
@@ -134,4 +139,50 @@
134139
)
135140
# REMOVE_END
136141

142+
# STEP_START make_hash_index
143+
hashSchema = (
144+
TextField("name"),
145+
TagField("city"),
146+
NumericField("age")
147+
)
148+
149+
hashIndexCreated = r.ft("hash-idx:users").create_index(
150+
hashSchema,
151+
definition=IndexDefinition(
152+
prefix=["huser:"], index_type=IndexType.HASH
153+
)
154+
)
155+
# STEP_END
156+
# REMOVE_START
157+
assert hashIndexCreated
158+
# REMOVE_END
159+
160+
# STEP_START add_hash_data
161+
huser1Set = r.hset("huser:1", mapping=user1)
162+
huser2Set = r.hset("huser:2", mapping=user2)
163+
huser3Set = r.hset("huser:3", mapping=user3)
164+
# STEP_END
165+
# REMOVE_START
166+
assert huser1Set
167+
assert huser2Set
168+
assert huser3Set
169+
# REMOVE_END
170+
171+
# STEP_START query1_hash
172+
findPaulHashResult = r.ft("hash-idx:users").search(
173+
Query("Paul @age:[30 40]")
174+
)
175+
176+
print(findPaulHashResult)
177+
# >>> Result{1 total, docs: [Document {'id': 'huser:3',
178+
# >>> 'payload': None, 'name': 'Paul Zamir', ...
179+
# STEP_END
180+
# REMOVE_START
181+
assert str(findPaulHashResult) == (
182+
"Result{1 total, docs: [Document " +
183+
"{'id': 'huser:3', 'payload': None, 'name': 'Paul Zamir', " +
184+
"'email': '[email protected]', 'age': '35', 'city': 'Tel Aviv'}]}"
185+
)
186+
# REMOVE_END
187+
137188
r.close()

Diff for: doctests/query_agg.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from redis.commands.search import Search
77
from redis.commands.search.aggregation import AggregateRequest
88
from redis.commands.search.field import NumericField, TagField
9-
from redis.commands.search.indexDefinition import IndexDefinition, IndexType
9+
from redis.commands.search.index_definition import IndexDefinition, IndexType
1010
import redis.commands.search.reducers as reducers
1111

1212
r = redis.Redis(decode_responses=True)

Diff for: doctests/query_combined.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import warnings
77
from redis.commands.json.path import Path
88
from redis.commands.search.field import NumericField, TagField, TextField, VectorField
9-
from redis.commands.search.indexDefinition import IndexDefinition, IndexType
9+
from redis.commands.search.index_definition import IndexDefinition, IndexType
1010
from redis.commands.search.query import Query
1111
from sentence_transformers import SentenceTransformer
1212

Diff for: doctests/query_em.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import redis
55
from redis.commands.json.path import Path
66
from redis.commands.search.field import TextField, NumericField, TagField
7-
from redis.commands.search.indexDefinition import IndexDefinition, IndexType
7+
from redis.commands.search.index_definition import IndexDefinition, IndexType
88
from redis.commands.search.query import NumericFilter, Query
99

1010
r = redis.Redis(decode_responses=True)

Diff for: doctests/query_ft.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import redis
66
from redis.commands.json.path import Path
77
from redis.commands.search.field import TextField, NumericField, TagField
8-
from redis.commands.search.indexDefinition import IndexDefinition, IndexType
8+
from redis.commands.search.index_definition import IndexDefinition, IndexType
99
from redis.commands.search.query import NumericFilter, Query
1010

1111
r = redis.Redis(decode_responses=True)

Diff for: doctests/query_geo.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import redis
66
from redis.commands.json.path import Path
77
from redis.commands.search.field import GeoField, GeoShapeField
8-
from redis.commands.search.indexDefinition import IndexDefinition, IndexType
8+
from redis.commands.search.index_definition import IndexDefinition, IndexType
99
from redis.commands.search.query import Query
1010

1111
r = redis.Redis(decode_responses=True)

Diff for: doctests/query_range.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import redis
66
from redis.commands.json.path import Path
77
from redis.commands.search.field import TextField, NumericField, TagField
8-
from redis.commands.search.indexDefinition import IndexDefinition, IndexType
8+
from redis.commands.search.index_definition import IndexDefinition, IndexType
99
from redis.commands.search.query import NumericFilter, Query
1010

1111
r = redis.Redis(decode_responses=True)

Diff for: doctests/search_quickstart.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import redis.commands.search.reducers as reducers
1111
from redis.commands.json.path import Path
1212
from redis.commands.search.field import NumericField, TagField, TextField
13-
from redis.commands.search.indexDefinition import IndexDefinition, IndexType
13+
from redis.commands.search.index_definition import IndexDefinition, IndexType
1414
from redis.commands.search.query import Query
1515

1616
# HIDE_END

Diff for: doctests/search_vss.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
TextField,
2121
VectorField,
2222
)
23-
from redis.commands.search.indexDefinition import IndexDefinition, IndexType
23+
from redis.commands.search.index_definition import IndexDefinition, IndexType
2424
from redis.commands.search.query import Query
2525
from sentence_transformers import SentenceTransformer
2626

0 commit comments

Comments
 (0)