@@ -390,6 +390,22 @@ def test_search(self):
390
390
self .assertEqual (self .sb .search ('Index' , highlight = True )['hits' ], 3 )
391
391
self .assertEqual ([result .highlighted ['text' ][0 ] for result in self .sb .search ('Index' , highlight = True )['results' ]], ['<em>Indexed</em>!\n 1' , '<em>Indexed</em>!\n 2' , '<em>Indexed</em>!\n 3' ])
392
392
393
+ # shortened highlighting options
394
+ highlight_dict = {'simple.pre' :'<i>' , 'simple.post' : '</i>' }
395
+ self .assertEqual (self .sb .search ('' , highlight = highlight_dict ), {'hits' : 0 , 'results' : []})
396
+ self .assertEqual (self .sb .search ('Index' , highlight = highlight_dict )['hits' ], 3 )
397
+ self .assertEqual ([result .highlighted ['text' ][0 ] for result in self .sb .search ('Index' , highlight = highlight_dict )['results' ]],
398
+ ['<i>Indexed</i>!\n 1' , '<i>Indexed</i>!\n 2' , '<i>Indexed</i>!\n 3' ])
399
+
400
+ # full-form highlighting options
401
+ highlight_dict = {'hl.simple.pre' :'<i>' , 'hl.simple.post' : '</i>' }
402
+ self .assertEqual ([result .highlighted ['text' ][0 ] for result in self .sb .search ('Index' , highlight = highlight_dict )['results' ]],
403
+ ['<i>Indexed</i>!\n 1' , '<i>Indexed</i>!\n 2' , '<i>Indexed</i>!\n 3' ])
404
+
405
+ self .assertEqual (self .sb .search ('Indx' )['hits' ], 0 )
406
+ self .assertEqual (self .sb .search ('indax' )['spelling_suggestion' ], 'index' )
407
+ self .assertEqual (self .sb .search ('Indx' , spelling_query = 'indexy' )['spelling_suggestion' ], 'index' )
408
+
393
409
self .assertEqual (self .sb .search ('' , facets = {'name' : {}}), {'hits' : 0 , 'results' : []})
394
410
results = self .sb .search ('Index' , facets = {'name' : {}})
395
411
self .assertEqual (results ['hits' ], 3 )
0 commit comments