-
-
Notifications
You must be signed in to change notification settings - Fork 76
/
settings.js
338 lines (326 loc) · 11 KB
/
settings.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
var Mergeable = require('mergeable');
var peliasConfig = require('pelias-config');
var punctuation = require('./punctuation');
var street_suffix = require('./street_suffix');
var moduleDir = require('path').dirname("../");
function generate(){
var config = peliasConfig.generate().export();
// Default settings
var settings = {
"analysis": {
"tokenizer": {
"peliasNameTokenizer": {
"type": "pattern",
"pattern": "[\\s,/\\\\]+"
},
"peliasStreetTokenizer": {
"type": "pattern",
"pattern": "[,/\\\\]+"
}
},
"analyzer": {
"peliasAdmin": {
"type": "custom",
"tokenizer": "peliasNameTokenizer",
"char_filter" : ["punctuation", "nfkc_normalizer"],
"filter": [
"lowercase",
"icu_folding",
"trim",
"word_delimiter",
"notnull"
]
},
"peliasIndexOneEdgeGram" : {
"type": "custom",
"tokenizer" : "peliasNameTokenizer",
"char_filter" : ["punctuation", "nfkc_normalizer"],
"filter": [
"lowercase",
"icu_folding",
"trim",
"full_token_address_suffix_expansion",
"ampersand",
"remove_ordinals",
"removeAllZeroNumericPrefix",
"surround_single_characters_with_word_markers",
"house_number_word_delimiter",
"remove_single_characters",
"surround_house_numbers_with_word_markers",
"peliasOneEdgeGramFilter",
"eliminate_tokens_starting_with_word_marker",
"remove_encapsulating_word_markers",
"unique",
"notnull"
]
},
"peliasIndexTwoEdgeGram" : {
"type": "custom",
"tokenizer" : "peliasNameTokenizer",
"char_filter" : ["punctuation", "nfkc_normalizer"],
"filter": [
"lowercase",
"icu_folding",
"trim",
"full_token_address_suffix_expansion",
"ampersand",
"remove_ordinals",
"removeAllZeroNumericPrefix",
"prefixZeroToSingleDigitNumbers",
"peliasTwoEdgeGramFilter",
"removeAllZeroNumericPrefix",
"direction_synonym_contraction_keep_original",
"unique",
"notnull"
]
},
"peliasQueryPartialToken" : {
"type": "custom",
"tokenizer" : "peliasNameTokenizer",
"char_filter" : ["punctuation", "nfkc_normalizer"],
"filter": [
"lowercase",
"icu_folding",
"trim",
"partial_token_address_suffix_expansion",
"ampersand",
"remove_ordinals",
"removeAllZeroNumericPrefix",
"unique",
"notnull"
]
},
"peliasQueryFullToken" : {
"type": "custom",
"tokenizer" : "peliasNameTokenizer",
"char_filter" : ["punctuation", "nfkc_normalizer"],
"filter": [
"lowercase",
"icu_folding",
"trim",
"remove_ordinals",
"full_token_address_suffix_expansion",
"ampersand",
"removeAllZeroNumericPrefix",
"unique",
"notnull"
]
},
"peliasPhrase": {
"type": "custom",
"tokenizer":"peliasNameTokenizer",
"char_filter" : ["punctuation", "nfkc_normalizer"],
"filter": [
"lowercase",
"icu_folding",
"trim",
"ampersand",
"street_synonym",
"direction_synonym",
"unique",
"notnull"
]
},
"peliasZip": {
"type": "custom",
"tokenizer":"keyword",
"char_filter" : ["alphanumeric"],
"filter": [
"lowercase",
"trim"
]
},
"peliasHousenumber": {
"type": "custom",
"tokenizer":"standard",
"char_filter" : ["numeric"]
},
"peliasStreet": {
"type": "custom",
"tokenizer":"peliasStreetTokenizer",
"char_filter" : ["punctuation", "nfkc_normalizer"],
"filter": [
"lowercase",
"icu_folding",
"remove_duplicate_spaces",
].concat( street_suffix.synonyms.map( function( synonym ){
return "keyword_street_suffix_" + synonym.split(' ')[0];
})).concat( street_suffix.direction_synonyms.map( function( synonym ){
return "keyword_compass_" + synonym.split(' ')[0];
})).concat([
"remove_ordinals",
"trim"
])
}
},
"filter" : {
"ampersand" :{
"type": "synonym",
"synonyms": [ "and => &" ]
},
"notnull" :{
"type" : "length",
"min" : 1
},
"peliasOneEdgeGramFilter": {
"type" : "edgeNGram",
"min_gram" : 1,
"max_gram" : 18
},
"peliasTwoEdgeGramFilter": {
"type" : "edgeNGram",
"min_gram" : 2,
"max_gram" : 18
},
"prefixZeroToSingleDigitNumbers" :{
"type" : "pattern_replace",
"pattern" : "^([0-9])$",
"replacement" : "0$1"
},
"removeAllZeroNumericPrefix" :{
"type" : "pattern_replace",
"pattern" : "^(0*)",
"replacement" : ""
},
"address_stop": {
"type": "stop",
"stopwords": street_suffix.terms
},
"street_synonym": {
"type": "synonym",
"synonyms": street_suffix.synonyms
},
"partial_token_address_suffix_expansion": {
"type": "synonym",
"synonyms": street_suffix.partial_token_safe_expansions
},
"full_token_address_suffix_expansion": {
"type": "synonym",
"synonyms": street_suffix.full_token_safe_expansions
},
"direction_synonym": {
"type": "synonym",
"synonyms": street_suffix.direction_synonyms
},
"direction_synonym_contraction_keep_original": {
"type": "synonym",
"synonyms": street_suffix.direction_synonyms_keep_original
},
"remove_ordinals" : {
"type" : "pattern_replace",
"pattern": "(?i)((^| )((1)st?|(2)nd?|(3)rd?|([4-9])th?)|(([0-9]*)(1[0-9])th?)|(([0-9]*[02-9])((1)st?|(2)nd?|(3)rd?|([04-9])th?))($| ))",
"replacement": "$2$4$5$6$7$9$10$12$14$15$16$17$18"
},
"remove_duplicate_spaces" : {
"type" : "pattern_replace",
"pattern": " +",
"replacement": " "
},
// START OF COMPLICATED FILTERS TO ANALYZE HOUSE NUMBERS
// @see: https://github.com/pelias/schema/pull/133
// note: we use \x02 (start-of-text) and \x03 (end-of-text) characters to mark word borders
"surround_single_characters_with_word_markers":{
"description": "wraps single characters with markers, needed to protect valid single characters and not those extracted from house numbers (14a creates an 'a' token)",
"type": "pattern_replace",
"pattern": "^(.{1})$",
"replacement": "\x02$1\x03"
},
"house_number_word_delimiter": {
"description": "splits on letter-to-number transition and vice versa, splits 14a -> [14, 14a, a]",
"type": "word_delimiter",
"split_on_numerics": "true",
"preserve_original": "true"
},
"remove_single_characters": {
"description": "removes single characters created from house_number_word_delimiter, removes the letter portion of a house number",
"type": "length",
"min": 2
},
"surround_house_numbers_with_word_markers": {
"description": "surrounds house numbers with markers, needed to protect whole house numbers from elimination step after prefix n-gramming",
"type": "pattern_replace",
"pattern": "^([0-9]+[a-z]?)$",
"replacement": "\x02$1\x03"
},
"eliminate_tokens_starting_with_word_marker": {
"description": "remove tokens starting but not ending with markers, saves whole house numbers wrapped in markers",
"type": "pattern_replace",
"pattern": "^\x02(.*[^\x03])?$",
"replacement": ""
},
"remove_encapsulating_word_markers": {
"description": "extract the stuff between the markers, extract 14 from \x0214\x03 since we're done the prefix n-gramming step",
"type": "pattern_replace",
"pattern": "^\x02(.*)\x03$",
"replacement": "$1"
}
// END OF COMPLICATED FILTERS TO ANALYZE HOUSE NUMBERS
// more generated below
},
"char_filter": {
"punctuation" : {
"type" : "mapping",
"mappings" : punctuation.blacklist.map(function(c){
return c + '=>';
})
},
"alphanumeric" : {
"type" : "pattern_replace",
"pattern": "[^a-zA-Z0-9]",
"replacement": ""
},
"numeric" : {
"type" : "pattern_replace",
"pattern": "[^0-9]",
"replacement": " "
},
"nfkc_normalizer": {
"type": "icu_normalizer",
"name": "nfkc",
"mode": "compose"
}
}
},
"index": {
"number_of_replicas": "0",
"number_of_shards": "1",
// A safe default can be 65% of the number of bounded cores (bounded at 32), with a minimum of 8 (which is the default in Lucene).
"index_concurrency": "10"
}
};
// dynamically create filters which can replace text *inside* a token.
// we are not able to re-use the synonym functionality in elasticsearch
// because it only matches whole tokens, not strings *within* tokens.
// eg. synonyms are capable of ['street'] => ['st'] but not
// ['sesame street'] => ['sesame st']
// street suffix filters (replace text inside tokens)
// based off synonym list
street_suffix.synonyms.forEach( function( synonym ){
var split = synonym.split(' ');
settings.analysis.filter[ "keyword_street_suffix_" + split[0] ] = {
"type": "pattern_replace",
"pattern": " " + split[0],
"replacement": " " + split[2]
}
});
// compass prefix filters (replace text inside tokens)
// based off direction_synonyms list
street_suffix.direction_synonyms.forEach( function( synonym ){
var split = synonym.split(' ');
settings.analysis.filter[ "keyword_compass_" + split[0] ] = {
"type": "pattern_replace",
"pattern": split[0],
"replacement": split[2]
}
});
// Merge settings from pelias/config
if( 'object' == typeof config &&
'object' == typeof config.elasticsearch &&
'object' == typeof config.elasticsearch.settings ){
var defaults = new Mergeable( settings );
defaults.deepMerge( config.elasticsearch.settings );
return defaults.export();
}
return settings;
}
module.exports = generate;