@@ -104,11 +104,12 @@ def setUp(self):
104
104
"equals_headline_index" ,
105
105
{"mappings" : {"dynamic" : False , "fields" : {"headline" : {"type" : "token" }}}},
106
106
)
107
- self .cross = Article .objects .create (headline = "cross" , number = 1 , body = "body" )
107
+ self .article = Article .objects .create (headline = "cross" , number = 1 , body = "body" )
108
+ Article .objects .create (headline = "other thing" , number = 2 , body = "body" )
108
109
109
110
def test_search_equals (self ):
110
111
qs = Article .objects .annotate (score = SearchEquals (path = "headline" , value = "cross" ))
111
- self .wait_for_assertion (lambda : self .assertCountEqual (qs .all (), [self .cross ]))
112
+ self .wait_for_assertion (lambda : self .assertCountEqual (qs .all (), [self .article ]))
112
113
113
114
def tearDown (self ):
114
115
self ._tear_down (Article )
@@ -139,6 +140,7 @@ def setUp(self):
139
140
self .article = Article .objects .create (
140
141
headline = "crossing and something" , number = 2 , body = "river"
141
142
)
143
+ Article .objects .create (headline = "Some random text" , number = 3 , body = "river" )
142
144
143
145
def tearDown (self ):
144
146
self ._tear_down (Article )
@@ -170,7 +172,7 @@ def setUp(self):
170
172
"in_headline_index" ,
171
173
{"mappings" : {"dynamic" : False , "fields" : {"headline" : {"type" : "token" }}}},
172
174
)
173
- self .cross = Article .objects .create (headline = "cross" , number = 1 , body = "a" )
175
+ self .article = Article .objects .create (headline = "cross" , number = 1 , body = "a" )
174
176
Article .objects .create (headline = "road" , number = 2 , body = "b" )
175
177
176
178
def tearDown (self ):
@@ -179,7 +181,7 @@ def tearDown(self):
179
181
180
182
def test_search_in (self ):
181
183
qs = Article .objects .annotate (score = SearchIn (path = "headline" , value = ["cross" , "river" ]))
182
- self .wait_for_assertion (lambda : self .assertCountEqual (qs .all (), [self .cross ]))
184
+ self .wait_for_assertion (lambda : self .assertCountEqual (qs .all (), [self .article ]))
183
185
184
186
185
187
class SearchPhraseTest (SearchUtilsMixin ):
@@ -189,17 +191,18 @@ def setUp(self):
189
191
"phrase_body_index" ,
190
192
{"mappings" : {"dynamic" : False , "fields" : {"body" : {"type" : "string" }}}},
191
193
)
192
- self .irrelevant = Article .objects .create (
194
+ self .article = Article .objects .create (
193
195
headline = "irrelevant" , number = 1 , body = "the quick brown fox"
194
196
)
197
+ Article .objects .create (headline = "cheetah" , number = 2 , body = "fastest animal" )
195
198
196
199
def tearDown (self ):
197
200
self ._tear_down (Article )
198
201
super ().tearDown ()
199
202
200
203
def test_search_phrase (self ):
201
204
qs = Article .objects .annotate (score = SearchPhrase (path = "body" , query = "quick brown" ))
202
- self .wait_for_assertion (lambda : self .assertCountEqual (qs .all (), [self .irrelevant ]))
205
+ self .wait_for_assertion (lambda : self .assertCountEqual (qs .all (), [self .article ]))
203
206
204
207
205
208
class SearchRangeTest (SearchUtilsMixin ):
@@ -234,6 +237,7 @@ def setUp(self):
234
237
},
235
238
)
236
239
self .article = Article .objects .create (headline = "hello world" , number = 1 , body = "abc" )
240
+ Article .objects .create (headline = "hola mundo" , number = 2 , body = "abc" )
237
241
238
242
def tearDown (self ):
239
243
self ._tear_down (Article )
@@ -256,6 +260,7 @@ def setUp(self):
256
260
self .article = Article .objects .create (
257
261
headline = "ignored" , number = 1 , body = "The lazy dog sleeps"
258
262
)
263
+ Article .objects .create (headline = "ignored" , number = 2 , body = "The sleepy bear" )
259
264
260
265
def tearDown (self ):
261
266
self ._tear_down (Article )
@@ -287,6 +292,7 @@ def setUp(self):
287
292
},
288
293
)
289
294
self .article = Article .objects .create (headline = "dark-knight" , number = 1 , body = "" )
295
+ Article .objects .create (headline = "batman" , number = 2 , body = "" )
290
296
291
297
def tearDown (self ):
292
298
self ._tear_down (Article )
@@ -312,6 +318,9 @@ def setUp(self):
312
318
self .article = Article .objects .create (
313
319
headline = "any" , number = 1 , body = "" , location = {"type" : "Point" , "coordinates" : [40 , 5 ]}
314
320
)
321
+ Article .objects .create (
322
+ headline = "any" , number = 2 , body = "" , location = {"type" : "Point" , "coordinates" : [400 , 50 ]}
323
+ )
315
324
316
325
def tearDown (self ):
317
326
self ._tear_down (Article )
@@ -338,6 +347,9 @@ def setUp(self):
338
347
self .article = Article .objects .create (
339
348
headline = "geo" , number = 2 , body = "" , location = {"type" : "Point" , "coordinates" : [40 , 5 ]}
340
349
)
350
+ Article .objects .create (
351
+ headline = "geo2" , number = 3 , body = "" , location = {"type" : "Point" , "coordinates" : [- 40 , - 5 ]}
352
+ )
341
353
342
354
def tearDown (self ):
343
355
self ._tear_down (Article )
0 commit comments