Skip to content

Commit 628ab6c

Browse files
committed
deal with long name searches
1 parent 542a1e1 commit 628ab6c

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

Diff for: indexer.go

+16-4
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,15 @@ const indexSettings = `
375375
"lowercase",
376376
"prefix_filter"
377377
]
378-
}
378+
},
379+
"name_search": {
380+
"type": "custom",
381+
"tokenizer": "standard",
382+
"filter": [
383+
"lowercase",
384+
"max_length"
385+
]
386+
}
379387
},
380388
"tokenizer": {
381389
"location_tokenizer": {
@@ -399,9 +407,13 @@ const indexSettings = `
399407
"filter": {
400408
"prefix_filter": {
401409
"type": "edge_ngram",
402-
"min_gram": 1,
410+
"min_gram": 2,
403411
"max_gram": 8
404-
}
412+
},
413+
"max_length":{
414+
"type": "truncate",
415+
"length": 8
416+
}
405417
}
406418
}
407419
},
@@ -501,7 +513,7 @@ const indexSettings = `
501513
"name": {
502514
"type": "text",
503515
"analyzer": "prefix",
504-
"search_analyzer": "standard",
516+
"search_analyzer": "name_search",
505517
"fields": {
506518
"keyword": {
507519
"type": "keyword",

Diff for: indexer_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@ func TestIndexing(t *testing.T) {
7575
assertQuery(t, client, physicalName, elastic.NewMatchQuery("name", "JO"), []int64{5, 7})
7676
assertQuery(t, client, physicalName, elastic.NewTermQuery("name.keyword", "JOHN DOE"), []int64{5})
7777

78+
// can search on both first and last name
79+
boolQuery := elastic.NewBoolQuery().Must(
80+
elastic.NewMatchQuery("name", "john"),
81+
elastic.NewMatchQuery("name", "doe"))
82+
assertQuery(t, client, physicalName, boolQuery, []int64{5})
83+
84+
// can search on a long name
85+
assertQuery(t, client, physicalName, elastic.NewMatchQuery("name", "Ajodinabiff"), []int64{6})
86+
7887
assertQuery(t, client, physicalName, elastic.NewMatchQuery("language", "eng"), []int64{1})
7988

8089
// test contact, not indexed

Diff for: testdb.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ INSERT INTO contacts_contact(id, is_active, created_by_id, created_on, modified_
9898
'{ "05bca1cd-e322-4837-9595-86d0d85e5adb": {"text": "9", "decimal": 9 }, "e0eac267-463a-4c00-9732-cab62df07b16": { "text": "2018-04-06T18:37:59+00:00", "datetime": "2018-04-06T18:37:59+00:00"}}'),
9999
(5, TRUE, -1, '2015-03-27 07:39:28.955051+00', -1, '2015-03-27 07:39:28.955051+00', 1, FALSE, 'John Doe', FALSE, NULL, '51762bba-01a2-4c4e-b5cd-b182d0405cd4', FALSE,
100100
'{ "e0eac267-463a-4c00-9732-cab62df07b16": { "text": "2030-04-06T18:37:59+00:00", "datetime": "2030-04-06T18:37:59+00:00"}}'),
101-
(6, TRUE, -1, '2015-10-30 19:42:27.001837+00', -1, '2015-10-30 19:42:27.001837+00', 2, FALSE, 'Ajodi Dane', FALSE, NULL, '3e814add-e614-41f7-8b5d-a07f670a698f', FALSE,
101+
(6, TRUE, -1, '2015-10-30 19:42:27.001837+00', -1, '2015-10-30 19:42:27.001837+00', 2, FALSE, 'Ajodinabiff Dane', FALSE, NULL, '3e814add-e614-41f7-8b5d-a07f670a698f', FALSE,
102102
'{ "22d11697-edba-4186-b084-793e3b876379": { "text": "USA > Washington", "state": "USA > Washington"} }'),
103103
(7, TRUE, -1, '2017-11-10 21:11:59.890662+00', -1, '2017-11-10 21:11:59.890662+00', 2, FALSE, 'Joanne Stone', FALSE, NULL, '7051dff0-0a27-49d7-af1f-4494239139e6', FALSE,
104104
'{ "22d11697-edba-4186-b084-793e3b876379": { "text": "USA > Colorado", "state": "USA > Colorado"} }'),

0 commit comments

Comments
 (0)