Skip to content

Commit

Permalink
Attributes to fields fix (#163)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: Chayim <[email protected]>
  • Loading branch information
3 people authored May 3, 2022
1 parent 9a9429a commit 36a153e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
8 changes: 7 additions & 1 deletion redisearch/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,8 +586,14 @@ func (i *Client) Info() (*IndexInfo, error) {
switch key {
case "index_options":
indexOptions, _ = redis.Strings(res[ii+1], nil)
case "fields", "attributes":
case "fields":
schemaAttributes, _ = redis.Values(res[ii+1], nil)
case "attributes":
for _, attr := range res[ii+1].([]interface{}) {
l := len(attr.([]interface{}))
schemaAttributes = append(schemaAttributes, attr.([]interface{})[3:l])

}
}
}

Expand Down
25 changes: 25 additions & 0 deletions redisearch/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1218,3 +1218,28 @@ func TestClient_InfoSchemaFields(t *testing.T) {
}
assert.True(t, reflect.DeepEqual(expVectorField, info.Schema.Fields[1]))
}

func TestClient_InfoFieldsTest(t *testing.T) {
c := createClient("ft-info-fields-test")
flush(c)
schema := NewSchema(DefaultOptions).
AddField(NewTextFieldOptions("text", TextFieldOptions{Sortable: true, PhoneticMatcher: PhoneticDoubleMetaphoneEnglish})).
AddField(NewGeoField("geo")).
AddField(NewNumericField("numeric"))
// In this example we will only index keys started by product:
indexDefinition := NewIndexDefinition().AddPrefix("ft-info-fields-test:")
// Add the Index Definition
err := c.CreateIndexWithIndexDefinition(schema, indexDefinition)
assert.Nil(t, err)

info, err := c.Info()
assert.Nil(t, err)
// Check to make sure the fields that we get back match the fields that we created
assert.Equal(t,
[]Field(
[]Field{
Field{Name: "text", Type: 0, Sortable: false, Options: TextFieldOptions{Weight: 1, Sortable: true, NoStem: false, NoIndex: false, PhoneticMatcher: "", As: ""}},
Field{Name: "geo", Type: 2, Sortable: false, Options: interface{}(nil)},
Field{Name: "numeric", Type: 1, Sortable: false, Options: NumericFieldOptions{Sortable: false, NoIndex: false, As: ""}}}),
info.Schema.Fields)
}

0 comments on commit 36a153e

Please sign in to comment.