|
20 | 20 |
|
21 | 21 | class RedisSearchTestCase(ModuleTestCase('../module.so')): |
22 | 22 |
|
23 | | - def createIndex(self, client, num_docs = 100): |
| 23 | + def createIndex(self, client, num_docs = 100, definition=None): |
24 | 24 |
|
25 | 25 | assert isinstance(client, Client) |
26 | 26 | try: |
27 | 27 | client.create_index((TextField('play', weight=5.0), |
28 | 28 | TextField('txt'), |
29 | | - NumericField('chapter'))) |
| 29 | + NumericField('chapter')), definition=definition) |
30 | 30 | except redis.ResponseError: |
31 | 31 | client.drop_index() |
32 | | - return self.createIndex(client, num_docs=num_docs) |
| 32 | + return self.createIndex(client, num_docs=num_docs, definition=definition) |
33 | 33 |
|
34 | 34 | chapters = {} |
35 | 35 | bzfp = bz2.BZ2File(WILL_PLAY_TEXT) |
@@ -781,6 +781,46 @@ def testAggregations(self): |
781 | 781 | self.assertEqual(b'RediSearch', res[23]) |
782 | 782 | self.assertEqual(2, len(res[25])) |
783 | 783 |
|
| 784 | + def testIndexDefiniontion(self): |
| 785 | + |
| 786 | + conn = self.redis() |
| 787 | + |
| 788 | + with conn as r: |
| 789 | + r.flushdb() |
| 790 | + client = Client('test', port=conn.port) |
| 791 | + |
| 792 | + definition = IndexDefinition(async=True, prefix=['hset:', 'henry'], |
| 793 | + filter='@f1==32', language='English', language_field='play', |
| 794 | + score_field='chapter', score=0.5, payload_field='txt' ) |
| 795 | + |
| 796 | + self.assertEqual(['ON','HASH','ASYNC','PREFIX',2,'hset:','henry', |
| 797 | + 'FILTER','@f1==32','LANGUAGE_FIELD','play','LANGUAGE','English', |
| 798 | + 'SCORE_FIELD','chapter','SCORE',0.5,'PAYLOAD_FIELD','txt'], |
| 799 | + definition.args) |
| 800 | + |
| 801 | + self.createIndex(client, num_docs=500, definition=definition) |
| 802 | + |
| 803 | + |
| 804 | + def testCreateClientDefiniontion(self): |
| 805 | + |
| 806 | + conn = self.redis() |
| 807 | + |
| 808 | + with conn as r: |
| 809 | + r.flushdb() |
| 810 | + client = Client('test', port=conn.port) |
| 811 | + |
| 812 | + definition = IndexDefinition(prefix=['hset:', 'henry']) |
| 813 | + self.createIndex(client, num_docs=500, definition=definition) |
| 814 | + |
| 815 | + info = client.info() |
| 816 | + self.assertEqual(494, int(info['num_docs'])) |
| 817 | + |
| 818 | + r.hset('hset:1', 'f1', 'v1'); |
| 819 | + |
| 820 | + info = client.info() |
| 821 | + self.assertEqual(495, int(info['num_docs'])) |
| 822 | + |
| 823 | + |
784 | 824 | if __name__ == '__main__': |
785 | 825 |
|
786 | 826 | unittest.main() |
0 commit comments