Skip to content

Commit 5131403

Browse files
authored
enable FT.TAGVALS command (#94)
* add the ability to return the results of FT.TAGVALS command * match names in docstring * review suggestions
1 parent 86cbec8 commit 5131403

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

redisearch/client.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ class Client(object):
174174
GET_CMD = 'FT.GET'
175175
MGET_CMD = 'FT.MGET'
176176
CONFIG_CMD = 'FT.CONFIG'
177+
TAGVALS_CMD = 'FT.TAGVALS'
177178

178179
NOOFFSETS = 'NOOFFSETS'
179180
NOFIELDS = 'NOFIELDS'
@@ -648,3 +649,16 @@ def config_get(self, option):
648649
for kvs in raw:
649650
res[kvs[0]] = kvs[1]
650651
return res
652+
653+
def tagvals(self, tagfield):
654+
"""
655+
Return a list of all possible tag values
656+
657+
### Parameters
658+
659+
- **tagfield**: Tag field name
660+
"""
661+
662+
cmd = self.redis.execute_command(self.TAGVALS_CMD, self.index_name, tagfield)
663+
return cmd
664+

test/test.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,12 @@ def testTags(self):
596596
client.redis.flushdb()
597597

598598
client.create_index((TextField('txt'), TagField('tags')))
599+
600+
tags = 'foo,foo bar,hello;world'
601+
tags2 = 'soba,ramen'
599602

600-
client.add_document('doc1', txt = 'fooz barz', tags = 'foo,foo bar,hello;world')
603+
client.add_document('doc1', txt = 'fooz barz', tags = tags)
604+
client.add_document('doc2', txt = 'noodles', tags = tags2)
601605

602606
for i in r.retry_with_rdb_reload():
603607
waitForIndex(r, 'idx')
@@ -617,6 +621,9 @@ def testTags(self):
617621
res = client.search(q)
618622
self.assertEqual(1, res.total)
619623

624+
q2 = client.tagvals('tags')
625+
self.assertEqual(tags.split(',') + tags2.split(','), q2)
626+
620627
def testTextFieldSortableNostem(self):
621628
conn = self.redis()
622629

0 commit comments

Comments
 (0)