MCPcopy
hub / github.com/redis/go-redis / ExampleClient_search_qs

Function ExampleClient_search_qs

doctests/search_quickstart_test.go:154–262  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

152}
153
154func ExampleClient_search_qs() {
155 // STEP_START connect
156 ctx := context.Background()
157
158 rdb := redis.NewClient(&redis.Options{
159 Addr: "localhost:6379",
160 Password: "", // no password docs
161 DB: 0, // use default DB
162 Protocol: 2,
163 })
164 // STEP_END
165
166 // REMOVE_START
167 rdb.FTDropIndex(ctx, "idx:bicycle")
168 // REMOVE_END
169
170 // STEP_START create_index
171 schema := []*redis.FieldSchema{
172 {
173 FieldName: "$.brand",
174 As: "brand",
175 FieldType: redis.SearchFieldTypeText,
176 },
177 {
178 FieldName: "$.model",
179 As: "model",
180 FieldType: redis.SearchFieldTypeText,
181 },
182 {
183 FieldName: "$.description",
184 As: "description",
185 FieldType: redis.SearchFieldTypeText,
186 },
187 }
188
189 _, err := rdb.FTCreate(ctx, "idx:bicycle",
190 &redis.FTCreateOptions{
191 Prefix: []interface{}{"bicycle:"},
192 OnJSON: true,
193 },
194 schema...,
195 ).Result()
196
197 if err != nil {
198 panic(err)
199 }
200 // STEP_END
201
202 // STEP_START add_documents
203 for i, bicycle := range bicycles {
204 _, err := rdb.JSONSet(
205 ctx,
206 fmt.Sprintf("bicycle:%v", i),
207 "$",
208 bicycle,
209 ).Result()
210
211 if err != nil {

Callers

nothing calls this directly

Calls 6

FTDropIndexMethod · 0.65
ResultMethod · 0.65
FTCreateMethod · 0.65
JSONSetMethod · 0.65
FTSearchMethod · 0.65
PrintfMethod · 0.65

Tested by

no test coverage detected