Skip to content

Commit

Permalink
fix(token_filters): fix mandatory token filter test and refactor sche…
Browse files Browse the repository at this point in the history
…ma to enforce original intent
  • Loading branch information
missinglink committed Nov 7, 2019
1 parent dbba70f commit 83e0cf2
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 14 deletions.
15 changes: 12 additions & 3 deletions settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function generate(){
"trim",
"word_delimiter",
"custom_admin",
"unique_only_same_position",
"notnull"
]
},
Expand Down Expand Up @@ -144,7 +145,10 @@ function generate(){
"char_filter" : ["alphanumeric"],
"filter": [
"lowercase",
"trim"
"icu_folding",
"trim",
"unique_only_same_position",
"notnull"
]
},
"peliasUnit": {
Expand All @@ -153,7 +157,10 @@ function generate(){
"char_filter" : ["alphanumeric"],
"filter": [
"lowercase",
"trim"
"icu_folding",
"trim",
"unique_only_same_position",
"notnull"
]
},
"peliasHousenumber": {
Expand All @@ -174,7 +181,9 @@ function generate(){
"directionals",
"icu_folding",
"remove_ordinals",
"trim"
"trim",
"unique_only_same_position",
"notnull"
]
}
},
Expand Down
15 changes: 12 additions & 3 deletions test/fixtures/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"trim",
"word_delimiter",
"custom_admin",
"unique_only_same_position",
"notnull"
]
},
Expand Down Expand Up @@ -141,7 +142,10 @@
],
"filter": [
"lowercase",
"trim"
"icu_folding",
"trim",
"unique_only_same_position",
"notnull"
]
},
"peliasUnit": {
Expand All @@ -152,7 +156,10 @@
],
"filter": [
"lowercase",
"trim"
"icu_folding",
"trim",
"unique_only_same_position",
"notnull"
]
},
"peliasHousenumber": {
Expand All @@ -178,7 +185,9 @@
"directionals",
"icu_folding",
"remove_ordinals",
"trim"
"trim",
"unique_only_same_position",
"notnull"
]
}
},
Expand Down
46 changes: 38 additions & 8 deletions test/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,10 @@ module.exports.tests.peliasZipAnalyzer = function(test, common) {
var analyzer = settings().analysis.analyzer.peliasZip;
t.deepEqual( analyzer.filter, [
"lowercase",
"trim"
"icu_folding",
"trim",
"unique_only_same_position",
"notnull"
]);
t.end();
});
Expand All @@ -248,7 +251,10 @@ module.exports.tests.peliasUnitAnalyzer = function(test, common) {
var analyzer = settings().analysis.analyzer.peliasUnit;
t.deepEqual( analyzer.filter, [
"lowercase",
"trim"
"icu_folding",
"trim",
"unique_only_same_position",
"notnull"
]);
t.end();
});
Expand Down Expand Up @@ -289,13 +295,15 @@ module.exports.tests.peliasStreetAnalyzer = function(test, common) {
"directionals",
"icu_folding",
"remove_ordinals",
"trim"
"trim",
"unique_only_same_position",
"notnull"
]);
t.end();
});
};

// cycle through all analyzers and ensure the corrsponding token filters are defined
// 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'
Expand All @@ -306,10 +314,10 @@ module.exports.tests.allTokenFiltersPresent = function(test, common) {
var analyzer = s.analysis.analyzer[analyzerName];
if( Array.isArray( analyzer.filter ) ){
analyzer.filter.forEach( function( tokenFilterName ){
var filterExists = s.analysis.filter.hasOwnProperty( tokenFilterName );
if( !filterExists && -1 < ES_INBUILT_FILTERS.indexOf( tokenFilterName ) ){
filterExists = true;
}
var filterExists = (
s.analysis.filter.hasOwnProperty( tokenFilterName ) ||
ES_INBUILT_FILTERS.includes( tokenFilterName )
);
t.true( filterExists, 'token filter exists: ' + tokenFilterName );
});
}
Expand All @@ -318,6 +326,28 @@ module.exports.tests.allTokenFiltersPresent = function(test, common) {
});
};

// 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 = [];
Expand Down

0 comments on commit 83e0cf2

Please sign in to comment.