diff --git a/redisearch/client.py b/redisearch/client.py index 35562e8..c576cc5 100644 --- a/redisearch/client.py +++ b/redisearch/client.py @@ -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' @@ -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 diff --git a/test/test.py b/test/test.py index ee1b77b..214344a 100644 --- a/test/test.py +++ b/test/test.py @@ -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__':