Skip to content

Commit 56d6025

Browse files
authored
Merge pull request #34 from nyaruka/location_punctuation
Fix creating of location keyword fields when values have punctuation
2 parents 3730d34 + db54150 commit 56d6025

File tree

3 files changed

+41
-23
lines changed

3 files changed

+41
-23
lines changed

Diff for: indexer.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -399,15 +399,15 @@ SELECT org_id, id, modified_on, is_active, row_to_json(t) FROM (
399399
select case
400400
when value ? 'ward'
401401
then jsonb_build_object(
402-
'ward_keyword', trim(substring(value ->> 'ward' from '(?!.* > )([\w ]+)'))
402+
'ward_keyword', trim(substring(value ->> 'ward' from '(?!.* > )([^>]+)'))
403403
)
404404
else '{}' :: jsonb
405405
end || district_value.value as value
406406
FROM (
407407
select case
408408
when value ? 'district'
409409
then jsonb_build_object(
410-
'district_keyword', trim(substring(value ->> 'district' from '(?!.* > )([\w ]+)'))
410+
'district_keyword', trim(substring(value ->> 'district' from '(?!.* > )([^>]+)'))
411411
)
412412
else '{}' :: jsonb
413413
end || state_value.value as value
@@ -416,7 +416,7 @@ SELECT org_id, id, modified_on, is_active, row_to_json(t) FROM (
416416
select case
417417
when value ? 'state'
418418
then jsonb_build_object(
419-
'state_keyword', trim(substring(value ->> 'state' from '(?!.* > )([\w ]+)'))
419+
'state_keyword', trim(substring(value ->> 'state' from '(?!.* > )([^>]+)'))
420420
)
421421
else '{}' :: jsonb
422422
end ||

Diff for: indexer_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,12 @@ func TestIndexing(t *testing.T) {
202202
// phrase matches all
203203
query = elastic.NewNestedQuery("fields", elastic.NewBoolQuery().Must(
204204
elastic.NewMatchQuery("fields.field", "fcab2439-861c-4832-aa54-0c97f38f24ab"),
205-
elastic.NewMatchPhraseQuery("fields.district", "King Côunty")))
205+
elastic.NewMatchPhraseQuery("fields.district", "King-Côunty")))
206206
assertQuery(t, client, physicalName, query, []int64{7})
207207

208208
query = elastic.NewNestedQuery("fields", elastic.NewBoolQuery().Must(
209209
elastic.NewMatchQuery("fields.field", "fcab2439-861c-4832-aa54-0c97f38f24ab"),
210-
elastic.NewMatchQuery("fields.district_keyword", "King Côunty")))
210+
elastic.NewMatchQuery("fields.district_keyword", "King-Côunty")))
211211
assertQuery(t, client, physicalName, query, []int64{7})
212212

213213
// ward query

Diff for: testdb.sql

+36-18
Original file line numberDiff line numberDiff line change
@@ -88,24 +88,42 @@ ALTER SEQUENCE contacts_contactgroup_contacts_id_seq OWNED BY contacts_contactgr
8888
-- a551ade4-e5a0-4d83-b185-53b515ad2f2a - home_ward (ward)
8989

