Skip to content

Commit 36a153e

Browse files
maguecAvital-Finechayim
authored
Attributes to fields fix (#163)
* fix the newer version * add a test to make sure we pull the correct information * ensure the datatypes are correct in both redis > 2.2 Co-authored-by: Avital Fine <98389525+Avital-Fine@users.noreply.github.com> Co-authored-by: Chayim <chayim@users.noreply.github.com>
1 parent 9a9429a commit 36a153e

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

redisearch/client.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,8 +586,14 @@ func (i *Client) Info() (*IndexInfo, error) {
586586
switch key {
587587
case "index_options":
588588
indexOptions, _ = redis.Strings(res[ii+1], nil)
589-
case "fields", "attributes":
589+
case "fields":
590590
schemaAttributes, _ = redis.Values(res[ii+1], nil)
591+
case "attributes":
592+
for _, attr := range res[ii+1].([]interface{}) {
593+
l := len(attr.([]interface{}))
594+
schemaAttributes = append(schemaAttributes, attr.([]interface{})[3:l])
595+
596+
}
591597
}
592598
}
593599

redisearch/client_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,3 +1218,28 @@ func TestClient_InfoSchemaFields(t *testing.T) {
12181218
}
12191219
assert.True(t, reflect.DeepEqual(expVectorField, info.Schema.Fields[1]))
12201220
}
1221+
1222+
func TestClient_InfoFieldsTest(t *testing.T) {
1223+
c := createClient("ft-info-fields-test")
1224+
flush(c)
1225+
schema := NewSchema(DefaultOptions).
1226+
AddField(NewTextFieldOptions("text", TextFieldOptions{Sortable: true, PhoneticMatcher: PhoneticDoubleMetaphoneEnglish})).
1227+
AddField(NewGeoField("geo")).
1228+
AddField(NewNumericField("numeric"))
1229+
// In this example we will only index keys started by product:
1230+
indexDefinition := NewIndexDefinition().AddPrefix("ft-info-fields-test:")
1231+
// Add the Index Definition
1232+
err := c.CreateIndexWithIndexDefinition(schema, indexDefinition)
1233+
assert.Nil(t, err)
1234+
1235+
info, err := c.Info()
1236+
assert.Nil(t, err)
1237+
// Check to make sure the fields that we get back match the fields that we created
1238+
assert.Equal(t,
1239+
[]Field(
1240+
[]Field{
1241+
Field{Name: "text", Type: 0, Sortable: false, Options: TextFieldOptions{Weight: 1, Sortable: true, NoStem: false, NoIndex: false, PhoneticMatcher: "", As: ""}},
1242+
Field{Name: "geo", Type: 2, Sortable: false, Options: interface{}(nil)},
1243+
Field{Name: "numeric", Type: 1, Sortable: false, Options: NumericFieldOptions{Sortable: false, NoIndex: false, As: ""}}}),
1244+
info.Schema.Fields)
1245+
}

0 commit comments

Comments
 (0)