@@ -300,6 +300,28 @@ def testReplace(self):
300300 self .assertEqual (1 , res .total )
301301 self .assertEqual ('doc1' , res .docs [0 ].id )
302302
303+ def testExpire (self ):
304+ client = self .getCleanClient ('idx' )
305+ client .create_index ((TextField ('txt' , sortable = True ),), temporary = 4 )
306+
307+ redis_client = redis .client .Redis ()
308+ ttl = redis_client .execute_command ('ft.debug' , 'TTL' , 'idx' )
309+ self .assertTrue (ttl > 2 )
310+ while ttl > 2 :
311+ ttl = redis_client .execute_command ('ft.debug' , 'TTL' , 'idx' )
312+ time .sleep (0.01 )
313+
314+ # add document - should reset the ttl
315+ client .add_document ('doc' , txt = 'foo bar' , text = 'this is a simple test' )
316+ ttl = redis_client .execute_command ('ft.debug' , 'TTL' , 'idx' )
317+ self .assertTrue (ttl > 2 )
318+ try :
319+ while True :
320+ ttl = redis_client .execute_command ('ft.debug' , 'TTL' , 'idx' )
321+ time .sleep (0.5 )
322+ except redis .exceptions .ResponseError :
323+ self .assertEqual (ttl , 0 )
324+
303325 def testStopwords (self ):
304326 # Creating a client with a given index name
305327 client = self .getCleanClient ('idx' )
@@ -314,6 +336,18 @@ def testStopwords(self):
314336 self .assertEqual (0 , res1 .total )
315337 self .assertEqual (1 , res2 .total )
316338
339+ def testSkipInitialScan (self ):
340+ client = self .getCleanClient ('idx' )
341+ client .redis .hset ("doc1" , "foo" , "bar" )
342+ q = Query ('@foo:bar' )
343+
344+ client1 = self .getCleanClient ('idx1' )
345+ client1 .create_index ((TextField ('foo' ),))
346+ self .assertEqual (1 , client1 .search (q ).total )
347+ client2 = self .getCleanClient ('idx2' )
348+ client2 .create_index ((TextField ('foo' ),), skip_initial_scan = True )
349+ self .assertEqual (0 , client2 .search (q ).total )
350+
317351 def testFilters (self ):
318352 conn = self .redis ()
319353
@@ -602,6 +636,25 @@ def testSummarize(self):
602636 self .assertEqual ('ACT I SCENE I. London. The palace. Enter <b>KING</b> <b>HENRY</b>, LORD JOHN OF LANCASTER, the EARL of WESTMORELAND, SIR... ' ,
603637 doc .txt )
604638
639+ def testSummarizeDisabled (self ):
640+ # test NOOFFSETS
641+ client = self .getCleanClient ('idx' )
642+ client .create_index ((TextField ('txt' ),), no_term_offsets = True )
643+ client .add_document ('doc1' , txt = 'foo bar' )
644+ with self .assertRaises (Exception ) as context :
645+ client .search (Query ('foo' ).summarize (fields = ['txt' ]))
646+ self .assertEqual ('Cannot use highlight/summarize because NOOFSETS was specified at index level' ,
647+ str (context .exception ))
648+
649+ # test NOHL
650+ client = self .getCleanClient ('idx' )
651+ client .create_index ((TextField ('txt' ),), no_highlight = True )
652+ client .add_document ('doc1' , txt = 'foo bar' )
653+ with self .assertRaises (Exception ) as context :
654+ client .search (Query ('foo' ).summarize (fields = ['txt' ]))
655+ self .assertEqual ('Cannot use highlight/summarize because NOOFSETS was specified at index level' ,
656+ str (context .exception ))
657+
605658 def testAlias (self ):
606659 conn = self .redis ()
607660 with conn as r :
@@ -735,6 +788,35 @@ def testTextFieldSortableNostem(self):
735788 self .assertIn ('SORTABLE' , response ['attributes' ][0 ])
736789 self .assertIn ('NOSTEM' , response ['attributes' ][0 ])
737790
791+ def testMaxTextFields (self ):
792+ conn = self .redis ()
793+
794+ with conn as r :
795+ # Creating a client
796+ client = Client ('idx1' , port = conn .port )
797+ client .redis .flushdb ()
798+
799+ # Creating the index definition
800+ client .create_index ((TextField ('f0' ),))
801+ # Fill the index with fields
802+ for x in range (1 , 32 ):
803+ client .alter_schema_add ((TextField ('f{}' .format (x )),))
804+ # OK for now.
805+
806+ # Should be too many indexes
807+ with self .assertRaises (redis .ResponseError ):
808+ client .alter_schema_add ((TextField ('f{}' .format (x )),))
809+
810+ # Creating new client
811+ client = Client ('idx2' , port = conn .port )
812+ client .redis .flushdb ()
813+
814+ # Creating the index definition
815+ client .create_index ((TextField ('f0' ),), max_text_fields = True )
816+ # Fill the index with fields
817+ for x in range (1 , 50 ):
818+ client .alter_schema_add ((TextField ('f{}' .format (x )),))
819+
738820 def testAlterSchemaAdd (self ):
739821 conn = self .redis ()
740822
0 commit comments