9090
INSERT INTO contacts_contact(id, is_active, created_by_id, created_on, modified_by_id, modified_on, last_seen_on, org_id, status, name, language, uuid, fields) VALUES
91-
(1, TRUE, -1, '2017-11-10 21:11:59.890662+00', -1, '2017-11-10 21:11:59.890662+00', '2020-08-04 21:11', 1, 'A', NULL, 'eng', 'c7a2dd87-a80e-420b-8431-ca48d422e924',
92-
'{ "17103bb1-1b48-4b70-92f7-1f6b73bd3488": {"text": "the rock"}}'),
93-
(2, TRUE, -1, '2015-03-26 10:07:14.054521+00', -1, '2015-03-26 10:07:14.054521+00', '2020-08-03 13:11', 1, 'S', NULL, NULL, '7a6606c7-ff41-4203-aa98-454a10d37209',
94-
'{ "05bca1cd-e322-4837-9595-86d0d85e5adb": {"text": "11", "number": 11 }}'),
95-
(3, TRUE, -1, '2015-03-26 13:04:58.699648+00', -1, '2015-03-26 13:04:58.699648+00', '2018-05-04 21:11', 1, 'B', NULL, NULL, '29b45297-15ad-4061-a7d4-e0b33d121541',
96-
'{ "05bca1cd-e322-4837-9595-86d0d85e5adb": {"text": "9", "number": 9 }, "e0eac267-463a-4c00-9732-cab62df07b16": { "text": "2018-04-06T18:37:59+00:00", "datetime": "2018-04-06T18:37:59+00:00"}}'),
97-
(4, TRUE, -1, '2015-03-27 07:39:28.955051+00', -1, '2015-03-27 07:39:28.955051+00', '2015-12-31 23:59', 1, 'A', 'John Doe', NULL, '51762bba-01a2-4c4e-b5cd-b182d0405cd4',
98-
'{ "e0eac267-463a-4c00-9732-cab62df07b16": { "text": "2030-04-06T18:37:59+00:00", "datetime": "2030-04-06T18:37:59+00:00"}}'),
99-
(5, TRUE, -1, '2015-10-30 19:42:27.001837+00', -1, '2015-10-30 19:42:27.001837+00', '2020-08-04 21:11', 2, 'A', 'Ajodinabiff Dane', NULL, '3e814add-e614-41f7-8b5d-a07f670a698f',
100-
'{ "22d11697-edba-4186-b084-793e3b876379": { "text": "USA > Washington", "state": "USA > Washington"} }'),
101-
(6, TRUE, -1, '2017-11-10 21:11:59.890662+00', -1, '2017-11-10 21:11:59.890662+00', '2020-08-04 21:00', 2, 'A', 'Joanne Stone', NULL, '7051dff0-0a27-49d7-af1f-4494239139e6',
102-
'{ "22d11697-edba-4186-b084-793e3b876379": { "text": "USA > Colorado", "state": "USA > Colorado"} }'),
103-
(7, TRUE, -1, '2015-03-27 13:39:43.995812+00', -1, '2015-03-27 13:39:43.995812+00', NULL, 2, 'A', NULL, NULL, 'b46f6e18-95b4-4984-9926-dded047f4eb3',
104-
'{ "fcab2439-861c-4832-aa54-0c97f38f24ab": { "text": "USA > Washington > King Côunty", "district": "USA > Washington > King Côunty"} }'),
105-
(8, TRUE, -1, '2017-11-10 21:11:59.890662+00', -1, '2017-11-10 21:11:59.890662+00', NULL, 2, 'A', NULL, NULL, '9195c8b7-6138-4d84-ac56-5192cc3d8ceb',
106-
'{ "a551ade4-e5a0-4d83-b185-53b515ad2f2a": { "text": "USA > Washington > King Côunty > Central District", "ward": "USA > Washington > King Côunty > Central District"} }'),
107-
(9, TRUE, -1, '2016-08-22 14:20:05.690311+00', -1, '2016-08-22 14:20:05.690311+00', NULL, 2, 'A', NULL, NULL, '2b8bd28d-43e0-4c34-a4bb-0f10b11fdb8a',
108-
'{ "fcab2439-861c-4832-aa54-0c97f38f24ab": { "text": "USA > Colorado > King", "district": "USA > Colorado > King"} }');
91+
(
92+
1, TRUE, -1, '2017-11-10 21:11:59.890662+00', -1, '2017-11-10 21:11:59.890662+00', '2020-08-04 21:11', 1, 'A', NULL, 'eng', 'c7a2dd87-a80e-420b-8431-ca48d422e924',
93+
'{ "17103bb1-1b48-4b70-92f7-1f6b73bd3488": {"text": "the rock"}}'
94+
),
95+
(
96+
2, TRUE, -1, '2015-03-26 10:07:14.054521+00', -1, '2015-03-26 10:07:14.054521+00', '2020-08-03 13:11', 1, 'S', NULL, NULL, '7a6606c7-ff41-4203-aa98-454a10d37209',
97+
'{ "05bca1cd-e322-4837-9595-86d0d85e5adb": {"text": "11", "number": 11 }}'
98+
),
99+
(
100+
3, TRUE, -1, '2015-03-26 13:04:58.699648+00', -1, '2015-03-26 13:04:58.699648+00', '2018-05-04 21:11', 1, 'B', NULL, NULL, '29b45297-15ad-4061-a7d4-e0b33d121541',
101+
'{ "05bca1cd-e322-4837-9595-86d0d85e5adb": {"text": "9", "number": 9 }, "e0eac267-463a-4c00-9732-cab62df07b16": { "text": "2018-04-06T18:37:59+00:00", "datetime": "2018-04-06T18:37:59+00:00"}}'
102+
),
103+
(
104+
4, TRUE, -1, '2015-03-27 07:39:28.955051+00', -1, '2015-03-27 07:39:28.955051+00', '2015-12-31 23:59', 1, 'A', 'John Doe', NULL, '51762bba-01a2-4c4e-b5cd-b182d0405cd4',
105+
'{ "e0eac267-463a-4c00-9732-cab62df07b16": { "text": "2030-04-06T18:37:59+00:00", "datetime": "2030-04-06T18:37:59+00:00"}}'
106+
),
107+
(
108+
5, TRUE, -1, '2015-10-30 19:42:27.001837+00', -1, '2015-10-30 19:42:27.001837+00', '2020-08-04 21:11', 2, 'A', 'Ajodinabiff Dane', NULL, '3e814add-e614-41f7-8b5d-a07f670a698f',
109+
'{ "22d11697-edba-4186-b084-793e3b876379": { "text": "USA > Washington", "state": "USA > Washington"} }'
110+
),
111+
(
112+
6, TRUE, -1, '2017-11-10 21:11:59.890662+00', -1, '2017-11-10 21:11:59.890662+00', '2020-08-04 21:00', 2, 'A', 'Joanne Stone', NULL, '7051dff0-0a27-49d7-af1f-4494239139e6',
113+
'{ "22d11697-edba-4186-b084-793e3b876379": { "text": "USA > Colorado", "state": "USA > Colorado"} }'
114+
),
115+
(
116+
7, TRUE, -1, '2015-03-27 13:39:43.995812+00', -1, '2015-03-27 13:39:43.995812+00', NULL, 2, 'A', NULL, NULL, 'b46f6e18-95b4-4984-9926-dded047f4eb3',
117+
'{ "fcab2439-861c-4832-aa54-0c97f38f24ab": { "text": "USA > Washington > King-Côunty", "district": "USA > Washington > King-Côunty"} }'
118+
),
119+
(
120+
8, TRUE, -1, '2017-11-10 21:11:59.890662+00', -1, '2017-11-10 21:11:59.890662+00', NULL, 2, 'A', NULL, NULL, '9195c8b7-6138-4d84-ac56-5192cc3d8ceb',
121+
'{ "a551ade4-e5a0-4d83-b185-53b515ad2f2a": { "text": "USA > Washington > King-Côunty > Central District", "ward": "USA > Washington > King-Côunty > Central District"} }'
122+
),
123+
(
124+
9, TRUE, -1, '2016-08-22 14:20:05.690311+00', -1, '2016-08-22 14:20:05.690311+00', NULL, 2, 'A', NULL, NULL, '2b8bd28d-43e0-4c34-a4bb-0f10b11fdb8a',
125+
'{ "fcab2439-861c-4832-aa54-0c97f38f24ab": { "text": "USA > Colorado > King", "district": "USA > Colorado > King"} }'
126+
);
109127

110128
INSERT INTO contacts_contacturn(id, contact_id, scheme, org_id, priority, path, display, identity) VALUES
111129
(1, 1, 'tel', 1, 50, '+12067791111', NULL, 'tel:+12067791111'),

0 commit comments

Comments
 (0)