-
-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathsettings.js
More file actions
703 lines (644 loc) · 25.7 KB
/
Copy pathsettings.js
File metadata and controls
703 lines (644 loc) · 25.7 KB
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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
const path = require('path'),
settings = require('../settings'),
fs = require('fs'),
config = require('pelias-config').generate();
module.exports.tests = {};
module.exports.tests.interface = function(test, common) {
test('valid interface', function(t) {
t.equal(typeof settings, 'function', 'settings is a function');
t.end();
});
};
module.exports.tests.configValidation = function(test, common) {
test('configValidation throwing error should rethrow', function(t) {
t.throws(function() {
const proxyquire = require('proxyquire').noCallThru();
proxyquire('../settings', {
'./configValidation': {
validate: () => {
throw Error('config is not valid');
}
}
})();
}, /config is not valid/);
t.end();
});
};
module.exports.tests.compile = function(test, common) {
test('valid settings file', function(t) {
var s = settings();
t.equal(typeof s, 'object', 'settings generated');
t.equal(Object.keys(s).length>0, true, 'settings has body');
t.end();
});
};
// analysis should always be set
module.exports.tests.analysis = function(test, common) {
test('has analysis settings', function(t) {
var s = settings();
t.equal(typeof s.analysis, 'object', 'analysis specified');
t.end();
});
};
function mayBeAmpersandMapper() {
if (config.featureFlags?.icuTokenizer) {
return ['ampersand_mapper'];
}
return [];
}
function mayBeAmpersandReplacer() {
if (config.featureFlags?.icuTokenizer) {
return ['ampersand_replacer'];
}
return [];
}
// -- analyzers --
module.exports.tests.peliasAdminAnalyzer = function(test, common) {
test('has pelias admin analyzer', function(t) {
var s = settings();
t.equal(typeof s.analysis.analyzer.peliasAdmin, 'object', 'there is a pelias admin analyzer');
var analyzer = s.analysis.analyzer.peliasAdmin;
t.equal(analyzer.type, 'custom', 'custom analyzer');
t.equal(typeof analyzer.tokenizer, 'string', 'tokenizer specified');
t.deepEqual(analyzer.char_filter, [...mayBeAmpersandMapper(), 'punctuation', 'nfkc_normalizer'], 'character filters specified');
t.true(Array.isArray(analyzer.filter), 'filters specified');
t.end();
});
test('peliasAdmin token filters', function (t) {
var analyzer = settings().analysis.analyzer.peliasAdmin;
t.deepEqual(analyzer.filter, [...mayBeAmpersandReplacer(),
"lowercase",
"trim",
"synonyms/custom_admin/multiword",
"admin_synonyms_multiplexer",
"icu_folding",
"word_delimiter",
"unique_only_same_position",
"notnull",
"flatten_graph"
]);
t.end();
});
};
module.exports.tests.peliasIndexOneEdgeGramAnalyzer = function(test, common) {
test('has peliasIndexOneEdgeGram analyzer', function(t) {
var s = settings();
t.equal(typeof s.analysis.analyzer.peliasIndexOneEdgeGram, 'object', 'there is a peliasIndexOneEdgeGram analyzer');
var analyzer = s.analysis.analyzer.peliasIndexOneEdgeGram;
t.equal(analyzer.type, 'custom', 'custom analyzer');
t.equal(typeof analyzer.tokenizer, 'string', 'tokenizer specified');
t.deepEqual(analyzer.char_filter, [...mayBeAmpersandMapper(), "punctuation","nfkc_normalizer"], 'character filters specified');
t.true(Array.isArray(analyzer.filter), 'filters specified');
t.end();
});
test('peliasIndexOneEdgeGram token filters', function(t) {
var analyzer = settings().analysis.analyzer.peliasIndexOneEdgeGram;
t.deepEqual( analyzer.filter, [
...mayBeAmpersandReplacer(),
"lowercase",
"trim",
"synonyms/custom_name/multiword",
"synonyms/custom_street/multiword",
"synonyms/custom_admin/multiword",
"name_synonyms_multiplexer",
"icu_folding",
"remove_ordinals",
"peliasOneEdgeGramFilter",
"unique_only_same_position",
"notnull",
"flatten_graph"
]);
t.end();
});
};
module.exports.tests.peliasQueryAnalyzer = function (test, common) {
test('has peliasQuery analyzer', function (t) {
var s = settings();
t.equal(typeof s.analysis.analyzer.peliasQuery, 'object', 'there is a peliasQuery analyzer');
var analyzer = s.analysis.analyzer.peliasQuery;
t.equal(analyzer.type, 'custom', 'custom analyzer');
t.equal(typeof analyzer.tokenizer, 'string', 'tokenizer specified');
t.deepEqual(analyzer.char_filter, [...mayBeAmpersandMapper(), 'punctuation', 'nfkc_normalizer'], 'character filters specified');
t.true(Array.isArray(analyzer.filter), 'filters specified');
t.end();
});
test('peliasQuery token filters', function (t) {
var analyzer = settings().analysis.analyzer.peliasQuery;
t.deepEqual(analyzer.filter, [
...mayBeAmpersandReplacer(),
'lowercase',
'trim',
'icu_folding',
'remove_ordinals',
'unique_only_same_position',
'notnull'
]);
t.end();
});
};
module.exports.tests.peliasPhraseAnalyzer = function(test, common) {
test('has peliasPhrase analyzer', function(t) {
var s = settings();
t.equal(typeof s.analysis.analyzer.peliasPhrase, 'object', 'there is a peliasPhrase analyzer');
var analyzer = s.analysis.analyzer.peliasPhrase;
t.equal(analyzer.type, 'custom', 'custom analyzer');
t.equal(typeof analyzer.tokenizer, 'string', 'tokenizer specified');
t.deepEqual(analyzer.char_filter, [...mayBeAmpersandMapper(), "punctuation", "nfkc_normalizer"], 'character filters specified');
t.true(Array.isArray(analyzer.filter), 'filters specified');
t.end();
});
test('peliasPhrase token filters', function(t) {
var analyzer = settings().analysis.analyzer.peliasPhrase;
t.deepEqual( analyzer.filter, [
...mayBeAmpersandReplacer(),
"lowercase",
"trim",
"remove_duplicate_spaces",
"synonyms/custom_name/multiword",
"synonyms/custom_street/multiword",
"synonyms/custom_admin/multiword",
"name_synonyms_multiplexer",
"icu_folding",
"remove_ordinals",
"unique_only_same_position",
"notnull",
"flatten_graph"
]);
t.end();
});
};
module.exports.tests.peliasZipAnalyzer = function(test, common) {
test('has peliasZip analyzer', function(t) {
var s = settings();
t.equal(typeof s.analysis.analyzer.peliasZip, 'object', 'there is a peliasZip analyzer');
var analyzer = s.analysis.analyzer.peliasZip;
t.equal(analyzer.type, 'custom', 'custom analyzer');
t.equal(typeof analyzer.tokenizer, 'string', 'tokenizer specified');
t.deepEqual(analyzer.char_filter, ['alphanumeric', 'nfkc_normalizer'], 'alphanumeric filter specified');
t.true(Array.isArray(analyzer.filter), 'filters specified');
t.end();
});
test('peliasZip token filters', function(t) {
var analyzer = settings().analysis.analyzer.peliasZip;
t.deepEqual( analyzer.filter, [
"lowercase",
"trim",
"icu_folding",
"unique_only_same_position",
"notnull"
]);
t.end();
});
};
module.exports.tests.peliasUnitAnalyzer = function(test, common) {
test('has peliasUnit analyzer', function(t) {
var s = settings();
t.equal(typeof s.analysis.analyzer.peliasUnit, 'object', 'there is a peliasUnit analyzer');
var analyzer = s.analysis.analyzer.peliasUnit;
t.equal(analyzer.type, 'custom', 'custom analyzer');
t.equal(typeof analyzer.tokenizer, 'string', 'tokenizer specified');
t.deepEqual(analyzer.char_filter, ['alphanumeric', 'nfkc_normalizer'], 'alphanumeric filter specified');
t.true(Array.isArray(analyzer.filter), 'filters specified');
t.end();
});
test('peliasUnit token filters', function(t) {
var analyzer = settings().analysis.analyzer.peliasUnit;
t.deepEqual( analyzer.filter, [
"lowercase",
"trim",
"icu_folding",
"unique_only_same_position",
"notnull"
]);
t.end();
});
};
module.exports.tests.peliasHousenumberAnalyzer = function(test, common) {
test('has peliasHousenumber analyzer', function(t) {
var s = settings();
t.equal(typeof s.analysis.analyzer.peliasHousenumber, 'object', 'there is a peliasHousenumber analyzer');
var analyzer = s.analysis.analyzer.peliasHousenumber;
t.equal(analyzer.type, 'custom', 'custom analyzer');
t.equal(typeof analyzer.tokenizer, 'string', 'tokenizer specified');
t.deepEqual(analyzer.char_filter, ["numeric"], 'numeric filter specified');
t.false(Array.isArray(analyzer.filter), 'no filters specified');
t.end();
});
};
module.exports.tests.peliasStreetAnalyzer = function(test, common) {
test('has peliasStreet analyzer', function(t) {
var s = settings();
t.equal(typeof s.analysis.analyzer.peliasStreet, 'object', 'there is a peliasStreet analyzer');
var analyzer = s.analysis.analyzer.peliasStreet;
t.equal(analyzer.type, 'custom', 'custom analyzer');
t.equal(typeof analyzer.tokenizer, 'string', 'tokenizer specified');
t.deepEqual(analyzer.char_filter, [...mayBeAmpersandMapper(), 'punctuation', 'nfkc_normalizer'], 'character filters specified');
t.true(Array.isArray(analyzer.filter), 'filters specified');
t.end();
});
test('peliasStreet token filters', function(t) {
var analyzer = settings().analysis.analyzer.peliasStreet;
t.deepEqual( analyzer.filter, [...mayBeAmpersandReplacer(),
"lowercase",
"trim",
"remove_duplicate_spaces",
"synonyms/custom_street/multiword",
"street_synonyms_multiplexer",
"icu_folding",
"remove_ordinals",
"trim",
"unique_only_same_position",
"notnull",
"flatten_graph"
]);
t.end();
});
};
module.exports.tests.peliasIndexCountryAbbreviation = function (test, common) {
test('has peliasIndexCountryAbbreviation analyzer', function (t) {
var s = settings();
t.equal(typeof s.analysis.analyzer.peliasIndexCountryAbbreviation, 'object', 'there is a peliasIndexCountryAbbreviation analyzer');
var analyzer = s.analysis.analyzer.peliasIndexCountryAbbreviation;
t.equal(analyzer.type, 'custom', 'custom analyzer');
t.equal(typeof analyzer.tokenizer, 'string', 'tokenizer specified');
t.deepEqual(analyzer.char_filter, [...mayBeAmpersandMapper(), 'punctuation', 'nfkc_normalizer'], 'character filters specified');
t.true(Array.isArray(analyzer.filter), 'filters specified');
t.end();
});
test('peliasIndexCountryAbbreviation token filters', function (t) {
var analyzer = settings().analysis.analyzer.peliasIndexCountryAbbreviation;
t.deepEqual(analyzer.filter, [...mayBeAmpersandReplacer(),
"lowercase",
"trim",
"icu_folding",
"country_abbreviation_synonyms_multiplexer",
"unique_only_same_position",
"notnull",
"flatten_graph"
]);
t.end();
});
};
module.exports.tests.peliasIndexCountryAbbreviationOneEdgeGramAnalyzer = function (test, common) {
test('has peliasIndexCountryAbbreviationOneEdgeGram analyzer', function (t) {
var s = settings();
t.equal(typeof s.analysis.analyzer.peliasIndexCountryAbbreviationOneEdgeGram, 'object', 'there is a peliasIndexCountryAbbreviationOneEdgeGram analyzer');
var analyzer = s.analysis.analyzer.peliasIndexCountryAbbreviationOneEdgeGram;
t.equal(analyzer.type, 'custom', 'custom analyzer');
t.equal(typeof analyzer.tokenizer, 'string', 'tokenizer specified');
t.deepEqual(analyzer.char_filter, [...mayBeAmpersandMapper(), "punctuation", "nfkc_normalizer"], 'character filters specified');
t.true(Array.isArray(analyzer.filter), 'filters specified');
t.end();
});
test('peliasIndexCountryAbbreviationOneEdgeGram token filters', function (t) {
var analyzer = settings().analysis.analyzer.peliasIndexCountryAbbreviationOneEdgeGram;
t.deepEqual(analyzer.filter, [
...mayBeAmpersandReplacer(),
"lowercase",
"trim",
"icu_folding",
"country_abbreviation_synonyms_multiplexer",
"peliasOneEdgeGramFilter",
"unique_only_same_position",
"notnull",
"flatten_graph"
]);
t.end();
});
};
// -- token filters --
// this multiplexer filter provides all the synonyms used by the peliasAdmin analyzer
// note: the multiplexer ensures than we do not virally generate synonyms of synonyms.
module.exports.tests.adminSynonymsMultiplexerFilter = function (test, common) {
test('has admin_synonyms_multiplexer filter', function (t) {
var s = settings();
t.equal(typeof s.analysis.filter.admin_synonyms_multiplexer, 'object', 'there is a admin_synonyms_multiplexer filter');
var filter = s.analysis.filter.admin_synonyms_multiplexer;
t.equal(filter.type, 'multiplexer');
t.deepEqual(filter.filters, [
'synonyms/custom_admin',
'synonyms/personal_titles',
'synonyms/place_names'
]);
t.end();
});
};
// this multiplexer filter provides all the synonyms for country codes.
module.exports.tests.countryAbbreviationSynonymsMultiplexerFilter = function (test, common) {
test('has country_abbreviation_synonyms_multiplexer filter', function (t) {
var s = settings();
t.equal(typeof s.analysis.filter.country_abbreviation_synonyms_multiplexer, 'object', 'there is a country_abbreviation_synonyms_multiplexer filter');
var filter = s.analysis.filter.country_abbreviation_synonyms_multiplexer;
t.equal(filter.type, 'multiplexer');
t.deepEqual(filter.filters, [
'synonyms/country_codes'
]);
t.end();
});
};
// this multiplexer filter provides all the synonyms used by the peliasPhrase and peliasIndexOneEdgeGram analyzers
// note: the multiplexer ensures than we do not virally generate synonyms of synonyms.
module.exports.tests.nameSynonymsMultiplexerFilter = function (test, common) {
test('has name_synonyms_multiplexer filter', function (t) {
var s = settings();
t.equal(typeof s.analysis.filter.name_synonyms_multiplexer, 'object', 'there is a name_synonyms_multiplexer filter');
var filter = s.analysis.filter.name_synonyms_multiplexer;
t.equal(filter.type, 'multiplexer');
t.deepEqual(filter.filters, [
'synonyms/custom_name',
'synonyms/custom_street',
'synonyms/custom_admin',
'synonyms/personal_titles',
'synonyms/place_names',
'synonyms/streets',
'synonyms/directionals',
'synonyms/punctuation',
'synonyms/british_american_english'
]);
t.end();
});
};
// this multiplexer filter provides all the synonyms used by the peliasStreet analyzer
// note: the multiplexer ensures than we do not virally generate synonyms of synonyms.
module.exports.tests.streetSynonymsMultiplexerFilter = function (test, common) {
test('has street_synonyms_multiplexer filter', function (t) {
var s = settings();
t.equal(typeof s.analysis.filter.street_synonyms_multiplexer, 'object', 'there is a street_synonyms_multiplexer filter');
var filter = s.analysis.filter.street_synonyms_multiplexer;
t.equal(filter.type, 'multiplexer');
t.deepEqual(filter.filters, [
'synonyms/custom_street',
'synonyms/personal_titles',
'synonyms/streets',
'synonyms/directionals',
'synonyms/british_american_english'
]);
t.end();
});
};
// cycle through all analyzers and ensure the corrsponding token filters are globally defined
module.exports.tests.allTokenFiltersPresent = function(test, common) {
var ES_INBUILT_FILTERS = [
'lowercase', 'icu_folding', 'trim', 'word_delimiter', 'unique', 'flatten_graph'
];
test('all token filters present', function(t) {
var s = settings();
for( var analyzerName in s.analysis.analyzer ){
var analyzer = s.analysis.analyzer[analyzerName];
if( Array.isArray( analyzer.filter ) ){
analyzer.filter.forEach( function( tokenFilterName ){
var filterExists = (
s.analysis.filter.hasOwnProperty( tokenFilterName ) ||
ES_INBUILT_FILTERS.includes( tokenFilterName )
);
t.true( filterExists, 'token filter exists: ' + tokenFilterName );
});
}
}
t.end();
});
};
// cycle through all analyzers and ensure the mandatory token filters are defined on each
module.exports.tests.mandatoryTokenFiltersPresent = function (test, common) {
var MANDATORY_FILTERS = [
'lowercase', 'icu_folding', 'trim', 'unique_only_same_position', 'notnull'
];
test('mandatory filters present', function (t) {
var s = settings();
for (var analyzerName in s.analysis.analyzer) {
var analyzer = s.analysis.analyzer[analyzerName];
if (Array.isArray(analyzer.filter)) {
MANDATORY_FILTERS.forEach(function (filterName) {
t.true(
analyzer.filter.includes(filterName),
`mandatory token filter ${filterName} not defined on ${analyzerName}`
);
});
}
}
t.end();
});
};
// cycle through all analyzers and ensure the corrsponding character filters are defined
module.exports.tests.allCharacterFiltersPresent = function(test, common) {
var ES_INBUILT_FILTERS = [];
test('all character filters present', function(t) {
var s = settings();
for( var analyzerName in s.analysis.analyzer ){
var analyzer = s.analysis.analyzer[analyzerName];
if( Array.isArray( analyzer.char_filter ) ){
analyzer.char_filter.forEach( function( charFilterName ){
var filterExists = s.analysis.char_filter.hasOwnProperty( charFilterName );
if( !filterExists && -1 < ES_INBUILT_FILTERS.indexOf( charFilterName ) ){
filterExists = true;
}
t.true( filterExists, 'missing character filter: ' + charFilterName );
});
}
}
t.end();
});
};
// -- filters --
// note: pattern/replace should not have surrounding whitespace
// we convert and->& rather than &->and to save memory/disk
module.exports.tests.punctuationFilter = function(test, common) {
test('has punctuation filter', function(t) {
var s = settings();
t.equal(typeof s.analysis.filter['synonyms/punctuation'], 'object', 'there is a punctuation filter');
var filter = s.analysis.filter['synonyms/punctuation'];
t.equal(filter.type, 'synonym');
t.deepEqual(filter.synonyms, [
"&,and",
"&,und"
]);
t.end();
});
};
// this filter simply removes empty tokens which can occur when other
// filters do weird things, so just to be sure, we explicitly get rid of them
module.exports.tests.notnullFilter = function(test, common) {
test('has notnull filter', function(t) {
var s = settings();
t.equal(typeof s.analysis.filter.notnull, 'object', 'there is a notnull filter');
var filter = s.analysis.filter.notnull;
t.equal(filter.type, 'length');
t.equal(filter.min, 1);
t.end();
});
};
// this filter creates edgeNGrams with the minimum size of 1
module.exports.tests.peliasOneEdgeGramFilter = function(test, common) {
test('has peliasIndexOneEdgeGram filter', function(t) {
var s = settings();
t.equal(typeof s.analysis.filter.peliasOneEdgeGramFilter, 'object', 'there is a peliasIndexOneEdgeGram filter');
var filter = s.analysis.filter.peliasOneEdgeGramFilter;
t.equal(filter.type, 'edge_ngram');
t.equal(filter.min_gram, 1);
t.equal(filter.max_gram, 24);
t.end();
});
};
// this filter provides synonyms for street suffixes
// eg. road=>rd
module.exports.tests.streetSynonymFilter = function(test, common) {
test('has synonyms/streets filter', function(t) {
var s = settings();
t.equal(typeof s.analysis.filter['synonyms/streets'], 'object', 'there is a synonyms/streets filter');
var filter = s.analysis.filter['synonyms/streets'];
t.equal(filter.type, 'synonym');
t.true(Array.isArray(filter.synonyms));
t.equal(filter.synonyms.length, 809);
t.end();
});
};
// this filter stems common directional terms
// eg. north=>n and south=>s
module.exports.tests.directionalSynonymFilter = function(test, common) {
test('has directionals filter', function(t) {
var s = settings();
t.equal(typeof s.analysis.filter['synonyms/directionals'], 'object', 'there is a synonyms/directionals filter');
var filter = s.analysis.filter['synonyms/directionals'];
t.equal(filter.type, 'synonym');
t.true(Array.isArray(filter.synonyms));
t.equal(filter.synonyms.length, 69);
t.end();
});
};
// this filter provides common synonyms for personal titles
// eg. doctor=>dr
module.exports.tests.personalTitleSynonymFilter = function (test, common) {
test('has personal_titles filter', function (t) {
var s = settings();
t.equal(typeof s.analysis.filter['synonyms/personal_titles'], 'object', 'there is a synonyms/personal_titles filter');
var filter = s.analysis.filter['synonyms/personal_titles'];
t.equal(filter.type, 'synonym');
t.true(Array.isArray(filter.synonyms));
t.equal(filter.synonyms.length, 191);
t.end();
});
};
// this filter provides common synonyms for place names
// eg. park=>pk
module.exports.tests.placeNameSynonymFilter = function (test, common) {
test('has place_names filter', function (t) {
var s = settings();
t.equal(typeof s.analysis.filter['synonyms/place_names'], 'object', 'there is a synonyms/place_names filter');
var filter = s.analysis.filter['synonyms/place_names'];
t.equal(filter.type, 'synonym');
t.true(Array.isArray(filter.synonyms));
t.equal(filter.synonyms.length, 314);
t.end();
});
};
// this filter removes number ordinals
// eg. 26th => 26, 1st => 1
module.exports.tests.removeOrdinalsFilter = function(test, common) {
test('has remove_ordinals filter', function(t) {
var s = settings();
t.equal(typeof s.analysis.filter.remove_ordinals, 'object', 'there is an remove_ordinals filter');
var filter = s.analysis.filter.remove_ordinals;
t.equal(filter.type, 'pattern_replace');
t.equal(filter.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?))($| ))');
t.equal(filter.replacement, '$2$4$5$6$7$9$10$12$14$15$16$17$18');
t.end();
});
};
// -- char filters --
// we use a custom punctuation filter in order to allow the ampersand
// character which would otherwise be stripped by the standard tokenizer
module.exports.tests.punctuationCharFilter = function(test, common) {
test('has punctuation char_filter', function(t) {
var s = settings();
t.equal(typeof s.analysis.char_filter.punctuation, 'object', 'there is a punctuation char_filter');
var char_filter = s.analysis.char_filter.punctuation;
t.equal(char_filter.type, 'mapping');
t.true(Array.isArray(char_filter.mappings));
t.equal(char_filter.mappings.length, 59);
t.end();
});
};
// remove non alphanumeric characters
module.exports.tests.alphanumericCharFilter = function(test, common) {
test('has alphanumeric char_filter', function(t) {
var s = settings();
t.equal(typeof s.analysis.char_filter.alphanumeric, 'object', 'there is a alphanumeric char_filter');
var char_filter = s.analysis.char_filter.alphanumeric;
t.equal(char_filter.type, 'pattern_replace');
t.equal(char_filter.pattern, '[^a-zA-Z0-9]');
t.equal(char_filter.replacement, '');
t.end();
});
};
// replace non-numeric chars with a space
module.exports.tests.numericCharFilter = function(test, common) {
test('has numeric char_filter', function(t) {
var s = settings();
t.equal(typeof s.analysis.char_filter.numeric, 'object', 'there is a numeric char_filter');
var char_filter = s.analysis.char_filter.numeric;
t.equal(char_filter.type, 'pattern_replace');
t.equal(char_filter.pattern, '[^0-9]');
t.equal(char_filter.replacement, ' ');
t.end();
});
};
// this filter provides british/american english synonyms
// eg. center<=>centre
module.exports.tests.britishAmericanEnglishSynonymFilter = function (test, common) {
test('has british_american_english filter', function (t) {
var s = settings();
t.equal(typeof s.analysis.filter['synonyms/british_american_english'], 'object', 'there is a synonyms/british_american_english filter');
var filter = s.analysis.filter['synonyms/british_american_english'];
t.equal(filter.type, 'synonym');
t.true(Array.isArray(filter.synonyms));
t.equal(filter.synonyms.length, 255);
t.end();
});
};
// -- etc --
// index should always be set
module.exports.tests.index = function(test, common) {
test('has index settings', function(t) {
var s = settings();
t.equal(typeof s.index, 'object', 'index specified');
t.equal(s.index.number_of_replicas, "0", 'replicas will increase index time');
t.equal(s.index.number_of_shards, "5", 'sharding value should use the elasticsearch default');
t.end();
});
};
// allow overrides from pelias/config
module.exports.tests.overrides = function(test, common) {
test('override defaults', function(t) {
process.env['PELIAS_CONFIG'] = path.resolve(__dirname + '/fixtures/empty.json');
var s = settings();
t.equal(s.index['number_of_replicas'], '0', 'unchanged');
// set the PELIAS_CONFIG env var
process.env['PELIAS_CONFIG'] = path.resolve( __dirname + '/fixtures/config.json' );
s = settings();
t.equal(s.index['number_of_replicas'], '999', 'changed');
t.end();
// unset the PELIAS_CONFIG env var
delete process.env['PELIAS_CONFIG'];
});
test('override similarity', function (t) {
process.env['PELIAS_CONFIG'] = path.resolve(__dirname + '/fixtures/empty.json');
var s = settings();
t.equal(s.index.similarity.peliasDefaultSimilarity.k1, 1.2, 'unchanged');
// set the PELIAS_CONFIG env var
process.env['PELIAS_CONFIG'] = path.resolve(__dirname + '/fixtures/similarity.json');
s = settings();
t.equal(s.index.similarity.peliasDefaultSimilarity.k1, 0, 'changed');
t.equal(s.index.similarity.peliasDefaultSimilarity.b, 0.75, 'changed');
t.end();
// unset the PELIAS_CONFIG env var
delete process.env['PELIAS_CONFIG'];
});
};
module.exports.all = function (tape, common) {
function test(name, testFunction) {
return tape('settings: ' + name, testFunction);
}
for( var testCase in module.exports.tests ){
module.exports.tests[testCase](test, common);
}
};