Skip to content

Commit 809e4da

Browse files
Merge pull request #53 from dengliming/f_get_tagvals
Support FT.TAGVALS command
2 parents 910ef02 + 531d81d commit 809e4da

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

redisearch/client.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,3 +521,12 @@ func (i *Client) GetConfig(option string) (map[string]string, error) {
521521
}
522522
return m, nil
523523
}
524+
525+
// Get the distinct tags indexed in a Tag field
526+
func (i *Client) GetTagVals(index string, filedName string) ([]string, error) {
527+
conn := i.pool.Get()
528+
defer conn.Close()
529+
530+
args := redis.Args{index, filedName}
531+
return redis.Strings(conn.Do("FT.TAGVALS", args...))
532+
}

redisearch/client_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,3 +491,29 @@ func TestClient_Config(t *testing.T) {
491491
kvs, _ = c.GetConfig("*")
492492
assert.Equal(t, "100", kvs["TIMEOUT"])
493493
}
494+
495+
func TestClient_GetTagVals(t *testing.T) {
496+
c := createClient("testgettagvals")
497+
498+
// Create a schema
499+
sc := NewSchema(DefaultOptions).
500+
AddField(NewTextField("name")).
501+
AddField(NewTagField("tags"))
502+
503+
c.Drop()
504+
c.CreateIndex(sc)
505+
506+
docs := make([]Document, 1)
507+
doc := NewDocument("doc1", 1.0)
508+
doc.Set("name", "John").
509+
Set("tags", "single, young")
510+
docs[0] = doc
511+
c.Index(docs...)
512+
tags, err := c.GetTagVals("testgettagvals", "tags")
513+
assert.Nil(t, err)
514+
assert.Contains(t, tags, "single")
515+
// negative tests
516+
tags, err = c.GetTagVals("notexit", "tags")
517+
assert.NotNil(t, err)
518+
assert.Nil(t, tags)
519+
}

0 commit comments

Comments
 (0)