STEP_END
()
| 15 | // STEP_END |
| 16 | |
| 17 | func ExampleClient_search_json() { |
| 18 | // STEP_START connect |
| 19 | ctx := context.Background() |
| 20 | |
| 21 | rdb := redis.NewClient(&redis.Options{ |
| 22 | Addr: "localhost:6379", |
| 23 | Password: "", // no password docs |
| 24 | DB: 0, // use default DB |
| 25 | Protocol: 2, |
| 26 | }) |
| 27 | // STEP_END |
| 28 | // REMOVE_START |
| 29 | // make sure we are working with fresh database |
| 30 | rdb.FlushDB(ctx) |
| 31 | rdb.Del(ctx, "user:1", "user:2", "user:3") |
| 32 | rdb.FTDropIndex(ctx, "idx:users") |
| 33 | // REMOVE_END |
| 34 | |
| 35 | // STEP_START create_data |
| 36 | user1 := map[string]interface{}{ |
| 37 | "name": "Paul John", |
| 38 | "email": "paul.john@example.com", |
| 39 | "age": 42, |
| 40 | "city": "London", |
| 41 | } |
| 42 | |
| 43 | user2 := map[string]interface{}{ |
| 44 | "name": "Eden Zamir", |
| 45 | "email": "eden.zamir@example.com", |
| 46 | "age": 29, |
| 47 | "city": "Tel Aviv", |
| 48 | } |
| 49 | |
| 50 | user3 := map[string]interface{}{ |
| 51 | "name": "Paul Zamir", |
| 52 | "email": "paul.zamir@example.com", |
| 53 | "age": 35, |
| 54 | "city": "Tel Aviv", |
| 55 | } |
| 56 | // STEP_END |
| 57 | |
| 58 | // STEP_START make_index |
| 59 | _, err := rdb.FTCreate( |
| 60 | ctx, |
| 61 | "idx:users", |
| 62 | // Options: |
| 63 | &redis.FTCreateOptions{ |
| 64 | OnJSON: true, |
| 65 | Prefix: []interface{}{"user:"}, |
| 66 | }, |
| 67 | // Index schema fields: |
| 68 | &redis.FieldSchema{ |
| 69 | FieldName: "$.name", |
| 70 | As: "name", |
| 71 | FieldType: redis.SearchFieldTypeText, |
| 72 | }, |
| 73 | &redis.FieldSchema{ |
| 74 | FieldName: "$.city", |
nothing calls this directly
no test coverage detected