Skip to content

fix #56 add support for FT.MGET #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 17, 2020
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
13 changes: 13 additions & 0 deletions redisearch/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ class Client(object):
DICT_ADD_CMD = 'FT.DICTADD'
DICT_DEL_CMD = 'FT.DICTDEL'
DICT_DUMP_CMD = 'FT.DICTDUMP'
GET_CMD = 'FT.GET'
MGET_CMD = 'FT.MGET'


NOOFFSETS = 'NOOFFSETS'
Expand Down Expand Up @@ -301,6 +303,17 @@ def load_document(self, id):

return Document(id=id, **fields)

def get(self, *ids):
"""
Returns the full contents of multiple documents.

### Parameters

- **ids**: the ids of the saved documents.
"""

return self.redis.execute_command('FT.MGET', self.index_name, *ids)

def info(self):
"""
Get info an stats about the the current index, including the number of documents, memory consumption, etc
Expand Down
13 changes: 13 additions & 0 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,19 @@ def testDictOps(self):
# Remove rest of the items before reload
client.dict_del('custom_dict', *res)

def testGet(self):
client = self.getCleanClient('idx')
client.create_index((TextField('f1'), TextField('f2')))

self.assertEqual([None], client.get('doc1'))
self.assertEqual([None, None], client.get('doc2', 'doc1'))

client.add_document('doc1', f1='some valid content dd1', f2='this is sample text ff1')
client.add_document('doc2', f1='some valid content dd2', f2='this is sample text ff2')

self.assertEqual([['f1', 'some valid content dd2', 'f2', 'this is sample text ff2']], client.get('doc2'))
self.assertEqual([['f1', 'some valid content dd1', 'f2', 'this is sample text ff1'], ['f1', 'some valid content dd2', 'f2', 'this is sample text ff2']], client.get('doc1', 'doc2'))


if __name__ == '__main__':

Expand Down