@@ -12,6 +12,7 @@ import (
12
12
13
13
_ "github.com/lib/pq"
14
14
"github.com/olivere/elastic"
15
+ "github.com/sirupsen/logrus"
15
16
"github.com/stretchr/testify/assert"
16
17
)
17
18
@@ -37,6 +38,8 @@ func setup(t *testing.T) (*sql.DB, *elastic.Client) {
37
38
assert .NoError (t , err )
38
39
}
39
40
41
+ logrus .SetLevel (logrus .DebugLevel )
42
+
40
43
return db , client
41
44
}
42
45
@@ -66,7 +69,10 @@ func TestIndexing(t *testing.T) {
66
69
67
70
time .Sleep (2 * time .Second )
68
71
69
- assertQuery (t , client , physicalName , elastic .NewMatchQuery ("name" , "JOHn" ), []int64 {5 })
72
+ assertQuery (t , client , physicalName , elastic .NewMatchQuery ("name" , "JOHn" ).Analyzer ("standard" ), []int64 {5 })
73
+
74
+ // prefix on name matches both john and joanne, but no ajodi
75
+ assertQuery (t , client , physicalName , elastic .NewMatchQuery ("name" , "JO" ).Analyzer ("standard" ), []int64 {5 , 7 })
70
76
assertQuery (t , client , physicalName , elastic .NewTermQuery ("name.keyword" , "JOHN DOE" ), []int64 {5 })
71
77
72
78
assertQuery (t , client , physicalName , elastic .NewMatchQuery ("language" , "eng" ), []int64 {1 })
@@ -201,10 +207,10 @@ func TestIndexing(t *testing.T) {
201
207
// map our index over
202
208
err = MapIndexAlias (elasticURL , indexName , physicalName )
203
209
assert .NoError (t , err )
204
- time .Sleep (2 * time .Second )
210
+ time .Sleep (5 * time .Second )
205
211
206
212
// try a test query to check it worked
207
- assertQuery (t , client , indexName , elastic .NewMatchQuery ("name" , "john" ), []int64 {5 })
213
+ assertQuery (t , client , indexName , elastic .NewMatchQuery ("name" , "john" ). Analyzer ( "standard" ) , []int64 {5 })
208
214
209
215
// look up our mapping
210
216
physical := FindPhysicalIndexes (elasticURL , indexName )
@@ -223,9 +229,9 @@ func TestIndexing(t *testing.T) {
223
229
err = MapIndexAlias (elasticURL , indexName , newIndex )
224
230
assert .NoError (t , err )
225
231
226
- time .Sleep (2 * time .Second )
232
+ time .Sleep (5 * time .Second )
227
233
228
- assertQuery (t , client , newIndex , elastic .NewMatchQuery ("name" , "john" ), []int64 {5 })
234
+ assertQuery (t , client , newIndex , elastic .NewMatchQuery ("name" , "john" ). Analyzer ( "standard" ) , []int64 {5 })
229
235
230
236
// update our database, removing one contact, updating another
231
237
dbUpdate , err := ioutil .ReadFile ("testdb_update.sql" )
@@ -238,10 +244,10 @@ func TestIndexing(t *testing.T) {
238
244
assert .Equal (t , 1 , added )
239
245
assert .Equal (t , 1 , deleted )
240
246
241
- time .Sleep (2 * time .Second )
247
+ time .Sleep (5 * time .Second )
242
248
243
249
// should only match new john, old john is gone
244
- assertQuery (t , client , indexName , elastic .NewMatchQuery ("name" , "john" ), []int64 {3 })
250
+ assertQuery (t , client , indexName , elastic .NewMatchQuery ("name" , "john" ). Analyzer ( "standard" ) , []int64 {3 })
245
251
246
252
// 3 is no longer in our group
247
253
assertQuery (t , client , indexName , elastic .NewMatchQuery ("groups" , "529bac39-550a-4d6f-817c-1833f3449007" ), []int64 {1 })
0 commit comments