Skip to content

Commit 01a21d3

Browse files
committed
store both a keyword and tokenized version of locations (without any path)
1 parent a974fcf commit 01a21d3

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

Diff for: indexer.go

+14-10
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,14 @@ const indexSettings = `
330330
"lowercase",
331331
"word_delimiter"
332332
]
333-
}
333+
},
334+
"locations_keyword": {
335+
"tokenizer": "location_tokenizer",
336+
"filter": [
337+
"lowercase",
338+
"trim"
339+
]
340+
}
334341
},
335342
"tokenizer": {
336343
"location_tokenizer": {
@@ -378,9 +385,8 @@ const indexSettings = `
378385
"analyzer": "locations",
379386
"fields": {
380387
"keyword": {
381-
"type": "keyword",
382-
"ignore_above": 128,
383-
"normalizer": "lowercase"
388+
"type": "text",
389+
"analyzer": "locations_keyword"
384390
}
385391
}
386392
},
@@ -389,9 +395,8 @@ const indexSettings = `
389395
"analyzer": "locations",
390396
"fields": {
391397
"keyword": {
392-
"type": "keyword",
393-
"ignore_above": 128,
394-
"normalizer": "lowercase"
398+
"type": "text",
399+
"analyzer": "locations_keyword"
395400
}
396401
}
397402
},
@@ -400,9 +405,8 @@ const indexSettings = `
400405
"analyzer": "locations",
401406
"fields": {
402407
"keyword": {
403-
"type": "keyword",
404-
"ignore_above": 128,
405-
"normalizer": "lowercase"
408+
"type": "text",
409+
"analyzer": "locations_keyword"
406410
}
407411
}
408412
}

Diff for: indexer_test.go

+14-3
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,15 @@ func TestIndexing(t *testing.T) {
137137

138138
query = elastic.NewNestedQuery("fields", elastic.NewBoolQuery().Must(
139139
elastic.NewMatchQuery("fields.field", "22d11697-edba-4186-b084-793e3b876379"),
140-
elastic.NewMatchPhraseQuery("fields.state.keyword", "usa > washington")))
140+
elastic.NewMatchQuery("fields.state.keyword", " washington")))
141141
assertQuery(t, client, physicalName, query, []int64{6})
142142

143143
// doesn't include country
144+
query = elastic.NewNestedQuery("fields", elastic.NewBoolQuery().Must(
145+
elastic.NewMatchQuery("fields.field", "22d11697-edba-4186-b084-793e3b876379"),
146+
elastic.NewMatchQuery("fields.state.keyword", "usa")))
147+
assertQuery(t, client, physicalName, query, []int64{})
148+
144149
query = elastic.NewNestedQuery("fields", elastic.NewBoolQuery().Must(
145150
elastic.NewMatchQuery("fields.field", "22d11697-edba-4186-b084-793e3b876379"),
146151
elastic.NewMatchPhraseQuery("fields.state", "usa")))
@@ -160,7 +165,7 @@ func TestIndexing(t *testing.T) {
160165

161166
query = elastic.NewNestedQuery("fields", elastic.NewBoolQuery().Must(
162167
elastic.NewMatchQuery("fields.field", "fcab2439-861c-4832-aa54-0c97f38f24ab"),
163-
elastic.NewMatchPhraseQuery("fields.district.keyword", "usa > washington > king county")))
168+
elastic.NewMatchQuery("fields.district.keyword", "King County")))
164169
assertQuery(t, client, physicalName, query, []int64{8})
165170

166171
// ward query
@@ -171,9 +176,15 @@ func TestIndexing(t *testing.T) {
171176

172177
query = elastic.NewNestedQuery("fields", elastic.NewBoolQuery().Must(
173178
elastic.NewMatchQuery("fields.field", "a551ade4-e5a0-4d83-b185-53b515ad2f2a"),
174-
elastic.NewMatchPhraseQuery("fields.ward.keyword", "usa > washington > king county > central district")))
179+
elastic.NewMatchQuery("fields.ward.keyword", "central district")))
175180
assertQuery(t, client, physicalName, query, []int64{9})
176181

182+
// no substring though on keyword
183+
query = elastic.NewNestedQuery("fields", elastic.NewBoolQuery().Must(
184+
elastic.NewMatchQuery("fields.field", "a551ade4-e5a0-4d83-b185-53b515ad2f2a"),
185+
elastic.NewMatchQuery("fields.ward.keyword", "district")))
186+
assertQuery(t, client, physicalName, query, []int64{})
187+
177188
// group query
178189
assertQuery(t, client, physicalName, elastic.NewMatchQuery("groups", "4ea0f313-2f62-4e57-bdf0-232b5191dd57"), []int64{1})
179190
assertQuery(t, client, physicalName, elastic.NewMatchQuery("groups", "529bac39-550a-4d6f-817c-1833f3449007"), []int64{1, 3})

0 commit comments

Comments
 (0)