Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions redisearch/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,3 +521,12 @@ func (i *Client) GetConfig(option string) (map[string]string, error) {
}
return m, nil
}

// Get the distinct tags indexed in a Tag field
func (i *Client) GetTagVals(index string, filedName string) ([]string, error) {
conn := i.pool.Get()
defer conn.Close()

args := redis.Args{index, filedName}
return redis.Strings(conn.Do("FT.TAGVALS", args...))
}
26 changes: 26 additions & 0 deletions redisearch/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,3 +491,29 @@ func TestClient_Config(t *testing.T) {
kvs, _ = c.GetConfig("*")
assert.Equal(t, "100", kvs["TIMEOUT"])
}

func TestClient_GetTagVals(t *testing.T) {
c := createClient("testgettagvals")

// Create a schema
sc := NewSchema(DefaultOptions).
AddField(NewTextField("name")).
AddField(NewTagField("tags"))

c.Drop()
c.CreateIndex(sc)

docs := make([]Document, 1)
doc := NewDocument("doc1", 1.0)
doc.Set("name", "John").
Set("tags", "single, young")
docs[0] = doc
c.Index(docs...)
tags, err := c.GetTagVals("testgettagvals", "tags")
assert.Nil(t, err)
assert.Contains(t, tags, "single")
// negative tests
tags, err = c.GetTagVals("notexit", "tags")
assert.NotNil(t, err)
assert.Nil(t, tags)
}