@@ -50,6 +50,18 @@ def get_model(self):
50
50
return MockModel
51
51
52
52
53
+ class ElasticsearchMockSpellingIndex (indexes .SearchIndex , indexes .Indexable ):
54
+ text = indexes .CharField (document = True )
55
+ name = indexes .CharField (model_attr = 'author' , faceted = True )
56
+ pub_date = indexes .DateField (model_attr = 'pub_date' )
57
+
58
+ def get_model (self ):
59
+ return MockModel
60
+
61
+ def prepare_text (self , obj ):
62
+ return obj .foo
63
+
64
+
53
65
class ElasticsearchMaintainTypeMockSearchIndex (indexes .SearchIndex , indexes .Indexable ):
54
66
text = indexes .CharField (document = True , use_template = True )
55
67
month = indexes .CharField (indexed = False )
@@ -906,6 +918,49 @@ def test_result_class(self):
906
918
self .assertTrue (isinstance (sqs [0 ], SearchResult ))
907
919
908
920
921
+ class LiveElasticsearchSpellingTestCase (TestCase ):
922
+ """Used to test actual implementation details of the SearchQuerySet."""
923
+ fixtures = ['bulk_data.json' ]
924
+
925
+ def setUp (self ):
926
+ super (LiveElasticsearchSpellingTestCase , self ).setUp ()
927
+
928
+ # Stow.
929
+ self .old_debug = settings .DEBUG
930
+ settings .DEBUG = True
931
+ self .old_ui = connections ['default' ].get_unified_index ()
932
+ self .ui = UnifiedIndex ()
933
+ self .smmi = ElasticsearchMockSpellingIndex ()
934
+ self .ui .build (indexes = [self .smmi ])
935
+ connections ['default' ]._index = self .ui
936
+
937
+ self .sqs = SearchQuerySet ()
938
+
939
+ # Ugly but not constantly reindexing saves us almost 50% runtime.
940
+ global lssqstc_all_loaded
941
+
942
+ if lssqstc_all_loaded is None :
943
+ lssqstc_all_loaded = True
944
+
945
+ # Wipe it clean.
946
+ clear_elasticsearch_index ()
947
+
948
+ # Force indexing of the content.
949
+ self .smmi .update ()
950
+
951
+ def tearDown (self ):
952
+ # Restore.
953
+ connections ['default' ]._index = self .old_ui
954
+ settings .DEBUG = self .old_debug
955
+ super (LiveElasticsearchSpellingTestCase , self ).tearDown ()
956
+
957
+ def test_spelling (self ):
958
+ self .assertEqual (self .sqs .auto_query ('structurd' ).spelling_suggestion (), 'structured' )
959
+ self .assertEqual (self .sqs .spelling_suggestion ('structurd' ), 'structured' )
960
+ self .assertEqual (self .sqs .auto_query ('srchindex instanc' ).spelling_suggestion (), 'searchindex instance' )
961
+ self .assertEqual (self .sqs .spelling_suggestion ('srchindex instanc' ), 'searchindex instance' )
962
+
963
+
909
964
class LiveElasticsearchMoreLikeThisTestCase (TestCase ):
910
965
fixtures = ['bulk_data.json' ]
911
966
0 commit comments