From 95fcf1251e56a98415cfe26ac9bb6c327c177a5a Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Sat, 1 Mar 2025 18:17:44 +0100 Subject: [PATCH 1/3] Modernize codebase --- integration/address_matching.js | 100 +++--- integration/admin_abbreviations.js | 16 +- integration/admin_matching.js | 26 +- integration/analyzer_peliasAdmin.js | 72 ++-- integration/analyzer_peliasHousenumber.js | 28 +- .../analyzer_peliasIndexOneEdgeGram.js | 92 ++--- integration/analyzer_peliasPhrase.js | 128 +++---- integration/analyzer_peliasQuery.js | 66 ++-- integration/analyzer_peliasStreet.js | 96 ++--- integration/analyzer_peliasZip.js | 28 +- .../autocomplete_abbreviated_street_names.js | 18 +- ...ocomplete_directional_synonym_expansion.js | 68 ++-- .../autocomplete_street_synonym_expansion.js | 68 ++-- integration/bounding_box.js | 18 +- integration/dynamic_templates.js | 18 +- integration/multi_token_synonyms.js | 14 +- integration/run.js | 22 +- .../source_layer_sourceid_filtering.js | 48 +-- integration/validate.js | 8 +- mappings/document.js | 2 +- scripts/cli.js | 2 +- scripts/drop_index.js | 4 +- scripts/info.js | 6 +- scripts/list_analyzers.js | 12 +- scripts/output_mapping.js | 2 +- scripts/update_settings.js | 16 +- settings.js | 4 +- synonyms/country_codes/generate.js | 8 +- test/compile.js | 40 +-- test/configValidation.js | 36 +- test/document.js | 84 ++--- test/partial-admin.js | 26 +- test/partial-centroid.js | 14 +- test/partial-hash.js | 18 +- test/partial-keyword.js | 22 +- test/run.js | 9 +- test/settings.js | 334 +++++++++--------- test/synonyms/parser.js | 24 +- 38 files changed, 791 insertions(+), 806 deletions(-) diff --git a/integration/address_matching.js b/integration/address_matching.js index 4ea5e23d..4eab55b2 100644 --- a/integration/address_matching.js +++ b/integration/address_matching.js @@ -6,14 +6,14 @@ const getTotalHits = require('./_hits_total_helper'); module.exports.tests = {}; -module.exports.tests.functional = function(test, common){ - test( 'functional', function(t){ +module.exports.tests.functional = (test, common) => { + test( 'functional', t => { - var suite = new Suite( common.clientOpts, common.create ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up // index some docs - suite.action( function( done ){ + suite.action( done => { suite.client.index({ index: suite.props.index, id: '1', body: { address_parts: { @@ -25,7 +25,7 @@ module.exports.tests.functional = function(test, common){ }, done ); }); - suite.action( function( done ){ + suite.action( done => { suite.client.index({ index: suite.props.index, id: '2', body: { address_parts: { @@ -37,7 +37,7 @@ module.exports.tests.functional = function(test, common){ }, done ); }); - suite.action( function( done ){ + suite.action( done => { suite.client.index({ index: suite.props.index, id: '3', body: { address_parts: { @@ -49,7 +49,7 @@ module.exports.tests.functional = function(test, common){ }, done ); }); - suite.action( function( done ){ + suite.action( done => { suite.client.index({ index: suite.props.index, id: '4', body: { address_parts: { @@ -62,13 +62,13 @@ module.exports.tests.functional = function(test, common){ }); // search by street number - suite.assert( function( done ){ + suite.assert( done => { suite.client.search({ index: suite.props.index, body: { query: { bool: { must: [ { match: { 'address_parts.number': 30 } } ]}}} - }, function( err, res ){ + }, (err, res) => { t.equal( err, undefined ); t.equal( getTotalHits(res.hits), 1, 'match street number' ); done(); @@ -76,13 +76,13 @@ module.exports.tests.functional = function(test, common){ }); // search by street name - case insensitive - suite.assert( function( done ){ + suite.assert( done => { suite.client.search({ index: suite.props.index, body: { query: { bool: { must: [ { match_phrase: { 'address_parts.street': 'west 26th street' } } ]}}} - }, function( err, res ){ + }, (err, res) => { t.equal( err, undefined ); t.equal( getTotalHits(res.hits), 2, 'match street name' ); done(); @@ -90,13 +90,13 @@ module.exports.tests.functional = function(test, common){ }); // search by street name - using abbreviations - suite.assert( function( done ){ + suite.assert( done => { suite.client.search({ index: suite.props.index, body: { query: { bool: { must: [ { match_phrase: { 'address_parts.street': 'W 26th ST' } } ]}}} - }, function( err, res ){ + }, (err, res) => { t.equal( err, undefined ); t.equal( getTotalHits(res.hits), 2, 'match street name - abbr' ); done(); @@ -104,13 +104,13 @@ module.exports.tests.functional = function(test, common){ }); // search by zip - numeric zip - suite.assert( function( done ){ + suite.assert( done => { suite.client.search({ index: suite.props.index, body: { query: { bool: { must: [ { match: { 'address_parts.zip': '10010' } } ]}}} - }, function( err, res ){ + }, (err, res) => { t.equal( err, undefined ); t.equal( getTotalHits(res.hits), 3, 'match zip - numeric' ); done(); @@ -118,13 +118,13 @@ module.exports.tests.functional = function(test, common){ }); // search by zip - string zip - suite.assert( function( done ){ + suite.assert( done => { suite.client.search({ index: suite.props.index, body: { query: { bool: { must: [ { match: { 'address_parts.zip': 'e24dn' } } ]}}} - }, function( err, res ){ + }, (err, res) => { t.equal( err, undefined ); t.equal( getTotalHits(res.hits), 1, 'match zip - string' ); done(); @@ -132,13 +132,13 @@ module.exports.tests.functional = function(test, common){ }); // search by zip - numeric zip - with punctuation - suite.assert( function( done ){ + suite.assert( done => { suite.client.search({ index: suite.props.index, body: { query: { bool: { must: [ { match: { 'address_parts.zip': '100-10' } } ]}}} - }, function( err, res ){ + }, (err, res) => { t.equal( err, undefined ); t.equal( getTotalHits(res.hits), 3, 'match zip - numeric - punct' ); done(); @@ -146,13 +146,13 @@ module.exports.tests.functional = function(test, common){ }); // search by zip - numeric zip - with whitespace - suite.assert( function( done ){ + suite.assert( done => { suite.client.search({ index: suite.props.index, body: { query: { bool: { must: [ { match: { 'address_parts.zip': '10 0 10' } } ]}}} - }, function( err, res ){ + }, (err, res) => { t.equal( err, undefined ); t.equal( getTotalHits(res.hits), 3, 'match zip - numeric - whitespace' ); done(); @@ -160,13 +160,13 @@ module.exports.tests.functional = function(test, common){ }); // search by zip - string zip - with punctuation - suite.assert( function( done ){ + suite.assert( done => { suite.client.search({ index: suite.props.index, body: { query: { bool: { must: [ { match: { 'address_parts.zip': 'E2-4DN' } } ]}}} - }, function( err, res ){ + }, (err, res) => { t.equal( err, undefined ); t.equal( getTotalHits(res.hits), 1, 'match zip - string - punct' ); done(); @@ -174,13 +174,13 @@ module.exports.tests.functional = function(test, common){ }); // search by zip - string zip - with whitespace - suite.assert( function( done ){ + suite.assert( done => { suite.client.search({ index: suite.props.index, body: { query: { bool: { must: [ { match: { 'address_parts.zip': 'E2 4DN' } } ]}}} - }, function( err, res ){ + }, (err, res) => { t.equal( err, undefined ); t.equal( getTotalHits(res.hits), 1, 'match zip - string - whitespace' ); done(); @@ -192,8 +192,8 @@ module.exports.tests.functional = function(test, common){ }; -module.exports.tests.venue_vs_address = function(test, common){ - test( 'venue_vs_address', function(t){ +module.exports.tests.venue_vs_address = (test, common) => { + test( 'venue_vs_address', t => { // This test shows that partial matching addresses score higher than exact matching // venues with the same name. @@ -204,11 +204,11 @@ module.exports.tests.venue_vs_address = function(test, common){ // Unfortunately there seems to be no easy way of fixing this, it's an artifact of us // storing the street names in the name.default field. - var suite = new Suite( common.clientOpts, common.create ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up // index a venue - suite.action( function( done ){ + suite.action( done => { suite.client.index({ index: suite.props.index, id: '1', body: { @@ -220,32 +220,30 @@ module.exports.tests.venue_vs_address = function(test, common){ // index multiple streets, having many in the index is important // because it influences the 'norms' and TF/IDF scoring - const testFactory = function(i){ - return function( done ){ - let id = i + 100; // id offset - suite.client.index({ - index: suite.props.index, - id: String(id), - body: { - name: { default: `${id} Union Square` }, - phrase: { default: `${id} Union Square` }, - address_parts: { - number: String(i), - street: 'Union Square' - } + const testFactory = i => done => { + let id = i + 100; // id offset + suite.client.index({ + index: suite.props.index, + id: String(id), + body: { + name: { default: `${id} Union Square` }, + phrase: { default: `${id} Union Square` }, + address_parts: { + number: String(i), + street: 'Union Square' } - }, done); - }; + } + }, done); }; const TOTAL_ADDRESS_DOCS=9; - for( var i=0; i { suite.client.search({ index: suite.props.index, searchType: 'dfs_query_then_fetch', @@ -289,7 +287,7 @@ module.exports.tests.venue_vs_address = function(test, common){ } } } - }, function( err, res ){ + }, (err, res) => { t.equal( err, undefined ); t.equal( getTotalHits(res.hits), TOTAL_ADDRESS_DOCS+1, 'matched all docs' ); t.equal( res.hits.hits[TOTAL_ADDRESS_DOCS]._id, '1', 'exact name match first' ); @@ -301,13 +299,13 @@ module.exports.tests.venue_vs_address = function(test, common){ }); }; -module.exports.all = function (tape, common) { +module.exports.all = (tape, common) => { function test(name, testFunction) { return tape('address matching: ' + name, testFunction); } - for( var testCase in module.exports.tests ){ + for( const testCase in module.exports.tests ){ module.exports.tests[testCase](test, common); } }; diff --git a/integration/admin_abbreviations.js b/integration/admin_abbreviations.js index 20369180..66b64a5f 100644 --- a/integration/admin_abbreviations.js +++ b/integration/admin_abbreviations.js @@ -9,10 +9,10 @@ module.exports.tests = {}; * include a synonym mapping for country code abbreviations * which maps between alpha2 and alpha3 variants. */ -module.exports.tests.synonyms = function (test, common) { - test('synonyms - alpha3 does not share a prefix with alpha2', function (t) { +module.exports.tests.synonyms = (test, common) => { + test('synonyms - alpha3 does not share a prefix with alpha2', t => { - var suite = new Suite(common.clientOpts, common.create); + const suite = new Suite(common.clientOpts, common.create); suite.action(done => setTimeout(done, 500)); // wait for es to bring some shards up // index document 1 with country_a='MEX' @@ -132,9 +132,9 @@ module.exports.tests.synonyms = function (test, common) { suite.run(t.end); }); - test('synonyms - alpha3 shares a prefix with alpha2', function (t) { + test('synonyms - alpha3 shares a prefix with alpha2', t => { - var suite = new Suite(common.clientOpts, common.create); + const suite = new Suite(common.clientOpts, common.create); suite.action(done => setTimeout(done, 500)); // wait for es to bring some shards up // index document 1 with country_a='NZL' @@ -254,9 +254,9 @@ module.exports.tests.synonyms = function (test, common) { suite.run(t.end); }); - test('synonyms - additional synonyms do not increase field length', function (t) { + test('synonyms - additional synonyms do not increase field length', t => { - var suite = new Suite(common.clientOpts, common.create); + const suite = new Suite(common.clientOpts, common.create); suite.action(done => setTimeout(done, 500)); // wait for es to bring some shards up // index document 1 with country_a='NZL' @@ -329,7 +329,7 @@ module.exports.all = (tape, common) => { return tape('multi token synonyms: ' + name, testFunction); } - for (var testCase in module.exports.tests) { + for (const testCase in module.exports.tests) { module.exports.tests[testCase](test, common); } }; diff --git a/integration/admin_matching.js b/integration/admin_matching.js index 7d1de3b0..ca72f099 100644 --- a/integration/admin_matching.js +++ b/integration/admin_matching.js @@ -6,14 +6,14 @@ const getTotalHits = require('./_hits_total_helper'); module.exports.tests = {}; -module.exports.tests.functional = function(test, common){ - test( 'functional', function(t){ +module.exports.tests.functional = (test, common) => { + test( 'functional', t => { - var suite = new Suite( common.clientOpts, common.create ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up // index a document with all admin values - suite.action( function( done ){ + suite.action( done => { suite.client.index({ index: suite.props.index, id: '1', body: { @@ -42,11 +42,11 @@ module.exports.tests.functional = function(test, common){ }); // search by country - suite.assert( function( done ){ + suite.assert( done => { suite.client.search({ index: suite.props.index, body: { query: { match: { 'parent.country': 'Test Country' } } } - }, function( err, res ){ + }, (err, res) => { t.equal( err, undefined ); t.equal( getTotalHits(res.hits), 1, 'document found' ); done(); @@ -54,11 +54,11 @@ module.exports.tests.functional = function(test, common){ }); // search by country_a - suite.assert( function( done ){ + suite.assert( done => { suite.client.search({ index: suite.props.index, body: { query: { match: { 'parent.country_a': 'TestCountry' } } } - }, function( err, res ){ + }, (err, res) => { t.equal( err, undefined ); t.equal( getTotalHits(res.hits), 1, 'document found' ); done(); @@ -66,11 +66,11 @@ module.exports.tests.functional = function(test, common){ }); // search by country_id - suite.assert( function( done ){ + suite.assert( done => { suite.client.search({ index: suite.props.index, body: { query: { match: { 'parent.country_id': '100' } } } - }, function( err, res ){ + }, (err, res) => { t.equal( err, undefined ); t.equal( getTotalHits(res.hits), 1, 'document found' ); done(); @@ -84,13 +84,13 @@ module.exports.tests.functional = function(test, common){ }); }; -module.exports.all = function (tape, common) { +module.exports.all = (tape, common) => { function test(name, testFunction) { return tape('admin matching: ' + name, testFunction); } - for( var testCase in module.exports.tests ){ + for( const testCase in module.exports.tests ){ module.exports.tests[testCase](test, common); } }; diff --git a/integration/analyzer_peliasAdmin.js b/integration/analyzer_peliasAdmin.js index 22ec63f8..cdc04cd2 100644 --- a/integration/analyzer_peliasAdmin.js +++ b/integration/analyzer_peliasAdmin.js @@ -1,17 +1,15 @@ // validate analyzer is behaving as expected -var tape = require('tape'), - Suite = require('../test/elastictest/Suite'), - punctuation = require('../punctuation'); +const tape = require('tape'), Suite = require('../test/elastictest/Suite'), punctuation = require('../punctuation'); module.exports.tests = {}; -module.exports.tests.analyze = function(test, common){ - test( 'analyze', function(t){ +module.exports.tests.analyze = (test, common) => { + test( 'analyze', t => { - var suite = new Suite( common.clientOpts, common.create ); - var assertAnalysis = common.analyze.bind( null, suite, t, 'peliasAdmin' ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + const assertAnalysis = common.analyze.bind( null, suite, t, 'peliasAdmin' ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up assertAnalysis( 'lowercase', 'F', ['f']); assertAnalysis( 'asciifolding', 'é', ['e']); @@ -30,12 +28,12 @@ module.exports.tests.analyze = function(test, common){ }); }; -module.exports.tests.functional = function(test, common){ - test( 'functional', function(t){ +module.exports.tests.functional = (test, common) => { + test( 'functional', t => { - var suite = new Suite( common.clientOpts, common.create ); - var assertAnalysis = common.analyze.bind( null, suite, t, 'peliasAdmin' ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + const assertAnalysis = common.analyze.bind( null, suite, t, 'peliasAdmin' ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up assertAnalysis( 'country', 'Trinidad and Tobago', [ 'trinidad', 'and', 'tobago' @@ -68,12 +66,12 @@ module.exports.tests.functional = function(test, common){ }); }; -module.exports.tests.synonyms = function(test, common){ - test( 'synonyms', function(t){ +module.exports.tests.synonyms = (test, common) => { + test( 'synonyms', t => { - var suite = new Suite( common.clientOpts, common.create ); - var assertAnalysis = common.analyze.bind( null, suite, t, 'peliasAdmin' ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + const assertAnalysis = common.analyze.bind( null, suite, t, 'peliasAdmin' ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up assertAnalysis( 'place', 'Saint-Louis-du-Ha! Ha!', [ '0:saint', '0:st', '1:louis', '2:du', '3:ha', '4:ha' @@ -95,12 +93,12 @@ module.exports.tests.synonyms = function(test, common){ }); }; -module.exports.tests.tokenizer = function(test, common){ - test( 'tokenizer', function(t){ +module.exports.tests.tokenizer = (test, common) => { + test( 'tokenizer', t => { - var suite = new Suite( common.clientOpts, common.create ); - var assertAnalysis = common.analyze.bind( null, suite, t, 'peliasAdmin' ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + const assertAnalysis = common.analyze.bind( null, suite, t, 'peliasAdmin' ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up const expected = ['0:trinidad', '1:tobago']; @@ -123,22 +121,22 @@ module.exports.tests.tokenizer = function(test, common){ }; // @see: https://github.com/pelias/api/issues/600 -module.exports.tests.unicode = function(test, common){ - test( 'normalization', function(t){ +module.exports.tests.unicode = (test, common) => { + test( 'normalization', t => { - var suite = new Suite( common.clientOpts, common.create ); - var assertAnalysis = common.analyze.bind( null, suite, t, 'peliasAdmin' ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + const assertAnalysis = common.analyze.bind( null, suite, t, 'peliasAdmin' ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up - var latin_large_letter_e_with_acute = String.fromCodePoint(0x00C9); - var latin_small_letter_e_with_acute = String.fromCodePoint(0x00E9); - var combining_acute_accent = String.fromCodePoint(0x0301); - var latin_large_letter_e = String.fromCodePoint(0x0045); - var latin_small_letter_e = String.fromCodePoint(0x0065); + const latin_large_letter_e_with_acute = String.fromCodePoint(0x00C9); + const latin_small_letter_e_with_acute = String.fromCodePoint(0x00E9); + const combining_acute_accent = String.fromCodePoint(0x0301); + const latin_large_letter_e = String.fromCodePoint(0x0045); + const latin_small_letter_e = String.fromCodePoint(0x0065); // Chambéry (both forms appear the same) - var composed = "Chamb" + latin_small_letter_e_with_acute + "ry"; - var decomposed = "Chamb" + combining_acute_accent + latin_small_letter_e + "ry"; + let composed = "Chamb" + latin_small_letter_e_with_acute + "ry"; + let decomposed = "Chamb" + combining_acute_accent + latin_small_letter_e + "ry"; assertAnalysis( 'composed', composed, ['chambery'] ); assertAnalysis( 'decomposed', decomposed, ['chambery'] ); @@ -154,13 +152,13 @@ module.exports.tests.unicode = function(test, common){ }); }; -module.exports.all = function (tape, common) { +module.exports.all = (tape, common) => { function test(name, testFunction) { return tape('peliasAdmin: ' + name, testFunction); } - for( var testCase in module.exports.tests ){ + for( const testCase in module.exports.tests ){ module.exports.tests[testCase](test, common); } }; diff --git a/integration/analyzer_peliasHousenumber.js b/integration/analyzer_peliasHousenumber.js index d24962cb..0b726574 100644 --- a/integration/analyzer_peliasHousenumber.js +++ b/integration/analyzer_peliasHousenumber.js @@ -1,17 +1,15 @@ // validate analyzer is behaving as expected -var tape = require('tape'), - Suite = require('../test/elastictest/Suite'), - punctuation = require('../punctuation'); +const tape = require('tape'), Suite = require('../test/elastictest/Suite'), punctuation = require('../punctuation'); module.exports.tests = {}; -module.exports.tests.analyze = function(test, common){ - test( 'analyze', function(t){ +module.exports.tests.analyze = (test, common) => { + test( 'analyze', t => { - var suite = new Suite( common.clientOpts, common.create ); - var assertAnalysis = common.analyze.bind( null, suite, t, 'peliasHousenumber' ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + const assertAnalysis = common.analyze.bind( null, suite, t, 'peliasHousenumber' ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up assertAnalysis( 'keyword', '100 100', ['100','100']); assertAnalysis( 'numeric', '1a', ['1'] ); @@ -20,12 +18,12 @@ module.exports.tests.analyze = function(test, common){ }); }; -module.exports.tests.functional = function(test, common){ - test( 'functional', function(t){ +module.exports.tests.functional = (test, common) => { + test( 'functional', t => { - var suite = new Suite( common.clientOpts, common.create ); - var assertAnalysis = common.analyze.bind( null, suite, t, 'peliasHousenumber' ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + const assertAnalysis = common.analyze.bind( null, suite, t, 'peliasHousenumber' ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up assertAnalysis( 'apt no (generic)', '101a', [ '101' ]); @@ -38,13 +36,13 @@ module.exports.tests.functional = function(test, common){ }); }; -module.exports.all = function (tape, common) { +module.exports.all = (tape, common) => { function test(name, testFunction) { return tape('peliasHousenumber: ' + name, testFunction); } - for( var testCase in module.exports.tests ){ + for( const testCase in module.exports.tests ){ module.exports.tests[testCase](test, common); } }; diff --git a/integration/analyzer_peliasIndexOneEdgeGram.js b/integration/analyzer_peliasIndexOneEdgeGram.js index 523c092f..2a3448cf 100644 --- a/integration/analyzer_peliasIndexOneEdgeGram.js +++ b/integration/analyzer_peliasIndexOneEdgeGram.js @@ -7,12 +7,12 @@ const tape = require('tape'), module.exports.tests = {}; -module.exports.tests.analyze = function(test, common){ - test( 'analyze', function(t){ +module.exports.tests.analyze = (test, common) => { + test( 'analyze', t => { - var suite = new Suite( common.clientOpts, common.create ); - var assertAnalysis = common.analyze.bind( null, suite, t, 'peliasIndexOneEdgeGram' ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + const assertAnalysis = common.analyze.bind( null, suite, t, 'peliasIndexOneEdgeGram' ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up assertAnalysis( 'lowercase', 'F', ['f']); assertAnalysis( 'asciifolding', 'á', ['a']); @@ -101,12 +101,12 @@ module.exports.tests.analyze = function(test, common){ // address suffix expansions should only performed in a way that is // safe for 'partial tokens'. -module.exports.tests.address_suffix_expansions = function(test, common){ - test( 'address suffix expansions', function(t){ +module.exports.tests.address_suffix_expansions = (test, common) => { + test( 'address suffix expansions', t => { - var suite = new Suite( common.clientOpts, common.create ); - var assertAnalysis = common.analyze.bind( null, suite, t, 'peliasIndexOneEdgeGram' ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + const assertAnalysis = common.analyze.bind( null, suite, t, 'peliasIndexOneEdgeGram' ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up assertAnalysis( 'safe expansions', 'aly', [ '0:a', '0:al', '0:aly', '0:all', '0:alle', '0:alley' @@ -131,12 +131,12 @@ module.exports.tests.address_suffix_expansions = function(test, common){ }; // stop words should be disabled so that the entire street prefix is indexed as ngrams -module.exports.tests.stop_words = function(test, common){ - test( 'stop words', function(t){ +module.exports.tests.stop_words = (test, common) => { + test( 'stop words', t => { - var suite = new Suite( common.clientOpts, common.create ); - var assertAnalysis = common.analyze.bind( null, suite, t, 'peliasIndexOneEdgeGram' ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + const assertAnalysis = common.analyze.bind( null, suite, t, 'peliasIndexOneEdgeGram' ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up assertAnalysis( 'street suffix', 'AB street', [ '0:a', '0:ab', @@ -152,12 +152,12 @@ module.exports.tests.stop_words = function(test, common){ }); }; -module.exports.tests.functional = function(test, common){ - test( 'functional', function(t){ +module.exports.tests.functional = (test, common) => { + test( 'functional', t => { - var suite = new Suite( common.clientOpts, common.create ); - var assertAnalysis = common.analyze.bind( null, suite, t, 'peliasIndexOneEdgeGram' ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + const assertAnalysis = common.analyze.bind( null, suite, t, 'peliasIndexOneEdgeGram' ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up assertAnalysis('country', 'Trinidad and Tobago', [ '0:t', '0:tr', '0:tri', '0:trin', '0:trini', '0:trinid', '0:trinida', '0:trinidad', @@ -178,12 +178,12 @@ module.exports.tests.functional = function(test, common){ }; // unique token filter should only remove duplicate tokens at same position -module.exports.tests.unique = function(test, common){ - test( 'unique', function(t){ +module.exports.tests.unique = (test, common) => { + test( 'unique', t => { - var suite = new Suite( common.clientOpts, common.create ); - var assertAnalysis = common.analyze.bind( null, suite, t, 'peliasIndexOneEdgeGram' ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + const assertAnalysis = common.analyze.bind( null, suite, t, 'peliasIndexOneEdgeGram' ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up // if 'only_on_same_position' is not used the '1:a' token is erroneously removed assertAnalysis( 'unique', 'a ab', [ '0:a', '1:a', '1:ab' ]); @@ -192,12 +192,12 @@ module.exports.tests.unique = function(test, common){ }); }; -module.exports.tests.address = function(test, common){ - test( 'address', function(t){ +module.exports.tests.address = (test, common) => { + test( 'address', t => { - var suite = new Suite( common.clientOpts, common.create ); - var assertAnalysis = common.analyze.bind( null, suite, t, 'peliasIndexOneEdgeGram' ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + const assertAnalysis = common.analyze.bind( null, suite, t, 'peliasIndexOneEdgeGram' ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up assertAnalysis( 'address', '101 mapzen place', [ '0:1', '0:10', '0:101', @@ -224,22 +224,22 @@ module.exports.tests.address = function(test, common){ }; // @see: https://github.com/pelias/api/issues/600 -module.exports.tests.unicode = function(test, common){ - test( 'normalization', function(t){ +module.exports.tests.unicode = (test, common) => { + test( 'normalization', t => { - var suite = new Suite( common.clientOpts, common.create ); - var assertAnalysis = common.analyze.bind( null, suite, t, 'peliasIndexOneEdgeGram' ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + const assertAnalysis = common.analyze.bind( null, suite, t, 'peliasIndexOneEdgeGram' ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up - var latin_large_letter_e_with_acute = String.fromCodePoint(0x00C9); - var latin_small_letter_e_with_acute = String.fromCodePoint(0x00E9); - var combining_acute_accent = String.fromCodePoint(0x0301); - var latin_large_letter_e = String.fromCodePoint(0x0045); - var latin_small_letter_e = String.fromCodePoint(0x0065); + const latin_large_letter_e_with_acute = String.fromCodePoint(0x00C9); + const latin_small_letter_e_with_acute = String.fromCodePoint(0x00E9); + const combining_acute_accent = String.fromCodePoint(0x0301); + const latin_large_letter_e = String.fromCodePoint(0x0045); + const latin_small_letter_e = String.fromCodePoint(0x0065); // Chambéry (both forms appear the same) - var composed = "Chamb" + latin_small_letter_e_with_acute + "ry"; - var decomposed = "Chamb" + combining_acute_accent + latin_small_letter_e + "ry" + let composed = "Chamb" + latin_small_letter_e_with_acute + "ry"; + let decomposed = "Chamb" + combining_acute_accent + latin_small_letter_e + "ry" assertAnalysis( 'composed', composed, [ '0:c', '0:ch', '0:cha', '0:cham', '0:chamb', '0:chambe', '0:chamber', '0:chambery' @@ -249,8 +249,8 @@ module.exports.tests.unicode = function(test, common){ ] ); // Één (both forms appear the same) - var composed = latin_large_letter_e_with_acute + latin_small_letter_e_with_acute + "n"; - var decomposed = combining_acute_accent + latin_large_letter_e + combining_acute_accent + latin_small_letter_e + "n" + composed = latin_large_letter_e_with_acute + latin_small_letter_e_with_acute + "n"; + decomposed = combining_acute_accent + latin_large_letter_e + combining_acute_accent + latin_small_letter_e + "n" assertAnalysis('composed', composed, ['0:e', '0:ee', '0:een']); assertAnalysis('decomposed', decomposed, ['0:e', '0:ee', '0:een']); @@ -259,13 +259,13 @@ module.exports.tests.unicode = function(test, common){ }); }; -module.exports.all = function (tape, common) { +module.exports.all = (tape, common) => { function test(name, testFunction) { return tape('peliasIndexOneEdgeGram: ' + name, testFunction); } - for( var testCase in module.exports.tests ){ + for( const testCase in module.exports.tests ){ module.exports.tests[testCase](test, common); } }; diff --git a/integration/analyzer_peliasPhrase.js b/integration/analyzer_peliasPhrase.js index d87a9fe2..21090bfd 100644 --- a/integration/analyzer_peliasPhrase.js +++ b/integration/analyzer_peliasPhrase.js @@ -7,12 +7,12 @@ const getTotalHits = require('./_hits_total_helper'); module.exports.tests = {}; -module.exports.tests.analyze = function(test, common){ - test( 'analyze', function(t){ +module.exports.tests.analyze = (test, common) => { + test( 'analyze', t => { - var suite = new Suite( common.clientOpts, common.create ); - var assertAnalysis = common.analyze.bind( null, suite, t, 'peliasPhrase' ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + const assertAnalysis = common.analyze.bind( null, suite, t, 'peliasPhrase' ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up assertAnalysis( 'lowercase', 'F', ['f']); assertAnalysis( 'asciifolding', 'é', ['e']); @@ -48,7 +48,7 @@ module.exports.tests.analyze = function(test, common){ assertAnalysis( 'punctuation', punctuation.all.join(''), ['0:&', '0:and', '0:und'] ); assertAnalysis( 'punctuation', 'Hawai‘i', ['hawaii'] ); assertAnalysis( 'punctuation - « in between', '«res»pub«lika»', ['respublika'] ); - + assertAnalysis( 'british_american_english', 'town theatre', ['0:town', '1:theatre', '1:theater'] ); assertAnalysis( 'british_american_english', 'town theater', ['0:town', '1:theater', '1:theatre'] ); @@ -56,12 +56,12 @@ module.exports.tests.analyze = function(test, common){ }); }; -module.exports.tests.functional = function(test, common){ - test( 'functional', function(t){ +module.exports.tests.functional = (test, common) => { + test( 'functional', t => { - var suite = new Suite( common.clientOpts, common.create ); - var assertAnalysis = common.analyze.bind( null, suite, t, 'peliasPhrase' ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + const assertAnalysis = common.analyze.bind( null, suite, t, 'peliasPhrase' ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up assertAnalysis( 'country', 'Trinidad and Tobago', [ '0:trinidad', '1:and', '1:&', '2:tobago' @@ -76,26 +76,26 @@ module.exports.tests.functional = function(test, common){ ]); // both terms should map to same tokens - var expected1 = [ '0:325', '1:n', '1:north', '2:12', '3:st', '3:street' ]; - var expected2 = [ '0:325', '1:north', '1:n', '2:12', '3:street', '3:st' ]; + const expected1 = [ '0:325', '1:n', '1:north', '2:12', '3:st', '3:street' ]; + const expected2 = [ '0:325', '1:north', '1:n', '2:12', '3:street', '3:st' ]; assertAnalysis( 'address', '325 N 12th St', expected1 ); assertAnalysis( 'address', '325 North 12th Street', expected2 ); // both terms should map to same tokens - var expected3 = [ '0:13509', '1:colfax', '2:ave', '2:avenue', '2:av', '3:s', '3:south' ]; - var expected4 = [ '0:13509', '1:colfax', '2:avenue', '2:ave', '2:av', '3:south', '3:s' ]; + const expected3 = [ '0:13509', '1:colfax', '2:ave', '2:avenue', '2:av', '3:s', '3:south' ]; + const expected4 = [ '0:13509', '1:colfax', '2:avenue', '2:ave', '2:av', '3:south', '3:s' ]; assertAnalysis( 'address', '13509 Colfax Ave S', expected3 ); assertAnalysis( 'address', '13509 Colfax Avenue South', expected4 ); // both terms should map to same tokens - var expected5 = [ '0:100', '1:s', '1:south', '2:lake', '2:lk', '3:dr', '3:drive' ]; - var expected6 = [ '0:100', '1:south', '1:s', '2:lake', '2:lk', '3:drive', '3:dr' ]; + const expected5 = [ '0:100', '1:s', '1:south', '2:lake', '2:lk', '3:dr', '3:drive' ]; + const expected6 = [ '0:100', '1:south', '1:s', '2:lake', '2:lk', '3:drive', '3:dr' ]; assertAnalysis( 'address', '100 S Lake Dr', expected5 ); assertAnalysis( 'address', '100 South Lake Drive', expected6 ); // both terms should map to same tokens - var expected7 = [ '0:100', '1:northwest', '1:nw', '2:highway', '2:hwy' ]; - var expected8 = [ '0:100', '1:nw', '1:northwest', '2:hwy', '2:highway' ]; + const expected7 = [ '0:100', '1:northwest', '1:nw', '2:highway', '2:hwy' ]; + const expected8 = [ '0:100', '1:nw', '1:northwest', '2:hwy', '2:highway' ]; assertAnalysis( 'address', '100 northwest highway', expected7 ); assertAnalysis( 'address', '100 nw hwy', expected8 ); @@ -103,14 +103,14 @@ module.exports.tests.functional = function(test, common){ }); }; -module.exports.tests.tokenizer = function(test, common){ - test( 'tokenizer', function(t){ +module.exports.tests.tokenizer = (test, common) => { + test( 'tokenizer', t => { - var suite = new Suite( common.clientOpts, common.create ); - var assertAnalysis = common.analyze.bind( null, suite, t, 'peliasPhrase' ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + const assertAnalysis = common.analyze.bind( null, suite, t, 'peliasPhrase' ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up - var expected = [ '0:bedell', '1:street', '1:st', '2:133', '3:avenue', '3:ave', '3:av' ]; + const expected = [ '0:bedell', '1:street', '1:st', '2:133', '3:avenue', '3:ave', '3:av' ]; // specify 2 streets with a delimeter assertAnalysis( 'forward slash', 'Bedell Street/133rd Avenue', expected ); @@ -129,12 +129,12 @@ module.exports.tests.tokenizer = function(test, common){ // @ref: https://www.elastic.co/guide/en/elasticsearch/guide/current/phrase-matching.html // @ref: https://www.elastic.co/guide/en/elasticsearch/guide/current/slop.html -module.exports.tests.slop = function(test, common){ - test( 'slop', function(t){ +module.exports.tests.slop = (test, common) => { + test( 'slop', t => { - var suite = new Suite( common.clientOpts, common.create ); - var assertAnalysis = common.analyze.bind( null, suite, t, 'peliasPhrase' ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + const assertAnalysis = common.analyze.bind( null, suite, t, 'peliasPhrase' ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up // no index-time slop operations performed assertAnalysis( 'place', 'Lake Cayuga', [ 'lake', 'cayuga' ]); @@ -147,15 +147,15 @@ module.exports.tests.slop = function(test, common){ // balance scoring for similar terms 'Lake Cayuga', 'Cayuga Lake' and '7991 Lake Cayuga Dr' // @ref: https://www.elastic.co/guide/en/elasticsearch/guide/current/phrase-matching.html // @ref: https://www.elastic.co/guide/en/elasticsearch/guide/current/slop.html -module.exports.tests.slop_query = function(test, common){ - test( 'slop query', function(t){ +module.exports.tests.slop_query = (test, common) => { + test( 'slop query', t => { - var suite = new Suite( common.clientOpts, common.create ); - var assertAnalysis = common.analyze.bind( null, suite, t, 'peliasPhrase' ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + const assertAnalysis = common.analyze.bind( null, suite, t, 'peliasPhrase' ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up // index 'Lake Cayuga' - suite.action( function( done ){ + suite.action( done => { suite.client.index({ index: suite.props.index, id: '1', @@ -164,7 +164,7 @@ module.exports.tests.slop_query = function(test, common){ }); // index 'Cayuga Lake' - suite.action( function( done ){ + suite.action( done => { suite.client.index({ index: suite.props.index, id: '2', @@ -173,7 +173,7 @@ module.exports.tests.slop_query = function(test, common){ }); // index '7991 Lake Cayuga Dr' - suite.action( function( done ){ + suite.action( done => { suite.client.index({ index: suite.props.index, id: '3', @@ -209,15 +209,15 @@ module.exports.tests.slop_query = function(test, common){ }; } - suite.assert( function( done ){ + suite.assert( done => { suite.client.search({ index: suite.props.index, type: config.schema.typeName, searchType: 'dfs_query_then_fetch', body: buildQuery('Lake Cayuga') - }, function( err, res ){ + }, (err, res) => { t.equal( getTotalHits(res.hits), 3 ); - var hits = res.hits.hits; + const hits = res.hits.hits; t.equal( hits[0]._source.name.default, 'Lake Cayuga' ); @@ -240,14 +240,14 @@ module.exports.tests.slop_query = function(test, common){ }; // test the minimum amount of slop required to retrieve address documents -module.exports.tests.slop = function(test, common){ - test( 'slop', function(t){ +module.exports.tests.slop = (test, common) => { + test( 'slop', t => { - var suite = new Suite( common.clientOpts, common.create ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up // index a document - suite.action( function( done ){ + suite.action( done => { suite.client.index({ index: suite.props.index, id: '1', @@ -259,7 +259,7 @@ module.exports.tests.slop = function(test, common){ // in this case we require a slop of 3 to return the same // record with the street number and street name reversed. // (as is common in European countries, such as Germany). - suite.assert( function( done ){ + suite.assert( done => { suite.client.search({ index: suite.props.index, searchType: 'dfs_query_then_fetch', @@ -270,7 +270,7 @@ module.exports.tests.slop = function(test, common){ 'slop': 3, } }}} - }, function( err, res ){ + }, (err, res) => { t.equal( err, undefined ); t.equal( getTotalHits(res.hits), 1, 'document found' ); done(); @@ -282,29 +282,29 @@ module.exports.tests.slop = function(test, common){ }; // @see: https://github.com/pelias/api/issues/600 -module.exports.tests.unicode = function(test, common){ - test( 'normalization', function(t){ +module.exports.tests.unicode = (test, common) => { + test( 'normalization', t => { - var suite = new Suite( common.clientOpts, common.create ); - var assertAnalysis = common.analyze.bind( null, suite, t, 'peliasPhrase' ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + const assertAnalysis = common.analyze.bind( null, suite, t, 'peliasPhrase' ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up - var latin_large_letter_e_with_acute = String.fromCodePoint(0x00C9); - var latin_small_letter_e_with_acute = String.fromCodePoint(0x00E9); - var combining_acute_accent = String.fromCodePoint(0x0301); - var latin_large_letter_e = String.fromCodePoint(0x0045); - var latin_small_letter_e = String.fromCodePoint(0x0065); + const latin_large_letter_e_with_acute = String.fromCodePoint(0x00C9); + const latin_small_letter_e_with_acute = String.fromCodePoint(0x00E9); + const combining_acute_accent = String.fromCodePoint(0x0301); + const latin_large_letter_e = String.fromCodePoint(0x0045); + const latin_small_letter_e = String.fromCodePoint(0x0065); // Chambéry (both forms appear the same) - var composed = "Chamb" + latin_small_letter_e_with_acute + "ry"; - var decomposed = "Chamb" + combining_acute_accent + latin_small_letter_e + "ry" + let composed = "Chamb" + latin_small_letter_e_with_acute + "ry"; + let decomposed = "Chamb" + combining_acute_accent + latin_small_letter_e + "ry" assertAnalysis( 'composed', composed, ['chambery'] ); assertAnalysis( 'decomposed', decomposed, ['chambery'] ); // Één (both forms appear the same) - var composed = latin_large_letter_e_with_acute + latin_small_letter_e_with_acute + "n"; - var decomposed = combining_acute_accent + latin_large_letter_e + combining_acute_accent + latin_small_letter_e + "n" + composed = latin_large_letter_e_with_acute + latin_small_letter_e_with_acute + "n"; + decomposed = combining_acute_accent + latin_large_letter_e + combining_acute_accent + latin_small_letter_e + "n" assertAnalysis( 'composed', composed, ['een'] ); assertAnalysis( 'decomposed', decomposed, ['een'] ); @@ -313,13 +313,13 @@ module.exports.tests.unicode = function(test, common){ }); }; -module.exports.all = function (tape, common) { +module.exports.all = (tape, common) => { function test(name, testFunction) { return tape('peliasPhrase: ' + name, testFunction); } - for( var testCase in module.exports.tests ){ + for( const testCase in module.exports.tests ){ module.exports.tests[testCase](test, common); } }; diff --git a/integration/analyzer_peliasQuery.js b/integration/analyzer_peliasQuery.js index fc5a579d..7071d654 100644 --- a/integration/analyzer_peliasQuery.js +++ b/integration/analyzer_peliasQuery.js @@ -7,12 +7,12 @@ const tape = require('tape'), module.exports.tests = {}; -module.exports.tests.analyze = function(test, common){ - test( 'analyze', function(t){ +module.exports.tests.analyze = (test, common) => { + test( 'analyze', t => { - var suite = new Suite( common.clientOpts, common.create ); - var assertAnalysis = common.analyze.bind( null, suite, t, 'peliasQuery' ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + const assertAnalysis = common.analyze.bind( null, suite, t, 'peliasQuery' ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up assertAnalysis('tokenizer', 'foo-bar baz/42', ['foo','bar','baz','42']); assertAnalysis('tokenizer', 'foo-bar baz/42', ['foo','bar','baz','42']); // tab instead of space @@ -26,10 +26,10 @@ module.exports.tests.analyze = function(test, common){ assertAnalysis('digit_glued_to_word', 'john doe42', ['john', 'doe42']); if (config.schema.icuTokenizer) { assertAnalysis('thai_tonemarks', 'ก่ก้ก๊ก๋ข่ข้ข๊ข๋ค่ค้ค๊ค๋ฆ่ฆ้ฆ๊ฆ๋', ['กก', 'กก', 'ขขขขคคคคฆฆฆฆ']); - assertAnalysis('chinese_address', '北京市朝阳区东三环中路1号国际大厦A座1001室', ['北京市', '朝阳', '区', '东', '三', '环', '中路', '1', '号', '国际', '大厦', 'a', '座', '1001', '室']); + assertAnalysis('chinese_address', '北京市朝阳区东三环中路1号国际大厦A座1001室', ['北京市', '朝阳', '区', '东', '三', '环', '中路', '1', '号', '国际', '大厦', 'a', '座', '1001', '室']); } else { assertAnalysis('thai_tonemarks', 'ก่ก้ก๊ก๋ข่ข้ข๊ข๋ค่ค้ค๊ค๋ฆ่ฆ้ฆ๊ฆ๋', ['กกกกขขขขคคคคฆฆฆฆ']); - assertAnalysis('chinese_address', '北京市朝阳区东三环中路1号国际大厦A座1001室', ['北京市朝阳区东三环中路1号国际大厦a座1001室']); + assertAnalysis('chinese_address', '北京市朝阳区东三环中路1号国际大厦A座1001室', ['北京市朝阳区东三环中路1号国际大厦a座1001室']); } assertAnalysis('asciifolding', 'é', ['e']); @@ -56,12 +56,12 @@ module.exports.tests.analyze = function(test, common){ }); }; -module.exports.tests.functional = function(test, common){ - test( 'functional', function(t){ +module.exports.tests.functional = (test, common) => { + test( 'functional', t => { - var suite = new Suite( common.clientOpts, common.create ); - var assertAnalysis = common.analyze.bind( null, suite, t, 'peliasQuery' ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + const assertAnalysis = common.analyze.bind( null, suite, t, 'peliasQuery' ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up assertAnalysis( 'country', 'Trinidad and Tobago', [ 'trinidad', 'and', 'tobago' ]); assertAnalysis( 'place', 'Toys "R" Us!', [ 'toys', 'r', 'us' ]); @@ -98,12 +98,12 @@ module.exports.tests.functional = function(test, common){ }); }; -module.exports.tests.address = function(test, common){ - test( 'address', function(t){ +module.exports.tests.address = (test, common) => { + test( 'address', t => { - var suite = new Suite( common.clientOpts, common.create ); - var assertAnalysis = common.analyze.bind( null, suite, t, 'peliasQuery' ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + const assertAnalysis = common.analyze.bind( null, suite, t, 'peliasQuery' ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up assertAnalysis( 'address', '101 mapzen place', [ '101', 'mapzen', 'place' @@ -122,29 +122,29 @@ module.exports.tests.address = function(test, common){ }; // @see: https://github.com/pelias/api/issues/600 -module.exports.tests.unicode = function(test, common){ - test( 'normalization', function(t){ +module.exports.tests.unicode = (test, common) => { + test( 'normalization', t => { - var suite = new Suite( common.clientOpts, common.create ); - var assertAnalysis = common.analyze.bind( null, suite, t, 'peliasQuery' ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + const assertAnalysis = common.analyze.bind( null, suite, t, 'peliasQuery' ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up - var latin_large_letter_e_with_acute = String.fromCodePoint(0x00C9); - var latin_small_letter_e_with_acute = String.fromCodePoint(0x00E9); - var combining_acute_accent = String.fromCodePoint(0x0301); - var latin_large_letter_e = String.fromCodePoint(0x0045); - var latin_small_letter_e = String.fromCodePoint(0x0065); + const latin_large_letter_e_with_acute = String.fromCodePoint(0x00C9); + const latin_small_letter_e_with_acute = String.fromCodePoint(0x00E9); + const combining_acute_accent = String.fromCodePoint(0x0301); + const latin_large_letter_e = String.fromCodePoint(0x0045); + const latin_small_letter_e = String.fromCodePoint(0x0065); // Chambéry (both forms appear the same) - var composed = "Chamb" + latin_small_letter_e_with_acute + "ry"; - var decomposed = "Chamb" + combining_acute_accent + latin_small_letter_e + "ry" + let composed = "Chamb" + latin_small_letter_e_with_acute + "ry"; + let decomposed = "Chamb" + combining_acute_accent + latin_small_letter_e + "ry" assertAnalysis( 'composed', composed, ['chambery'] ); assertAnalysis( 'decomposed', decomposed, ['chambery'] ); // Één (both forms appear the same) - var composed = latin_large_letter_e_with_acute + latin_small_letter_e_with_acute + "n"; - var decomposed = combining_acute_accent + latin_large_letter_e + combining_acute_accent + latin_small_letter_e + "n" + composed = latin_large_letter_e_with_acute + latin_small_letter_e_with_acute + "n"; + decomposed = combining_acute_accent + latin_large_letter_e + combining_acute_accent + latin_small_letter_e + "n" assertAnalysis( 'composed', composed, ['een'] ); assertAnalysis( 'decomposed', decomposed, ['een'] ); @@ -153,13 +153,13 @@ module.exports.tests.unicode = function(test, common){ }); }; -module.exports.all = function (tape, common) { +module.exports.all = (tape, common) => { function test(name, testFunction) { return tape('peliasQuery: ' + name, testFunction); } - for( var testCase in module.exports.tests ){ + for( const testCase in module.exports.tests ){ module.exports.tests[testCase](test, common); } }; diff --git a/integration/analyzer_peliasStreet.js b/integration/analyzer_peliasStreet.js index 7f861f9a..e7a553a7 100644 --- a/integration/analyzer_peliasStreet.js +++ b/integration/analyzer_peliasStreet.js @@ -4,12 +4,12 @@ const config = require('pelias-config').generate() module.exports.tests = {}; -module.exports.tests.analyze = function(test, common){ - test( 'analyze', function(t){ +module.exports.tests.analyze = (test, common) => { + test( 'analyze', t => { - var suite = new Suite( common.clientOpts, common.create ); - var assertAnalysis = common.analyze.bind( null, suite, t, 'peliasStreet' ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + const assertAnalysis = common.analyze.bind( null, suite, t, 'peliasStreet' ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up assertAnalysis( 'lowercase', 'F', ['f']); assertAnalysis( 'asciifolding', 'Max-Beer-Straße', ['0:max', '1:beer', '2:strasse', '2:str']); @@ -41,12 +41,12 @@ module.exports.tests.analyze = function(test, common){ }); }; -module.exports.tests.functional = function(test, common){ - test( 'functional', function(t){ +module.exports.tests.functional = (test, common) => { + test( 'functional', t => { - var suite = new Suite( common.clientOpts, common.create ); - var assertAnalysis = common.analyze.bind( null, suite, t, 'peliasStreet' ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + const assertAnalysis = common.analyze.bind( null, suite, t, 'peliasStreet' ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up assertAnalysis( 'USA address', 'west 26th street', [ '0:west', '0:w', '1:26', '2:street', '2:st' ]); assertAnalysis( 'USA address', 'West 26th Street', [ '0:west', '0:w', '1:26', '2:street', '2:st' ]); @@ -58,14 +58,14 @@ module.exports.tests.functional = function(test, common){ }); }; -module.exports.tests.normalize_punctuation = function(test, common){ - test( 'normalize punctuation', function(t){ +module.exports.tests.normalize_punctuation = (test, common) => { + test( 'normalize punctuation', t => { - var suite = new Suite( common.clientOpts, common.create ); - var assertAnalysis = common.analyze.bind( null, suite, t, 'peliasStreet' ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + const assertAnalysis = common.analyze.bind( null, suite, t, 'peliasStreet' ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up - var expected = [ '0:chapala', '1:street', '1:st' ]; + const expected = [ '0:chapala', '1:street', '1:st' ]; assertAnalysis( 'single space', 'Chapala Street', expected ); assertAnalysis( 'double space', 'Chapala Street', expected ); @@ -76,12 +76,12 @@ module.exports.tests.normalize_punctuation = function(test, common){ }); }; -module.exports.tests.remove_ordinals = function(test, common){ - test( 'remove ordinals', function(t){ +module.exports.tests.remove_ordinals = (test, common) => { + test( 'remove ordinals', t => { - var suite = new Suite( common.clientOpts, common.create ); - var assertAnalysis = common.analyze.bind( null, suite, t, 'peliasStreet' ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + const assertAnalysis = common.analyze.bind( null, suite, t, 'peliasStreet' ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up assertAnalysis( 'ordindals', "1st", ["1"] ); assertAnalysis( 'ordindals', "22nd", ["22"] ); @@ -150,14 +150,14 @@ module.exports.tests.remove_ordinals = function(test, common){ }); }; -module.exports.tests.tokenizer = function(test, common){ - test( 'tokenizer', function(t){ +module.exports.tests.tokenizer = (test, common) => { + test( 'tokenizer', t => { - var suite = new Suite( common.clientOpts, common.create ); - var assertAnalysis = common.analyze.bind( null, suite, t, 'peliasStreet' ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + const assertAnalysis = common.analyze.bind( null, suite, t, 'peliasStreet' ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up - var expected = [ '0:bedell', '1:street', '1:st', '2:133', '3:avenue', '3:ave', '3:av' ]; + const expected = [ '0:bedell', '1:street', '1:st', '2:133', '3:avenue', '3:ave', '3:av' ]; // specify 2 streets with a delimeter assertAnalysis( 'forward slash', 'Bedell Street/133rd Avenue', expected ); @@ -175,29 +175,29 @@ module.exports.tests.tokenizer = function(test, common){ }; // @see: https://github.com/pelias/api/issues/600 -module.exports.tests.unicode = function(test, common){ - test( 'normalization', function(t){ +module.exports.tests.unicode = (test, common) => { + test( 'normalization', t => { - var suite = new Suite( common.clientOpts, common.create ); - var assertAnalysis = common.analyze.bind( null, suite, t, 'peliasStreet' ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + const assertAnalysis = common.analyze.bind( null, suite, t, 'peliasStreet' ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up - var latin_large_letter_e_with_acute = String.fromCodePoint(0x00C9); - var latin_small_letter_e_with_acute = String.fromCodePoint(0x00E9); - var combining_acute_accent = String.fromCodePoint(0x0301); - var latin_large_letter_e = String.fromCodePoint(0x0045); - var latin_small_letter_e = String.fromCodePoint(0x0065); + const latin_large_letter_e_with_acute = String.fromCodePoint(0x00C9); + const latin_small_letter_e_with_acute = String.fromCodePoint(0x00E9); + const combining_acute_accent = String.fromCodePoint(0x0301); + const latin_large_letter_e = String.fromCodePoint(0x0045); + const latin_small_letter_e = String.fromCodePoint(0x0065); // Chambéry (both forms appear the same) - var composed = "Chamb" + latin_small_letter_e_with_acute + "ry"; - var decomposed = "Chamb" + combining_acute_accent + latin_small_letter_e + "ry" + let composed = "Chamb" + latin_small_letter_e_with_acute + "ry"; + let decomposed = "Chamb" + combining_acute_accent + latin_small_letter_e + "ry" assertAnalysis( 'composed', composed, ['chambery'] ); assertAnalysis( 'decomposed', decomposed, ['chambery'] ); // Één (both forms appear the same) - var composed = latin_large_letter_e_with_acute + latin_small_letter_e_with_acute + "n"; - var decomposed = combining_acute_accent + latin_large_letter_e + combining_acute_accent + latin_small_letter_e + "n" + composed = latin_large_letter_e_with_acute + latin_small_letter_e_with_acute + "n"; + decomposed = combining_acute_accent + latin_large_letter_e + combining_acute_accent + latin_small_letter_e + "n" assertAnalysis( 'composed', composed, ['een'] ); assertAnalysis( 'decomposed', decomposed, ['een'] ); @@ -206,12 +206,12 @@ module.exports.tests.unicode = function(test, common){ }); }; -module.exports.tests.germanic_street_suffixes = function (test, common) { - test('germanic_street_suffixes', function (t) { +module.exports.tests.germanic_street_suffixes = (test, common) => { + test('germanic_street_suffixes', t => { - var suite = new Suite(common.clientOpts, common.create ); - var assertAnalysis = common.analyze.bind(null, suite, t, 'peliasStreet'); - suite.action(function (done) { setTimeout(done, 500); }); // wait for es to bring some shards up + const suite = new Suite(common.clientOpts, common.create ); + const assertAnalysis = common.analyze.bind(null, suite, t, 'peliasStreet'); + suite.action(done => { setTimeout(done, 500); }); // wait for es to bring some shards up // Germanic street suffixes assertAnalysis('straße', 'straße', ['0:strasse', '0:str']); @@ -228,13 +228,13 @@ module.exports.tests.germanic_street_suffixes = function (test, common) { }); }; -module.exports.all = function (tape, common) { +module.exports.all = (tape, common) => { function test(name, testFunction) { return tape('peliasStreet: ' + name, testFunction); } - for( var testCase in module.exports.tests ){ + for( const testCase in module.exports.tests ){ module.exports.tests[testCase](test, common); } }; diff --git a/integration/analyzer_peliasZip.js b/integration/analyzer_peliasZip.js index 810b092f..ed5b3aae 100644 --- a/integration/analyzer_peliasZip.js +++ b/integration/analyzer_peliasZip.js @@ -1,17 +1,15 @@ // validate analyzer is behaving as expected -var tape = require('tape'), - Suite = require('../test/elastictest/Suite'), - punctuation = require('../punctuation'); +const tape = require('tape'), Suite = require('../test/elastictest/Suite'), punctuation = require('../punctuation'); module.exports.tests = {}; -module.exports.tests.analyze = function(test, common){ - test( 'analyze', function(t){ +module.exports.tests.analyze = (test, common) => { + test( 'analyze', t => { - var suite = new Suite( common.clientOpts, common.create ); - var assertAnalysis = common.analyze.bind( null, suite, t, 'peliasZip' ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + const assertAnalysis = common.analyze.bind( null, suite, t, 'peliasZip' ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up assertAnalysis( 'lowercase', 'F', ['f']); assertAnalysis( 'trim', ' f ', ['f'] ); @@ -21,12 +19,12 @@ module.exports.tests.analyze = function(test, common){ }); }; -module.exports.tests.functional = function(test, common){ - test( 'functional', function(t){ +module.exports.tests.functional = (test, common) => { + test( 'functional', t => { - var suite = new Suite( common.clientOpts, common.create ); - var assertAnalysis = common.analyze.bind( null, suite, t, 'peliasZip' ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + const assertAnalysis = common.analyze.bind( null, suite, t, 'peliasZip' ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up assertAnalysis( 'usa zip', '10010', [ '10010' ]); assertAnalysis( 'usa zip', 10010, [ '10010' ]); @@ -40,13 +38,13 @@ module.exports.tests.functional = function(test, common){ }); }; -module.exports.all = function (tape, common) { +module.exports.all = (tape, common) => { function test(name, testFunction) { return tape('peliasZip: ' + name, testFunction); } - for( var testCase in module.exports.tests ){ + for( const testCase in module.exports.tests ){ module.exports.tests[testCase](test, common); } }; diff --git a/integration/autocomplete_abbreviated_street_names.js b/integration/autocomplete_abbreviated_street_names.js index fde4add4..6e1ee4a4 100644 --- a/integration/autocomplete_abbreviated_street_names.js +++ b/integration/autocomplete_abbreviated_street_names.js @@ -11,14 +11,14 @@ const getTotalHits = require('./_hits_total_helper'); module.exports.tests = {}; // index the name as 'Grolmanstraße' and then retrieve with partially complete token 'Grolmanstr.' -module.exports.tests.index_expanded_form_search_contracted = function(test, common){ - test( 'index expanded and retrieve contracted form', function(t){ +module.exports.tests.index_expanded_form_search_contracted = (test, common) => { + test( 'index expanded and retrieve contracted form', t => { - var suite = new Suite( common.clientOpts, common.create ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up // index a document with a name which contains a synonym (center) - suite.action( function( done ){ + suite.action( done => { suite.client.index({ index: suite.props.index, id: '1', @@ -27,7 +27,7 @@ module.exports.tests.index_expanded_form_search_contracted = function(test, comm }); // search using 'peliasQuery' - suite.assert( function( done ){ + suite.assert( done => { suite.client.search({ index: suite.props.index, body: { query: { match: { @@ -36,7 +36,7 @@ module.exports.tests.index_expanded_form_search_contracted = function(test, comm 'query': 'Grolmanstr.' } }}} - }, function( err, res ){ + }, (err, res) => { t.equal( err, undefined ); t.equal( getTotalHits(res.hits), 1, 'document found' ); done(); @@ -109,13 +109,13 @@ module.exports.tests.index_expanded_form_search_contracted = function(test, comm // }); // }; -module.exports.all = function (tape, common) { +module.exports.all = (tape, common) => { function test(name, testFunction) { return tape('autocomplete abbreviated street names: ' + name, testFunction); } - for( var testCase in module.exports.tests ){ + for( const testCase in module.exports.tests ){ module.exports.tests[testCase](test, common); } }; diff --git a/integration/autocomplete_directional_synonym_expansion.js b/integration/autocomplete_directional_synonym_expansion.js index 4f409ae6..bf3dbeb6 100644 --- a/integration/autocomplete_directional_synonym_expansion.js +++ b/integration/autocomplete_directional_synonym_expansion.js @@ -11,14 +11,14 @@ const getTotalHits = require('./_hits_total_helper'); module.exports.tests = {}; // index the name as 'north' and then retrieve with partially complete token 'nor' -module.exports.tests.index_and_retrieve_expanded_form = function(test, common){ - test( 'index and retrieve expanded form', function(t){ +module.exports.tests.index_and_retrieve_expanded_form = (test, common) => { + test( 'index and retrieve expanded form', t => { - var suite = new Suite( common.clientOpts, common.create ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up // index a document with a name which contains a synonym (center) - suite.action( function( done ){ + suite.action( done => { suite.client.index({ index: suite.props.index, id: '1', @@ -27,7 +27,7 @@ module.exports.tests.index_and_retrieve_expanded_form = function(test, common){ }); // search using 'peliasQuery' - suite.assert( function( done ){ + suite.assert( done => { suite.client.search({ index: suite.props.index, body: { query: { match: { @@ -36,7 +36,7 @@ module.exports.tests.index_and_retrieve_expanded_form = function(test, common){ 'query': 'nor' } }}} - }, function( err, res ){ + }, (err, res) => { t.equal( err, undefined ); t.equal( getTotalHits(res.hits), 1, 'document found' ); done(); @@ -44,7 +44,7 @@ module.exports.tests.index_and_retrieve_expanded_form = function(test, common){ }); // search using 'peliasQuery' - suite.assert( function( done ){ + suite.assert( done => { suite.client.search({ index: suite.props.index, body: { query: { match: { @@ -53,7 +53,7 @@ module.exports.tests.index_and_retrieve_expanded_form = function(test, common){ 'query': 'north' } }}} - }, function( err, res ){ + }, (err, res) => { t.equal( err, undefined ); t.equal( getTotalHits(res.hits), 1, 'document found' ); done(); @@ -65,14 +65,14 @@ module.exports.tests.index_and_retrieve_expanded_form = function(test, common){ }; // index the name as 'n' and then retrieve with 'n' -module.exports.tests.index_and_retrieve_contracted_form = function(test, common){ - test( 'index and retrieve contracted form', function(t){ +module.exports.tests.index_and_retrieve_contracted_form = (test, common) => { + test( 'index and retrieve contracted form', t => { - var suite = new Suite( common.clientOpts, common.create ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up // index a document with a name which contains a synonym (center) - suite.action( function( done ){ + suite.action( done => { suite.client.index({ index: suite.props.index, id: '1', @@ -81,7 +81,7 @@ module.exports.tests.index_and_retrieve_contracted_form = function(test, common) }); // search using 'peliasQuery' - suite.assert( function( done ){ + suite.assert( done => { suite.client.search({ index: suite.props.index, body: { query: { match: { @@ -90,7 +90,7 @@ module.exports.tests.index_and_retrieve_contracted_form = function(test, common) 'query': 'n' } }}} - }, function( err, res ){ + }, (err, res) => { t.equal( err, undefined ); t.equal( getTotalHits(res.hits), 1, 'document found' ); done(); @@ -102,14 +102,14 @@ module.exports.tests.index_and_retrieve_contracted_form = function(test, common) }; // index the name as 'n' and then retrieve with partially complete token 'nor' -module.exports.tests.index_and_retrieve_mixed_form_1 = function(test, common){ - test( 'index and retrieve mixed form 1', function(t){ +module.exports.tests.index_and_retrieve_mixed_form_1 = (test, common) => { + test( 'index and retrieve mixed form 1', t => { - var suite = new Suite( common.clientOpts, common.create ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up // index a document with a name which contains a synonym (center) - suite.action( function( done ){ + suite.action( done => { suite.client.index({ index: suite.props.index, id: '1', @@ -118,7 +118,7 @@ module.exports.tests.index_and_retrieve_mixed_form_1 = function(test, common){ }); // search using 'peliasQuery' - suite.assert( function( done ){ + suite.assert( done => { suite.client.search({ index: suite.props.index, body: { query: { match: { @@ -127,7 +127,7 @@ module.exports.tests.index_and_retrieve_mixed_form_1 = function(test, common){ 'query': 'nor' } }}} - }, function( err, res ){ + }, (err, res) => { t.equal( err, undefined ); t.equal( getTotalHits(res.hits), 1, 'document found' ); done(); @@ -135,7 +135,7 @@ module.exports.tests.index_and_retrieve_mixed_form_1 = function(test, common){ }); // search using 'peliasQuery' - suite.assert( function( done ){ + suite.assert( done => { suite.client.search({ index: suite.props.index, body: { query: { match: { @@ -144,7 +144,7 @@ module.exports.tests.index_and_retrieve_mixed_form_1 = function(test, common){ 'query': 'north' } }}} - }, function( err, res ){ + }, (err, res) => { t.equal( err, undefined ); t.equal( getTotalHits(res.hits), 1, 'document found' ); done(); @@ -156,14 +156,14 @@ module.exports.tests.index_and_retrieve_mixed_form_1 = function(test, common){ }; // index the name as 'north' and then retrieve with 'n' -module.exports.tests.index_and_retrieve_mixed_form_2 = function(test, common){ - test( 'index and retrieve mixed form 2', function(t){ +module.exports.tests.index_and_retrieve_mixed_form_2 = (test, common) => { + test( 'index and retrieve mixed form 2', t => { - var suite = new Suite( common.clientOpts, common.create ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up // index a document with a name which contains a synonym (center) - suite.action( function( done ){ + suite.action( done => { suite.client.index({ index: suite.props.index, id: '1', @@ -172,7 +172,7 @@ module.exports.tests.index_and_retrieve_mixed_form_2 = function(test, common){ }); // search using 'peliasQuery' - suite.assert( function( done ){ + suite.assert( done => { suite.client.search({ index: suite.props.index, body: { query: { match: { @@ -181,7 +181,7 @@ module.exports.tests.index_and_retrieve_mixed_form_2 = function(test, common){ 'query': 'n' } }}} - }, function( err, res ){ + }, (err, res) => { t.equal( err, undefined ); t.equal( getTotalHits(res.hits), 1, 'document found' ); done(); @@ -192,13 +192,13 @@ module.exports.tests.index_and_retrieve_mixed_form_2 = function(test, common){ }); }; -module.exports.all = function (tape, common) { +module.exports.all = (tape, common) => { function test(name, testFunction) { return tape('autocomplete directional synonym expansion: ' + name, testFunction); } - for( var testCase in module.exports.tests ){ + for( const testCase in module.exports.tests ){ module.exports.tests[testCase](test, common); } }; diff --git a/integration/autocomplete_street_synonym_expansion.js b/integration/autocomplete_street_synonym_expansion.js index c2c21e6f..ccb10c47 100644 --- a/integration/autocomplete_street_synonym_expansion.js +++ b/integration/autocomplete_street_synonym_expansion.js @@ -12,14 +12,14 @@ const getTotalHits = require('./_hits_total_helper'); module.exports.tests = {}; // index the name as 'center' and then retrieve with partially complete token 'cent' -module.exports.tests.index_and_retrieve_expanded_form = function(test, common){ - test( 'index and retrieve expanded form', function(t){ +module.exports.tests.index_and_retrieve_expanded_form = (test, common) => { + test( 'index and retrieve expanded form', t => { - var suite = new Suite( common.clientOpts, common.create ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up // index a document with a name which contains a synonym (center) - suite.action( function( done ){ + suite.action( done => { suite.client.index({ index: suite.props.index, id: '1', @@ -28,7 +28,7 @@ module.exports.tests.index_and_retrieve_expanded_form = function(test, common){ }); // search using 'peliasQuery' - suite.assert( function( done ){ + suite.assert( done => { suite.client.search({ index: suite.props.index, body: { query: { match: { @@ -37,7 +37,7 @@ module.exports.tests.index_and_retrieve_expanded_form = function(test, common){ 'query': 'cent' } }}} - }, function( err, res ){ + }, (err, res) => { t.equal( err, undefined ); t.equal( getTotalHits(res.hits), 1, 'document found' ); done(); @@ -45,7 +45,7 @@ module.exports.tests.index_and_retrieve_expanded_form = function(test, common){ }); // search using 'peliasQuery' - suite.assert( function( done ){ + suite.assert( done => { suite.client.search({ index: suite.props.index, body: { query: { match: { @@ -54,7 +54,7 @@ module.exports.tests.index_and_retrieve_expanded_form = function(test, common){ 'query': 'center' } }}} - }, function( err, res ){ + }, (err, res) => { t.equal( err, undefined ); t.equal( getTotalHits(res.hits), 1, 'document found' ); done(); @@ -66,14 +66,14 @@ module.exports.tests.index_and_retrieve_expanded_form = function(test, common){ }; // index the name as 'ctr' and then retrieve with 'ctr' -module.exports.tests.index_and_retrieve_contracted_form = function(test, common){ - test( 'index and retrieve contracted form', function(t){ +module.exports.tests.index_and_retrieve_contracted_form = (test, common) => { + test( 'index and retrieve contracted form', t => { - var suite = new Suite( common.clientOpts, common.create ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up // index a document with a name which contains a synonym (center) - suite.action( function( done ){ + suite.action( done => { suite.client.index({ index: suite.props.index, id: '1', @@ -82,7 +82,7 @@ module.exports.tests.index_and_retrieve_contracted_form = function(test, common) }); // search using 'peliasQuery' - suite.assert( function( done ){ + suite.assert( done => { suite.client.search({ index: suite.props.index, body: { query: { match: { @@ -91,7 +91,7 @@ module.exports.tests.index_and_retrieve_contracted_form = function(test, common) 'query': 'ctr' } }}} - }, function( err, res ){ + }, (err, res) => { t.equal( err, undefined ); t.equal( getTotalHits(res.hits), 1, 'document found' ); done(); @@ -103,14 +103,14 @@ module.exports.tests.index_and_retrieve_contracted_form = function(test, common) }; // index the name as 'ctr' and then retrieve with partially complete token 'cent' -module.exports.tests.index_and_retrieve_mixed_form_1 = function(test, common){ - test( 'index and retrieve mixed form 1', function(t){ +module.exports.tests.index_and_retrieve_mixed_form_1 = (test, common) => { + test( 'index and retrieve mixed form 1', t => { - var suite = new Suite( common.clientOpts, common.create ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up // index a document with a name which contains a synonym (center) - suite.action( function( done ){ + suite.action( done => { suite.client.index({ index: suite.props.index, id: '1', @@ -119,7 +119,7 @@ module.exports.tests.index_and_retrieve_mixed_form_1 = function(test, common){ }); // search using 'peliasQuery' - suite.assert( function( done ){ + suite.assert( done => { suite.client.search({ index: suite.props.index, body: { query: { match: { @@ -128,7 +128,7 @@ module.exports.tests.index_and_retrieve_mixed_form_1 = function(test, common){ 'query': 'cent' } }}} - }, function( err, res ){ + }, (err, res) => { t.equal( err, undefined ); t.equal( getTotalHits(res.hits), 1, 'document found' ); done(); @@ -136,7 +136,7 @@ module.exports.tests.index_and_retrieve_mixed_form_1 = function(test, common){ }); // search using 'peliasQuery' - suite.assert( function( done ){ + suite.assert( done => { suite.client.search({ index: suite.props.index, body: { query: { match: { @@ -145,7 +145,7 @@ module.exports.tests.index_and_retrieve_mixed_form_1 = function(test, common){ 'query': 'center' } }}} - }, function( err, res ){ + }, (err, res) => { t.equal( err, undefined ); t.equal( getTotalHits(res.hits), 1, 'document found' ); done(); @@ -157,14 +157,14 @@ module.exports.tests.index_and_retrieve_mixed_form_1 = function(test, common){ }; // index the name as 'center' and then retrieve with 'ctr' -module.exports.tests.index_and_retrieve_mixed_form_2 = function(test, common){ - test( 'index and retrieve mixed form 2', function(t){ +module.exports.tests.index_and_retrieve_mixed_form_2 = (test, common) => { + test( 'index and retrieve mixed form 2', t => { - var suite = new Suite( common.clientOpts, common.create ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up // index a document with a name which contains a synonym (center) - suite.action( function( done ){ + suite.action( done => { suite.client.index({ index: suite.props.index, id: '1', @@ -173,7 +173,7 @@ module.exports.tests.index_and_retrieve_mixed_form_2 = function(test, common){ }); // search using 'peliasQuery' - suite.assert( function( done ){ + suite.assert( done => { suite.client.search({ index: suite.props.index, body: { query: { match: { @@ -182,7 +182,7 @@ module.exports.tests.index_and_retrieve_mixed_form_2 = function(test, common){ 'query': 'ctr' } }}} - }, function( err, res ){ + }, (err, res) => { t.equal( err, undefined ); t.equal( getTotalHits(res.hits), 1, 'document found' ); done(); @@ -193,13 +193,13 @@ module.exports.tests.index_and_retrieve_mixed_form_2 = function(test, common){ }); }; -module.exports.all = function (tape, common) { +module.exports.all = (tape, common) => { function test(name, testFunction) { return tape('autocomplete street synonym expansion: ' + name, testFunction); } - for( var testCase in module.exports.tests ){ + for( const testCase in module.exports.tests ){ module.exports.tests[testCase](test, common); } }; diff --git a/integration/bounding_box.js b/integration/bounding_box.js index 21e5c864..d299bd90 100644 --- a/integration/bounding_box.js +++ b/integration/bounding_box.js @@ -5,14 +5,14 @@ const config = require('pelias-config').generate(); module.exports.tests = {}; -module.exports.tests.index_and_retrieve = function(test, common){ - test( 'index and retrieve', function(t){ +module.exports.tests.index_and_retrieve = (test, common) => { + test( 'index and retrieve', t => { - var suite = new Suite( common.clientOpts, common.create ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up // index a document with a bbox - suite.action( function( done ){ + suite.action( done => { suite.client.index({ index: suite.props.index, id: '1', @@ -23,13 +23,13 @@ module.exports.tests.index_and_retrieve = function(test, common){ }); // retrieve document by id - suite.assert( function( done ) { + suite.assert( done => { suite.client.get( { index: suite.props.index, id: '1' }, - function (err, res) { + (err, res) => { t.equal(err, undefined); t.deepEqual(res._source.bounding_box, '{"min_lat":-47.75,"max_lat":-33.9,"min_lon":163.82,"max_lon":179.42}'); done(); @@ -41,13 +41,13 @@ module.exports.tests.index_and_retrieve = function(test, common){ }); }; -module.exports.all = function (tape, common) { +module.exports.all = (tape, common) => { function test(name, testFunction) { return tape('bounding box: ' + name, testFunction); } - for( var testCase in module.exports.tests ){ + for( const testCase in module.exports.tests ){ module.exports.tests[testCase](test, common); } }; diff --git a/integration/dynamic_templates.js b/integration/dynamic_templates.js index 6e64a09c..352fa6c3 100644 --- a/integration/dynamic_templates.js +++ b/integration/dynamic_templates.js @@ -5,33 +5,33 @@ const config = require('pelias-config').generate(); module.exports.tests = {}; -module.exports.tests.dynamic_templates_name = function(test, common){ +module.exports.tests.dynamic_templates_name = (test, common) => { test( 'document->name', nameAssertion( 'peliasIndexOneEdgeGram', common ) ); }; -module.exports.tests.dynamic_templates_phrase = function(test, common){ +module.exports.tests.dynamic_templates_phrase = (test, common) => { test( 'document->phrase', phraseAssertion( 'peliasPhrase', common ) ); }; -module.exports.tests.dynamic_templates_addendum = function(test, common){ +module.exports.tests.dynamic_templates_addendum = (test, common) => { test( 'addendum', addendumAssertion( 'wikipedia', JSON.stringify({ slug: 'Wikipedia' }), common ) ); }; -module.exports.all = function (tape, common) { +module.exports.all = (tape, common) => { function test(name, testFunction) { return tape('dynamic_templates: ' + name, testFunction); } - for( var testCase in module.exports.tests ){ + for( const testCase in module.exports.tests ){ module.exports.tests[testCase](test, common); } }; function nameAssertion( analyzer, common ){ - return function(t){ + return t => { - var suite = new Suite( common.clientOpts, common.create ); + const suite = new Suite( common.clientOpts, common.create ); // index a document from a normal document layer suite.action( done => { @@ -65,7 +65,7 @@ function nameAssertion( analyzer, common ){ } function phraseAssertion( analyzer, common ){ - return function(t){ + return t => { const suite = new Suite( common.clientOpts, common.create ); @@ -101,7 +101,7 @@ function phraseAssertion( analyzer, common ){ } function addendumAssertion( namespace, value, common ){ - return function(t){ + return t => { const suite = new Suite( common.clientOpts, common.create ); diff --git a/integration/multi_token_synonyms.js b/integration/multi_token_synonyms.js index 74ef9eec..95ccb91a 100644 --- a/integration/multi_token_synonyms.js +++ b/integration/multi_token_synonyms.js @@ -7,16 +7,16 @@ module.exports.tests = {}; // simple test to cover the issue noted in: // https://github.com/pelias/schema/issues/381#issuecomment-548305594 -module.exports.tests.functional = function (test, common) { - test('functional', function (t) { +module.exports.tests.functional = (test, common) => { + test('functional', t => { - var suite = new Suite(common.clientOpts, common.create); - suite.action(function (done) { setTimeout(done, 500); }); // wait for es to bring some shards up + const suite = new Suite(common.clientOpts, common.create); + suite.action(done => { setTimeout(done, 500); }); // wait for es to bring some shards up // index a document with all admin values // note: this will return an error if multi-token synonyms are // not supported on ES6+ - suite.action(function (done) { + suite.action(done => { suite.client.index({ index: suite.props.index, id: '1', body: { @@ -37,13 +37,13 @@ module.exports.tests.functional = function (test, common) { }); }; -module.exports.all = function (tape, common) { +module.exports.all = (tape, common) => { function test(name, testFunction) { return tape('multi token synonyms: ' + name, testFunction); } - for (var testCase in module.exports.tests) { + for (const testCase in module.exports.tests) { module.exports.tests[testCase](test, common); } }; diff --git a/integration/run.js b/integration/run.js index 4c906792..d4355843 100644 --- a/integration/run.js +++ b/integration/run.js @@ -14,15 +14,11 @@ const common = { schema: schema, create: { } }, - summaryMap: (res) => { - return res.hits.hits.map(h => { - return { - _id: h._id, - _score: h._score, - name: h._source.name - }; - }); - }, + summaryMap: res => res.hits.hits.map(h => ({ + _id: h._id, + _score: h._score, + name: h._source.name + })), summary: (res) => { common.summaryMap( res ) .forEach( console.dir ); @@ -50,7 +46,7 @@ const common = { } }); // sort all the arrays so that order is irrelevant - for (var attr in positions){ + for (const attr in positions){ positions[attr] = positions[attr].sort(); } return positions; @@ -82,7 +78,7 @@ const common = { }; function removeIndexTokensFromExpectedTokens(index, expected){ - for (var pos in index) { + for (const pos in index) { if (!_.isArray(expected[pos])) { continue; } expected[pos] = expected[pos].filter(token => !index[pos].includes(token)); if (_.isEmpty(expected[pos])) { delete expected[pos]; } @@ -91,7 +87,7 @@ function removeIndexTokensFromExpectedTokens(index, expected){ return expected; } -var tests = [ +const tests = [ require('./validate.js'), require('./dynamic_templates.js'), require('./analyzer_peliasIndexOneEdgeGram.js'), @@ -112,6 +108,6 @@ var tests = [ require('./admin_abbreviations.js') ]; -tests.map(function(t) { +tests.map(t => { t.all(tape, common); }); diff --git a/integration/source_layer_sourceid_filtering.js b/integration/source_layer_sourceid_filtering.js index 5b3e5cb5..3c60df32 100644 --- a/integration/source_layer_sourceid_filtering.js +++ b/integration/source_layer_sourceid_filtering.js @@ -6,35 +6,35 @@ const getTotalHits = require('./_hits_total_helper'); module.exports.tests = {}; -module.exports.tests.source_filter = function(test, common){ - test( 'source filter', function(t){ +module.exports.tests.source_filter = (test, common) => { + test( 'source filter', t => { - var suite = new Suite( common.clientOpts, common.create ); - suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up + const suite = new Suite( common.clientOpts, common.create ); + suite.action( done => { setTimeout( done, 500 ); }); // wait for es to bring some shards up // index some docs - suite.action( function( done ){ + suite.action( done => { suite.client.index({ index: suite.props.index, id: '1', body: { source: 'osm', layer: 'node', source_id: 'dataset/1' } }, done ); }); - suite.action( function( done ){ + suite.action( done => { suite.client.index({ index: suite.props.index, id: '2', body: { source: 'osm', layer: 'address', source_id: 'dataset/2' } }, done ); }); - suite.action( function( done ){ + suite.action( done => { suite.client.index({ index: suite.props.index, id: '3', body: { source: 'geonames', layer: 'address', source_id: 'dataset/1' } }, done ); }); - suite.action( function( done ){ + suite.action( done => { suite.client.index({ index: suite.props.index, id: '4', body: { source: 'foo bar baz' } @@ -42,7 +42,7 @@ module.exports.tests.source_filter = function(test, common){ }); // find all 'osm' sources - suite.assert( function( done ){ + suite.assert( done => { suite.client.search({ index: suite.props.index, body: { query: { @@ -50,14 +50,14 @@ module.exports.tests.source_filter = function(test, common){ source: 'osm' } }} - }, function( err, res ){ + }, (err, res) => { t.equal( getTotalHits(res.hits), 2 ); done(); }); }); // find all 'address' layers - suite.assert( function( done ){ + suite.assert( done => { suite.client.search({ index: suite.props.index, body: { query: { @@ -65,14 +65,14 @@ module.exports.tests.source_filter = function(test, common){ layer: 'address' } }} - }, function( err, res ){ + }, (err, res) => { t.equal( getTotalHits(res.hits), 2 ); done(); }); }); // find all 'shop' source_ids - suite.assert( function( done ){ + suite.assert( done => { suite.client.search({ index: suite.props.index, body: { query: { @@ -80,28 +80,28 @@ module.exports.tests.source_filter = function(test, common){ source_id: 'dataset/1' } }} - }, function( err, res ){ + }, (err, res) => { t.equal( getTotalHits(res.hits), 2 ); done(); }); }); // find all 'shop' source_ids from 'osm' source - suite.assert( function( done ){ + suite.assert( done => { suite.client.search({ index: suite.props.index, body: { query: { bool: { must: [ { term: { source: 'osm' } }, { term: { source_id: 'dataset/1' } } ]}}} - }, function( err, res ){ + }, (err, res) => { t.equal( getTotalHits(res.hits), 1 ); done(); }); }); // case sensitive - suite.assert( function( done ){ + suite.assert( done => { suite.client.search({ index: suite.props.index, body: { query: { @@ -109,14 +109,14 @@ module.exports.tests.source_filter = function(test, common){ source: 'OSM' } }} - }, function( err, res ){ + }, (err, res) => { t.equal( getTotalHits(res.hits), 0 ); done(); }); }); // keyword analysis - no partial matching - suite.assert( function( done ){ + suite.assert( done => { suite.client.search({ index: suite.props.index, body: { query: { @@ -124,14 +124,14 @@ module.exports.tests.source_filter = function(test, common){ source: 'foo' } }} - }, function( err, res ){ + }, (err, res) => { t.equal( getTotalHits(res.hits), 0 ); done(); }); }); // keyword analysis - allows spaces - suite.assert( function( done ){ + suite.assert( done => { suite.client.search({ index: suite.props.index, body: { query: { @@ -139,7 +139,7 @@ module.exports.tests.source_filter = function(test, common){ source: 'foo bar baz' } }} - }, function( err, res ){ + }, (err, res) => { t.equal( getTotalHits(res.hits), 1 ); done(); }); @@ -149,13 +149,13 @@ module.exports.tests.source_filter = function(test, common){ }); }; -module.exports.all = function (tape, common) { +module.exports.all = (tape, common) => { function test(name, testFunction) { return tape('field filtering: ' + name, testFunction); } - for( var testCase in module.exports.tests ){ + for( const testCase in module.exports.tests ){ module.exports.tests[testCase](test, common); } }; diff --git a/integration/validate.js b/integration/validate.js index 31622e98..7432b700 100644 --- a/integration/validate.js +++ b/integration/validate.js @@ -5,10 +5,10 @@ const Suite = require('../test/elastictest/Suite'); module.exports.tests = {}; -module.exports.tests.validate = function(test, common){ +module.exports.tests.validate = (test, common) => { test( 'schema', t => { - var suite = new Suite( common.clientOpts, common.create ); + const suite = new Suite( common.clientOpts, common.create ); suite.assert( done => { suite.client.info({}, ( err, res, status ) => { @@ -21,13 +21,13 @@ module.exports.tests.validate = function(test, common){ }); }; -module.exports.all = function (tape, common) { +module.exports.all = (tape, common) => { function test(name, testFunction) { return tape('validate: ' + name, testFunction); } - for( var testCase in module.exports.tests ){ + for( const testCase in module.exports.tests ){ module.exports.tests[testCase](test, common); } }; diff --git a/mappings/document.js b/mappings/document.js index da22b396..e8e23c21 100644 --- a/mappings/document.js +++ b/mappings/document.js @@ -6,7 +6,7 @@ const multiplier = require('./partial/multiplier'); const keyword = require('./partial/keyword'); const keyword_with_doc_values = require('./partial/keyword_with_doc_values'); -var schema = { +const schema = { properties: { // data partitioning diff --git a/scripts/cli.js b/scripts/cli.js index fb0d7b56..bb998544 100644 --- a/scripts/cli.js +++ b/scripts/cli.js @@ -3,7 +3,7 @@ const util = require('util'); const colors = require('colors/safe'); module.exports.header = function( text ){ - var rule = new Array( text.length + 3 ).join("-"); + const rule = new Array( text.length + 3 ).join("-"); console.log( util.format("\n\033[0;33m%s\n %s \n%s\033[0m\n", rule, text, rule ) ); } diff --git a/scripts/drop_index.js b/scripts/drop_index.js index 100ad2ec..036b8026 100644 --- a/scripts/drop_index.js +++ b/scripts/drop_index.js @@ -19,7 +19,7 @@ function drop() { // check all hosts to see if any is not localhost function warnIfNotLocal() { - if (config.esclient.hosts.some((env) => { return env.host !== 'localhost'; })) { + if (config.esclient.hosts.some(env => env.host !== 'localhost')) { console.log(colors.red(`WARNING: DROPPING SCHEMA NOT ON LOCALHOST: ${config.esclient.hosts[0].host}`)); } } @@ -38,5 +38,5 @@ function fail() { } function isForced() { - return process.argv.length > 2 && ['--force-yes', '-f'].indexOf(process.argv[2]) > -1; + return process.argv.length > 2 && ['--force-yes', '-f'].includes(process.argv[2]); } \ No newline at end of file diff --git a/scripts/info.js b/scripts/info.js index 373dbccf..7a44379e 100644 --- a/scripts/info.js +++ b/scripts/info.js @@ -1,5 +1,5 @@ -var config = require('pelias-config').generate().esclient; -var es = require('elasticsearch'); -var client = new es.Client(config); +const config = require('pelias-config').generate().esclient; +const es = require('elasticsearch'); +const client = new es.Client(config); client.info( {}, console.log.bind(console) ); diff --git a/scripts/list_analyzers.js b/scripts/list_analyzers.js index f7e367c6..6adaffa9 100644 --- a/scripts/list_analyzers.js +++ b/scripts/list_analyzers.js @@ -7,7 +7,7 @@ const NOT_APPLICABLE_ANALYZER = 'n/a'; const DEFAULT_NORMALIZER = '{none}'; const NOT_APPLICABLE_NORMALIZER = 'n/a'; -const defaultAnalyzerFor = function(mapping){ +const defaultAnalyzerFor = mapping => { switch (mapping.type){ case 'text': return DEFAULT_ANALYZER; case 'string': return DEFAULT_ANALYZER; @@ -15,7 +15,7 @@ const defaultAnalyzerFor = function(mapping){ return NOT_APPLICABLE_ANALYZER; } -const defaultNormalizerFor = function (mapping) { +const defaultNormalizerFor = mapping => { switch (mapping.type) { case 'keyword': return DEFAULT_NORMALIZER; } @@ -23,7 +23,7 @@ const defaultNormalizerFor = function (mapping) { } // pretty print a single analyzer/normalizer label -const pretty = function(analyzer){ +const pretty = analyzer => { if (analyzer === DEFAULT_ANALYZER) { return colors.blue(analyzer) } @@ -37,7 +37,7 @@ const pretty = function(analyzer){ } // pretty print a single line -const print = function(vals) { +const print = vals => { console.error( colors.brightBlue(vals.field.padEnd(32)), vals.type.padEnd(32), @@ -48,7 +48,7 @@ const print = function(vals) { } // pretty print an error -const error = function(vals) { +const error = vals => { console.error(Object.values(vals).map(v => colors.red(v)).join(' | ')); } @@ -57,7 +57,7 @@ const mapping = schema.mappings; const dynamic = mapping.dynamic_templates.map(t => _.first(_.map(t, v => v))); // process and single mapping property (recursively) -const property = function(prop, field){ +const property = (prop, field) => { // properties with subfields if (prop.type === 'object') { // recurse the object properties diff --git a/scripts/output_mapping.js b/scripts/output_mapping.js index 3cc6b050..9d8426a1 100644 --- a/scripts/output_mapping.js +++ b/scripts/output_mapping.js @@ -1,4 +1,4 @@ -var schema = require('../schema'); +const schema = require('../schema'); console.log( JSON.stringify( schema.mappings, null, 2 ) ); diff --git a/scripts/update_settings.js b/scripts/update_settings.js index 22d7b9c5..87429523 100644 --- a/scripts/update_settings.js +++ b/scripts/update_settings.js @@ -1,9 +1,9 @@ -var config = require('pelias-config').generate(); -var es = require('elasticsearch'); -var client = new es.Client(config.esclient); -var schema = require('../schema'); +const config = require('pelias-config').generate(); +const es = require('elasticsearch'); +const client = new es.Client(config.esclient); +const schema = require('../schema'); -var _index = config.schema.indexName; +const _index = config.schema.indexName; // Error: ElasticsearchIllegalArgumentException[can't change the number of shards for an index if( schema.settings.hasOwnProperty('index') && @@ -12,11 +12,11 @@ if( schema.settings.hasOwnProperty('index') && delete schema.settings.index.number_of_replicas; } -client.indices.close( { index: _index }, function( err, res ){ +client.indices.close( { index: _index }, (err, res) => { console.log( '[close index]', '\t', _index, err || '\t', res ); - client.indices.putSettings( { index: _index, body: schema.settings }, function( err, res ){ + client.indices.putSettings( { index: _index, body: schema.settings }, (err, res) => { console.log( '[put settings]', '\t', _index, err || '\t', res ); - client.indices.open( { index: _index }, function( err, res ){ + client.indices.open( { index: _index }, (err, res) => { console.log( '[open index]', '\t', _index, err || '\t', res ); process.exit( !!err ); }); diff --git a/settings.js b/settings.js index be3ad673..5208e4fb 100644 --- a/settings.js +++ b/settings.js @@ -243,9 +243,7 @@ function generate(){ "char_filter": { "punctuation" : { "type" : "mapping", - "mappings" : punctuation.blacklist.map(function(c){ - return c + '=>'; - }) + "mappings" : punctuation.blacklist.map(c => c + '=>') }, "alphanumeric" : { "type" : "pattern_replace", diff --git a/synonyms/country_codes/generate.js b/synonyms/country_codes/generate.js index 80070d0b..a7b9f928 100644 --- a/synonyms/country_codes/generate.js +++ b/synonyms/country_codes/generate.js @@ -4,8 +4,8 @@ const path = require('path'); const iso3166 = require('iso3166-1'); const filename = path.join(__dirname, 'iso3166.txt'); const comparer = (a, b) => { - var aa = a.replace(/^#/, '') - var bb = b.replace(/^#/, '') + const aa = a.replace(/^#/, ''); + const bb = b.replace(/^#/, ''); if (aa < bb){ return -1; } if (aa > bb){ return 1; } return 0; @@ -15,7 +15,7 @@ const nonstandard = { } const mapper = (row) => { const columns = [row.alpha3, row.alpha2]; - var prefix = ''; + let prefix = ''; // comment-out synonyms where alpha2 is a prefix of alpha3 // if (row.alpha3.startsWith(row.alpha2)){ @@ -23,7 +23,7 @@ const mapper = (row) => { // } // add informal synonyms - var ns = _.get(nonstandard, columns[0]) + const ns = _.get(nonstandard, columns[0]); if (ns){ if (prefix === ''){ // set as 3rd synonym diff --git a/test/compile.js b/test/compile.js index b1d922ac..05b9109b 100644 --- a/test/compile.js +++ b/test/compile.js @@ -14,8 +14,8 @@ const forEachDeep = (obj, cb) => module.exports.tests = {}; -module.exports.tests.compile = function(test, common) { - test('valid schema file', function(t) { +module.exports.tests.compile = (test, common) => { + test('valid schema file', t => { t.equal(typeof schema, 'object', 'schema generated'); t.equal(Object.keys(schema).length>0, true, 'schema has body'); t.end(); @@ -25,8 +25,8 @@ module.exports.tests.compile = function(test, common) { // admin indices are explicitly specified in order to specify a custom // dynamic_template and to avoid 'type not found' errors when deploying // the api codebase against an index without admin data -module.exports.tests.indices = function(test, common) { - test('explicitly specify some admin indices and their analyzer', function(t) { +module.exports.tests.indices = (test, common) => { + test('explicitly specify some admin indices and their analyzer', t => { t.equal(typeof schema.mappings, 'object', 'mappings present'); t.equal(schema.mappings.dynamic_templates[0].nameGram.mapping.analyzer, 'peliasIndexOneEdgeGram'); t.end(); @@ -34,10 +34,10 @@ module.exports.tests.indices = function(test, common) { }; // some 'admin' types allow single edgeNGrams and so have a different dynamic_template -module.exports.tests.dynamic_templates = function(test, common) { - test('dynamic_templates: nameGram', function(t) { +module.exports.tests.dynamic_templates = (test, common) => { + test('dynamic_templates: nameGram', t => { t.equal(typeof schema.mappings.dynamic_templates[0].nameGram, 'object', 'nameGram template specified'); - var template = schema.mappings.dynamic_templates[0].nameGram; + const template = schema.mappings.dynamic_templates[0].nameGram; t.equal(template.path_match, 'name.*'); t.equal(template.match_mapping_type, 'string'); t.deepEqual(template.mapping, { @@ -48,9 +48,9 @@ module.exports.tests.dynamic_templates = function(test, common) { }); t.end(); }); - test('dynamic_templates: phrase', function (t) { + test('dynamic_templates: phrase', t => { t.equal(typeof schema.mappings.dynamic_templates[1].phrase, 'object', 'phrase template specified'); - var template = schema.mappings.dynamic_templates[1].phrase; + const template = schema.mappings.dynamic_templates[1].phrase; t.equal(template.path_match, 'phrase.*'); t.equal(template.match_mapping_type, 'string'); t.deepEqual(template.mapping, { @@ -61,9 +61,9 @@ module.exports.tests.dynamic_templates = function(test, common) { }); t.end(); }); - test('dynamic_templates: addendum', function (t) { + test('dynamic_templates: addendum', t => { t.equal(typeof schema.mappings.dynamic_templates[2].addendum, 'object', 'addendum template specified'); - var template = schema.mappings.dynamic_templates[2].addendum; + const template = schema.mappings.dynamic_templates[2].addendum; t.equal(template.path_match, 'addendum.*'); t.equal(template.match_mapping_type, 'string'); t.deepEqual(template.mapping, { @@ -76,8 +76,8 @@ module.exports.tests.dynamic_templates = function(test, common) { }; // ensure both "analyzer" and "search_analyzer" are set for stringy fields -module.exports.tests.analyzers = function (test, common) { - test('analyzers: ensure "analyzer" and "search_analyzer" are set', function (t) { +module.exports.tests.analyzers = (test, common) => { + test('analyzers: ensure "analyzer" and "search_analyzer" are set', t => { const stringyTypes = ['string', 'text']; const stringyFields = []; @@ -112,11 +112,11 @@ function overridePeliasConfig(value, cb) { // current schema (compiled) - requires schema to be copied and settings to // be regenerated from a fixture in order to pass in CI environments. -module.exports.tests.current_schema = function(test, common) { - test('current schema vs. fixture', function(t) { +module.exports.tests.current_schema = (test, common) => { + test('current schema vs. fixture', t => { // copy schema - var schemaCopy = JSON.parse( JSON.stringify( schema ) ); + const schemaCopy = JSON.parse( JSON.stringify( schema ) ); // use the pelias config fixture instead of the local config overridePeliasConfig(path.resolve( __dirname + '/fixtures/config.json' ), () => { @@ -135,10 +135,10 @@ module.exports.tests.current_schema = function(test, common) { t.end(); }); - test('current schema vs. fixture with ICU tokenizer', function(t) { + test('current schema vs. fixture with ICU tokenizer', t => { // copy schema - var schemaCopy = JSON.parse( JSON.stringify( schema ) ); + const schemaCopy = JSON.parse( JSON.stringify( schema ) ); // use the pelias config fixture instead of the local config overridePeliasConfig(path.resolve( __dirname + '/fixtures/config-icu-tokenizer.json' ), () => { @@ -158,13 +158,13 @@ module.exports.tests.current_schema = function(test, common) { }); }; -module.exports.all = function (tape, common) { +module.exports.all = (tape, common) => { function test(name, testFunction) { return tape('compile: ' + name, testFunction); } - for( var testCase in module.exports.tests ){ + for( const testCase in module.exports.tests ){ module.exports.tests[testCase](test, common); } }; diff --git a/test/configValidation.js b/test/configValidation.js index f5469b6a..66cb33d9 100644 --- a/test/configValidation.js +++ b/test/configValidation.js @@ -4,42 +4,42 @@ const configValidation = require('../configValidation'); module.exports.tests = {}; -module.exports.tests.interface = function(test, common) { - test('config without schema should throw error', function(t) { - var config = { +module.exports.tests.interface = (test, common) => { + test('config without schema should throw error', t => { + const config = { esclient: {} }; - t.throws(function() { + t.throws(() => { configValidation.validate(config); }, /"schema" is required/, 'schema should exist'); t.end(); }); - test('config without schema.indexName should throw error', function(t) { - var config = { + test('config without schema.indexName should throw error', t => { + const config = { schema: {}, esclient: {} }; - t.throws(function() { + t.throws(() => { configValidation.validate(config); }, /"schema.indexName" is required/, 'schema.indexName should exist'); t.end(); }); - test('config with non-string schema.indexName should throw error', function(t) { + test('config with non-string schema.indexName should throw error', t => { [null, 17, {}, [], false].forEach((value) => { - var config = { + const config = { schema: { indexName: value, }, esclient: {} }; - t.throws(function() { + t.throws(() => { configValidation.validate(config); }, /"schema.indexName" must be a string/, 'schema.indexName should be a string'); @@ -49,16 +49,16 @@ module.exports.tests.interface = function(test, common) { }); - test('config with non-object esclient should throw error', function(t) { + test('config with non-object esclient should throw error', t => { [null, 17, [], 'string', true].forEach((value) => { - var config = { + const config = { schema: { indexName: 'example_index', }, esclient: value }; - t.throws(function() { + t.throws(() => { configValidation.validate(config); }, /"esclient" must be of type object/, 'esclient should be an object'); @@ -68,15 +68,15 @@ module.exports.tests.interface = function(test, common) { }); - test('config with string schema.indexName and object esclient should not throw error', function(t) { - var config = { + test('config with string schema.indexName and object esclient should not throw error', t => { + const config = { schema: { indexName: 'example_index', }, esclient: {} }; - t.doesNotThrow(function() { + t.doesNotThrow(() => { configValidation.validate(config); }, 'no error should have been thrown'); @@ -86,13 +86,13 @@ module.exports.tests.interface = function(test, common) { }; -module.exports.all = function (tape, common) { +module.exports.all = (tape, common) => { function test(name, testFunction) { return tape('configValidation: ' + name, testFunction); } - for( var testCase in module.exports.tests ){ + for( const testCase in module.exports.tests ){ module.exports.tests[testCase](test, common); } }; diff --git a/test/document.js b/test/document.js index 81aed4aa..d004a685 100644 --- a/test/document.js +++ b/test/document.js @@ -3,8 +3,8 @@ const schema = require('../mappings/document'); module.exports.tests = {}; -module.exports.tests.compile = function(test, common) { - test('valid schema file', function(t) { +module.exports.tests.compile = (test, common) => { + test('valid schema file', t => { t.equal(typeof schema, 'object', 'schema generated'); t.equal(Object.keys(schema).length>0, true, 'schema has body'); t.end(); @@ -12,28 +12,28 @@ module.exports.tests.compile = function(test, common) { }; // properties should always be set -module.exports.tests.properties = function(test, common) { - test('has properties', function(t) { +module.exports.tests.properties = (test, common) => { + test('has properties', t => { t.equal(typeof schema.properties, 'object', 'properties specified'); t.end(); }); }; // should contain the correct field definitions -module.exports.tests.fields = function(test, common) { - var fields = ['source', 'layer', 'name', 'phrase', 'address_parts', +module.exports.tests.fields = (test, common) => { + const fields = ['source', 'layer', 'name', 'phrase', 'address_parts', 'parent', 'center_point', 'shape', 'bounding_box', 'source_id', 'category', 'population', 'popularity', 'addendum']; - test('fields specified', function(t) { + test('fields specified', t => { t.deepEqual(Object.keys(schema.properties), fields); t.end(); }); }; // should contain the correct address field definitions -module.exports.tests.address_fields = function(test, common) { - var fields = ['name','unit','number','street','cross_street','zip']; - test('address fields specified', function(t) { +module.exports.tests.address_fields = (test, common) => { + const fields = ['name','unit','number','street','cross_street','zip']; + test('address fields specified', t => { t.deepEqual(Object.keys(schema.properties.address_parts.properties), fields); t.end(); }); @@ -41,12 +41,12 @@ module.exports.tests.address_fields = function(test, common) { // address field analysis // ref: https://github.com/pelias/schema/pull/77 -module.exports.tests.address_analysis = function(test, common) { - var prop = schema.properties.address_parts.properties; +module.exports.tests.address_analysis = (test, common) => { + const prop = schema.properties.address_parts.properties; // $name analysis is pretty basic, work can be done to improve this, although // at time of writing this field was not used by any API queries. - test('name', function(t) { + test('name', t => { t.equal(prop.name.type, 'text'); t.equal(prop.name.analyzer, 'keyword'); t.equal(prop.name.search_analyzer, 'keyword'); @@ -54,7 +54,7 @@ module.exports.tests.address_analysis = function(test, common) { }); // $unit analysis - test('unit', function(t) { + test('unit', t => { t.equal(prop.unit.type, 'text', 'unit has full text type'); t.equal(prop.unit.analyzer, 'peliasUnit', 'unit analyzer is peliasUnit'); t.equal(prop.unit.search_analyzer, 'peliasUnit', 'unit search_analyzer is peliasUnit'); @@ -62,7 +62,7 @@ module.exports.tests.address_analysis = function(test, common) { }); // $number analysis is discussed in: https://github.com/pelias/schema/pull/77 - test('number', function(t) { + test('number', t => { t.equal(prop.number.type, 'text'); t.equal(prop.number.analyzer, 'peliasHousenumber'); t.equal(prop.number.search_analyzer, 'peliasHousenumber'); @@ -71,7 +71,7 @@ module.exports.tests.address_analysis = function(test, common) { // $street analysis is discussed in: https://github.com/pelias/schema/pull/77 // and https://github.com/pelias/api/pull/1444 - test('street', function(t) { + test('street', t => { t.equal(prop.street.type, 'text'); t.equal(prop.street.analyzer, 'peliasStreet'); t.equal(prop.street.search_analyzer, 'peliasQuery'); @@ -79,7 +79,7 @@ module.exports.tests.address_analysis = function(test, common) { }); // $cross_street analysis - test('cross_street', function (t) { + test('cross_street', t => { t.equal(prop.cross_street.type, 'text'); t.equal(prop.cross_street.analyzer, 'peliasStreet'); t.equal(prop.cross_street.search_analyzer, 'peliasQuery'); @@ -89,7 +89,7 @@ module.exports.tests.address_analysis = function(test, common) { // $zip analysis is discussed in: https://github.com/pelias/schema/pull/77 // note: this is a poor name, it would be better to rename this field to a more // generic term such as $postalcode as it is not specific to the USA. - test('zip', function(t) { + test('zip', t => { t.equal(prop.zip.type, 'text'); t.equal(prop.zip.analyzer, 'peliasZip'); t.equal(prop.zip.search_analyzer, 'peliasZip'); @@ -98,8 +98,8 @@ module.exports.tests.address_analysis = function(test, common) { }; // should contain the correct parent field definitions -module.exports.tests.parent_fields = function(test, common) { - var fields = [ +module.exports.tests.parent_fields = (test, common) => { + const fields = [ 'continent', 'continent_a', 'continent_id', 'continent.fields.ngram', 'ocean', 'ocean_a', 'ocean_id', 'ocean.fields.ngram', 'empire', 'empire_a', 'empire_id', 'empire.fields.ngram', @@ -116,7 +116,7 @@ module.exports.tests.parent_fields = function(test, common) { 'neighbourhood', 'neighbourhood_a', 'neighbourhood_id', 'neighbourhood.fields.ngram', 'postalcode', 'postalcode_a', 'postalcode_id', 'postalcode.fields.ngram' ]; - test('parent fields specified', function(t) { + test('parent fields specified', t => { fields.forEach( expected => { t.true( _.has( schema.properties.parent.properties, expected ), expected ); }); @@ -126,7 +126,7 @@ module.exports.tests.parent_fields = function(test, common) { // parent field analysis // ref: https://github.com/pelias/schema/pull/95 -module.exports.tests.parent_analysis = function(test, common) { +module.exports.tests.parent_analysis = (test, common) => { const prop = schema.properties.parent.properties; const fields = [ 'continent', 'ocean', 'empire', 'country', 'dependency', 'marinearea', @@ -134,15 +134,15 @@ module.exports.tests.parent_analysis = function(test, common) { 'localadmin', 'neighbourhood' ]; - fields.forEach( function( field ){ - test(field, function(t) { + fields.forEach( field => { + test(field, t => { // this is how the *default* analysis is currently set up across admin fields // note: we would like to move away from this to individual analyzers per-admin field. - var expectedFullTextIndexAnalyzer = 'peliasAdmin'; - var expectedFullTextSearchAnalyzer = 'peliasAdmin'; - var expectedNgramIndexAnalyzer = 'peliasIndexOneEdgeGram'; - var expectedNgramSearchAnalyzer = 'peliasAdmin'; + let expectedFullTextIndexAnalyzer = 'peliasAdmin'; + let expectedFullTextSearchAnalyzer = 'peliasAdmin'; + let expectedNgramIndexAnalyzer = 'peliasIndexOneEdgeGram'; + let expectedNgramSearchAnalyzer = 'peliasAdmin'; // id field t.equal(prop[field+'_id'].type, 'keyword', `${field}_id type is keyword`); @@ -185,7 +185,7 @@ module.exports.tests.parent_analysis = function(test, common) { }); }); - test('postalcode', function(t) { + test('postalcode', t => { t.equal(prop['postalcode'].type, 'text', 'postalcode is full text field'); t.equal(prop['postalcode'].analyzer, 'peliasZip', 'postalcode analyzer is peliasZip'); t.equal(prop['postalcode'].search_analyzer, 'peliasZip', 'postalcode analyzer is peliasZip'); @@ -199,10 +199,10 @@ module.exports.tests.parent_analysis = function(test, common) { }); }; -module.exports.tests.dynamic_templates = function(test, common) { - test('dynamic_templates: nameGram', function(t) { +module.exports.tests.dynamic_templates = (test, common) => { + test('dynamic_templates: nameGram', t => { t.equal(typeof schema.dynamic_templates[0].nameGram, 'object', 'nameGram template specified'); - var template = schema.dynamic_templates[0].nameGram; + const template = schema.dynamic_templates[0].nameGram; t.equal(template.path_match, 'name.*'); t.equal(template.match_mapping_type, 'string'); t.equal(template.mapping.type, 'text', 'set to full text type'); @@ -211,9 +211,9 @@ module.exports.tests.dynamic_templates = function(test, common) { t.equal(template.mapping.search_analyzer, 'peliasQuery', 'search_analyzer set'); t.end(); }); - test('dynamic_templates: phrase', function(t) { + test('dynamic_templates: phrase', t => { t.equal(typeof schema.dynamic_templates[1].phrase, 'object', 'phrase template specified'); - var template = schema.dynamic_templates[1].phrase; + const template = schema.dynamic_templates[1].phrase; t.equal(template.path_match, 'phrase.*'); t.equal(template.match_mapping_type, 'string'); t.equal(template.mapping.type, 'text', 'set to full text type'); @@ -225,8 +225,8 @@ module.exports.tests.dynamic_templates = function(test, common) { }; // _all should be disabled -module.exports.tests.all_disabled = function(test, common) { - test('_all disabled', function(t) { +module.exports.tests.all_disabled = (test, common) => { + test('_all disabled', t => { t.false(schema._all, '_all undefined'); t.end(); }); @@ -235,16 +235,16 @@ module.exports.tests.all_disabled = function(test, common) { // dynamic should be true in order for dynamic_templates to function properly // @see: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-dynamic-mapping.html // strict ensures extra fields cannot be added: https://www.elastic.co/guide/en/elasticsearch/guide/current/dynamic-mapping.html -module.exports.tests.dynamic_disabled = function(test, common) { - test('dynamic strict', function(t) { +module.exports.tests.dynamic_disabled = (test, common) => { + test('dynamic strict', t => { t.equal(schema.dynamic, 'strict', 'dynamic true'); t.end(); }); }; // shape field should be exluded from _source because it's massive -module.exports.tests._source = function(test, common) { - test('_source', function(t) { +module.exports.tests._source = (test, common) => { + test('_source', t => { t.ok(Array.isArray(schema._source.excludes), 'exclusions specified'); t.equal(schema._source.excludes[0], 'shape', 'exclude shape'); t.equal(schema._source.excludes[1], 'phrase', 'exclude phrase'); @@ -252,13 +252,13 @@ module.exports.tests._source = function(test, common) { }); }; -module.exports.all = function (tape, common) { +module.exports.all = (tape, common) => { function test(name, testFunction) { return tape('document: ' + name, testFunction); } - for( var testCase in module.exports.tests ){ + for( const testCase in module.exports.tests ){ module.exports.tests[testCase](test, common); } }; diff --git a/test/partial-admin.js b/test/partial-admin.js index 09f52d53..bee5ae6d 100644 --- a/test/partial-admin.js +++ b/test/partial-admin.js @@ -1,9 +1,9 @@ -var schema = require('../mappings/partial/admin'); +const schema = require('../mappings/partial/admin'); module.exports.tests = {}; -module.exports.tests.compile = function(test, common) { - test('valid schema file', function(t) { +module.exports.tests.compile = (test, common) => { + test('valid schema file', t => { t.equal(typeof schema, 'object', 'schema generated'); t.equal(Object.keys(schema).length>0, true, 'schema has body'); t.end(); @@ -11,23 +11,23 @@ module.exports.tests.compile = function(test, common) { }; // this should never need to change -module.exports.tests.type = function(test, common) { - test('correct type', function(t) { +module.exports.tests.type = (test, common) => { + test('correct type', t => { t.equal(schema.type, 'text', 'set to text field for full text search'); t.end(); }); }; -module.exports.tests.store = function(test, common) { - test('store unset (will not be stored)', function(t) { +module.exports.tests.store = (test, common) => { + test('store unset (will not be stored)', t => { t.equal(schema.store, undefined, 'unset'); t.end(); }); }; // this should be enabled to allow 'exists' filters to work -module.exports.tests.index = function(test, common) { - test('index enabled', function(t) { +module.exports.tests.index = (test, common) => { + test('index enabled', t => { t.notEqual(schema.index, 'no', 'should not be disabled'); t.end(); }); @@ -35,20 +35,20 @@ module.exports.tests.index = function(test, common) { // pelias analysis does not ensure that we get ['Great Britain'] instead of ['Great','Britain'] // TODO this needs to be addressed -module.exports.tests.analysis = function(test, common) { - test('index analysis', function(t) { +module.exports.tests.analysis = (test, common) => { + test('index analysis', t => { t.equal(schema.analyzer, 'peliasAdmin', 'should be peliasAdmin'); t.end(); }); }; -module.exports.all = function (tape, common) { +module.exports.all = (tape, common) => { function test(name, testFunction) { return tape('admin: ' + name, testFunction); } - for( var testCase in module.exports.tests ){ + for( const testCase in module.exports.tests ){ module.exports.tests[testCase](test, common); } }; diff --git a/test/partial-centroid.js b/test/partial-centroid.js index 0b745269..8c3d8d7f 100644 --- a/test/partial-centroid.js +++ b/test/partial-centroid.js @@ -1,10 +1,10 @@ -var schema = require('../mappings/partial/centroid'); +const schema = require('../mappings/partial/centroid'); module.exports.tests = {}; -module.exports.tests.compile = function(test, common) { - test('valid schema file', function(t) { +module.exports.tests.compile = (test, common) => { + test('valid schema file', t => { t.equal(typeof schema, 'object', 'schema generated'); t.equal(Object.keys(schema).length>0, true, 'schema has body'); t.end(); @@ -12,20 +12,20 @@ module.exports.tests.compile = function(test, common) { }; // this should never need to change -module.exports.tests.type = function(test, common) { - test('correct type', function(t) { +module.exports.tests.type = (test, common) => { + test('correct type', t => { t.equal(schema.type, 'geo_point', 'correct value'); t.end(); }); }; -module.exports.all = function (tape, common) { +module.exports.all = (tape, common) => { function test(name, testFunction) { return tape('centroid: ' + name, testFunction); } - for( var testCase in module.exports.tests ){ + for( const testCase in module.exports.tests ){ module.exports.tests[testCase](test, common); } }; diff --git a/test/partial-hash.js b/test/partial-hash.js index bb69261c..1338db8b 100644 --- a/test/partial-hash.js +++ b/test/partial-hash.js @@ -1,9 +1,9 @@ -var schema = require('../mappings/partial/hash'); +const schema = require('../mappings/partial/hash'); module.exports.tests = {}; -module.exports.tests.compile = function(test, common) { - test('valid schema file', function(t) { +module.exports.tests.compile = (test, common) => { + test('valid schema file', t => { t.equal(typeof schema, 'object', 'schema generated'); t.equal(Object.keys(schema).length>0, true, 'schema has body'); t.end(); @@ -11,8 +11,8 @@ module.exports.tests.compile = function(test, common) { }; // this should never need to change -module.exports.tests.type = function(test, common) { - test('correct type', function(t) { +module.exports.tests.type = (test, common) => { + test('correct type', t => { t.equal(schema.type, 'object', 'correct value'); t.end(); }); @@ -20,20 +20,20 @@ module.exports.tests.type = function(test, common) { // if dynamic=false you won't be able to // query the properties of the object! -module.exports.tests.dynamic = function(test, common) { - test('dynamic true', function(t) { +module.exports.tests.dynamic = (test, common) => { + test('dynamic true', t => { t.equal(schema.dynamic, true, 'correct value'); t.end(); }); }; -module.exports.all = function (tape, common) { +module.exports.all = (tape, common) => { function test(name, testFunction) { return tape('hash: ' + name, testFunction); } - for( var testCase in module.exports.tests ){ + for( const testCase in module.exports.tests ){ module.exports.tests[testCase](test, common); } }; diff --git a/test/partial-keyword.js b/test/partial-keyword.js index 03878009..62587cd3 100644 --- a/test/partial-keyword.js +++ b/test/partial-keyword.js @@ -1,9 +1,9 @@ -var schema = require('../mappings/partial/keyword'); +const schema = require('../mappings/partial/keyword'); module.exports.tests = {}; -module.exports.tests.compile = function(test, common) { - test('valid schema file', function(t) { +module.exports.tests.compile = (test, common) => { + test('valid schema file', t => { t.equal(typeof schema, 'object', 'schema generated'); t.equal(Object.keys(schema).length>0, true, 'schema has body'); t.end(); @@ -11,35 +11,35 @@ module.exports.tests.compile = function(test, common) { }; // this should never need to change -module.exports.tests.type = function(test, common) { - test('correct type', function(t) { +module.exports.tests.type = (test, common) => { + test('correct type', t => { t.equal(schema.type, 'keyword', 'correct value'); t.end(); }); }; -module.exports.tests.store = function(test, common) { - test('store unset (will not be stored)', function(t) { +module.exports.tests.store = (test, common) => { + test('store unset (will not be stored)', t => { t.equal(schema.store, undefined, 'unset'); t.end(); }); }; // do not perform analysis on categories -module.exports.tests.analysis = function(test, common) { - test('index analysis disabled', function(t) { +module.exports.tests.analysis = (test, common) => { + test('index analysis disabled', t => { t.equal(schema.index, undefined, 'should be set to default'); t.end(); }); }; -module.exports.all = function (tape, common) { +module.exports.all = (tape, common) => { function test(name, testFunction) { return tape('keyword: ' + name, testFunction); } - for( var testCase in module.exports.tests ){ + for( const testCase in module.exports.tests ){ module.exports.tests[testCase](test, common); } }; diff --git a/test/run.js b/test/run.js index 185d144f..37b5b3b0 100644 --- a/test/run.js +++ b/test/run.js @@ -1,14 +1,13 @@ -var tape = require('tape'), - diff = require('difflet')({ indent : 2, comment : true }); +const tape = require('tape'), diff = require('difflet')({ indent : 2, comment : true }); -var common = { +const common = { // a visual deep diff rendered using console.error() diff: function( actual, expected ){ console.error( diff.compare( actual, expected ) ); } }; -var tests = [ +const tests = [ require('./compile.js'), require('./document.js'), require('./partial-centroid.js'), @@ -20,6 +19,6 @@ var tests = [ require('./synonyms/parser.js'), ]; -tests.map(function(t) { +tests.map(t => { t.all(tape, common); }); diff --git a/test/settings.js b/test/settings.js index 37789dfd..dc95ac19 100644 --- a/test/settings.js +++ b/test/settings.js @@ -5,16 +5,16 @@ const path = require('path'), module.exports.tests = {}; -module.exports.tests.interface = function(test, common) { - test('valid interface', function(t) { +module.exports.tests.interface = (test, common) => { + test('valid interface', 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() { +module.exports.tests.configValidation = (test, common) => { + test('configValidation throwing error should rethrow', t => { + t.throws(() => { const proxyquire = require('proxyquire').noCallThru(); proxyquire('../settings', { './configValidation': { @@ -31,9 +31,9 @@ module.exports.tests.configValidation = function(test, common) { }); }; -module.exports.tests.compile = function(test, common) { - test('valid settings file', function(t) { - var s = settings(); +module.exports.tests.compile = (test, common) => { + test('valid settings file', t => { + const s = settings(); t.equal(typeof s, 'object', 'settings generated'); t.equal(Object.keys(s).length>0, true, 'settings has body'); t.end(); @@ -41,9 +41,9 @@ module.exports.tests.compile = function(test, common) { }; // analysis should always be set -module.exports.tests.analysis = function(test, common) { - test('has analysis settings', function(t) { - var s = settings(); +module.exports.tests.analysis = (test, common) => { + test('has analysis settings', t => { + const s = settings(); t.equal(typeof s.analysis, 'object', 'analysis specified'); t.end(); }); @@ -65,19 +65,19 @@ function mayBeAmpersandReplacer() { // -- analyzers -- -module.exports.tests.peliasAdminAnalyzer = function(test, common) { - test('has pelias admin analyzer', function(t) { - var s = settings(); +module.exports.tests.peliasAdminAnalyzer = (test, common) => { + test('has pelias admin analyzer', t => { + const s = settings(); t.equal(typeof s.analysis.analyzer.peliasAdmin, 'object', 'there is a pelias admin analyzer'); - var analyzer = s.analysis.analyzer.peliasAdmin; + const 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; + test('peliasAdmin token filters', t => { + const analyzer = settings().analysis.analyzer.peliasAdmin; t.deepEqual(analyzer.filter, [...mayBeAmpersandReplacer(), "lowercase", "trim", @@ -93,19 +93,19 @@ module.exports.tests.peliasAdminAnalyzer = function(test, common) { }); }; -module.exports.tests.peliasIndexOneEdgeGramAnalyzer = function(test, common) { - test('has peliasIndexOneEdgeGram analyzer', function(t) { - var s = settings(); +module.exports.tests.peliasIndexOneEdgeGramAnalyzer = (test, common) => { + test('has peliasIndexOneEdgeGram analyzer', t => { + const s = settings(); t.equal(typeof s.analysis.analyzer.peliasIndexOneEdgeGram, 'object', 'there is a peliasIndexOneEdgeGram analyzer'); - var analyzer = s.analysis.analyzer.peliasIndexOneEdgeGram; + const 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; + test('peliasIndexOneEdgeGram token filters', t => { + const analyzer = settings().analysis.analyzer.peliasIndexOneEdgeGram; t.deepEqual( analyzer.filter, [ ...mayBeAmpersandReplacer(), "lowercase", @@ -125,19 +125,19 @@ module.exports.tests.peliasIndexOneEdgeGramAnalyzer = function(test, common) { }); }; -module.exports.tests.peliasQueryAnalyzer = function (test, common) { - test('has peliasQuery analyzer', function (t) { - var s = settings(); +module.exports.tests.peliasQueryAnalyzer = (test, common) => { + test('has peliasQuery analyzer', t => { + const s = settings(); t.equal(typeof s.analysis.analyzer.peliasQuery, 'object', 'there is a peliasQuery analyzer'); - var analyzer = s.analysis.analyzer.peliasQuery; + const 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; + test('peliasQuery token filters', t => { + const analyzer = settings().analysis.analyzer.peliasQuery; t.deepEqual(analyzer.filter, [ ...mayBeAmpersandReplacer(), 'lowercase', @@ -151,19 +151,19 @@ module.exports.tests.peliasQueryAnalyzer = function (test, common) { }); }; -module.exports.tests.peliasPhraseAnalyzer = function(test, common) { - test('has peliasPhrase analyzer', function(t) { - var s = settings(); +module.exports.tests.peliasPhraseAnalyzer = (test, common) => { + test('has peliasPhrase analyzer', t => { + const s = settings(); t.equal(typeof s.analysis.analyzer.peliasPhrase, 'object', 'there is a peliasPhrase analyzer'); - var analyzer = s.analysis.analyzer.peliasPhrase; + const 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; + test('peliasPhrase token filters', t => { + const analyzer = settings().analysis.analyzer.peliasPhrase; t.deepEqual( analyzer.filter, [ ...mayBeAmpersandReplacer(), "lowercase", @@ -183,19 +183,19 @@ module.exports.tests.peliasPhraseAnalyzer = function(test, common) { }); }; -module.exports.tests.peliasZipAnalyzer = function(test, common) { - test('has peliasZip analyzer', function(t) { - var s = settings(); +module.exports.tests.peliasZipAnalyzer = (test, common) => { + test('has peliasZip analyzer', t => { + const s = settings(); t.equal(typeof s.analysis.analyzer.peliasZip, 'object', 'there is a peliasZip analyzer'); - var analyzer = s.analysis.analyzer.peliasZip; + const 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; + test('peliasZip token filters', t => { + const analyzer = settings().analysis.analyzer.peliasZip; t.deepEqual( analyzer.filter, [ "lowercase", "trim", @@ -207,19 +207,19 @@ module.exports.tests.peliasZipAnalyzer = function(test, common) { }); }; -module.exports.tests.peliasUnitAnalyzer = function(test, common) { - test('has peliasUnit analyzer', function(t) { - var s = settings(); +module.exports.tests.peliasUnitAnalyzer = (test, common) => { + test('has peliasUnit analyzer', t => { + const s = settings(); t.equal(typeof s.analysis.analyzer.peliasUnit, 'object', 'there is a peliasUnit analyzer'); - var analyzer = s.analysis.analyzer.peliasUnit; + const 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; + test('peliasUnit token filters', t => { + const analyzer = settings().analysis.analyzer.peliasUnit; t.deepEqual( analyzer.filter, [ "lowercase", "trim", @@ -231,11 +231,11 @@ module.exports.tests.peliasUnitAnalyzer = function(test, common) { }); }; -module.exports.tests.peliasHousenumberAnalyzer = function(test, common) { - test('has peliasHousenumber analyzer', function(t) { - var s = settings(); +module.exports.tests.peliasHousenumberAnalyzer = (test, common) => { + test('has peliasHousenumber analyzer', t => { + const s = settings(); t.equal(typeof s.analysis.analyzer.peliasHousenumber, 'object', 'there is a peliasHousenumber analyzer'); - var analyzer = s.analysis.analyzer.peliasHousenumber; + const 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'); @@ -244,19 +244,19 @@ module.exports.tests.peliasHousenumberAnalyzer = function(test, common) { }); }; -module.exports.tests.peliasStreetAnalyzer = function(test, common) { - test('has peliasStreet analyzer', function(t) { - var s = settings(); +module.exports.tests.peliasStreetAnalyzer = (test, common) => { + test('has peliasStreet analyzer', t => { + const s = settings(); t.equal(typeof s.analysis.analyzer.peliasStreet, 'object', 'there is a peliasStreet analyzer'); - var analyzer = s.analysis.analyzer.peliasStreet; + const 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; + test('peliasStreet token filters', t => { + const analyzer = settings().analysis.analyzer.peliasStreet; t.deepEqual( analyzer.filter, [...mayBeAmpersandReplacer(), "lowercase", "trim", @@ -274,19 +274,19 @@ module.exports.tests.peliasStreetAnalyzer = function(test, common) { }); }; -module.exports.tests.peliasIndexCountryAbbreviation = function (test, common) { - test('has peliasIndexCountryAbbreviation analyzer', function (t) { - var s = settings(); +module.exports.tests.peliasIndexCountryAbbreviation = (test, common) => { + test('has peliasIndexCountryAbbreviation analyzer', t => { + const s = settings(); t.equal(typeof s.analysis.analyzer.peliasIndexCountryAbbreviation, 'object', 'there is a peliasIndexCountryAbbreviation analyzer'); - var analyzer = s.analysis.analyzer.peliasIndexCountryAbbreviation; + const 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; + test('peliasIndexCountryAbbreviation token filters', t => { + const analyzer = settings().analysis.analyzer.peliasIndexCountryAbbreviation; t.deepEqual(analyzer.filter, [...mayBeAmpersandReplacer(), "lowercase", "trim", @@ -300,19 +300,19 @@ module.exports.tests.peliasIndexCountryAbbreviation = function (test, common) { }); }; -module.exports.tests.peliasIndexCountryAbbreviationOneEdgeGramAnalyzer = function (test, common) { - test('has peliasIndexCountryAbbreviationOneEdgeGram analyzer', function (t) { - var s = settings(); +module.exports.tests.peliasIndexCountryAbbreviationOneEdgeGramAnalyzer = (test, common) => { + test('has peliasIndexCountryAbbreviationOneEdgeGram analyzer', t => { + const s = settings(); t.equal(typeof s.analysis.analyzer.peliasIndexCountryAbbreviationOneEdgeGram, 'object', 'there is a peliasIndexCountryAbbreviationOneEdgeGram analyzer'); - var analyzer = s.analysis.analyzer.peliasIndexCountryAbbreviationOneEdgeGram; + const 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; + test('peliasIndexCountryAbbreviationOneEdgeGram token filters', t => { + const analyzer = settings().analysis.analyzer.peliasIndexCountryAbbreviationOneEdgeGram; t.deepEqual(analyzer.filter, [ ...mayBeAmpersandReplacer(), "lowercase", @@ -332,11 +332,11 @@ module.exports.tests.peliasIndexCountryAbbreviationOneEdgeGramAnalyzer = functio // 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(); +module.exports.tests.adminSynonymsMultiplexerFilter = (test, common) => { + test('has admin_synonyms_multiplexer filter', t => { + const 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; + const filter = s.analysis.filter.admin_synonyms_multiplexer; t.equal(filter.type, 'multiplexer'); t.deepEqual(filter.filters, [ 'synonyms/custom_admin', @@ -348,11 +348,11 @@ module.exports.tests.adminSynonymsMultiplexerFilter = function (test, common) { }; // 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(); +module.exports.tests.countryAbbreviationSynonymsMultiplexerFilter = (test, common) => { + test('has country_abbreviation_synonyms_multiplexer filter', t => { + const 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; + const filter = s.analysis.filter.country_abbreviation_synonyms_multiplexer; t.equal(filter.type, 'multiplexer'); t.deepEqual(filter.filters, [ 'synonyms/country_codes' @@ -363,11 +363,11 @@ module.exports.tests.countryAbbreviationSynonymsMultiplexerFilter = function (te // 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(); +module.exports.tests.nameSynonymsMultiplexerFilter = (test, common) => { + test('has name_synonyms_multiplexer filter', t => { + const 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; + const filter = s.analysis.filter.name_synonyms_multiplexer; t.equal(filter.type, 'multiplexer'); t.deepEqual(filter.filters, [ 'synonyms/custom_name', @@ -386,11 +386,11 @@ module.exports.tests.nameSynonymsMultiplexerFilter = function (test, common) { // 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(); +module.exports.tests.streetSynonymsMultiplexerFilter = (test, common) => { + test('has street_synonyms_multiplexer filter', t => { + const 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; + const filter = s.analysis.filter.street_synonyms_multiplexer; t.equal(filter.type, 'multiplexer'); t.deepEqual(filter.filters, [ 'synonyms/custom_street', @@ -404,17 +404,17 @@ module.exports.tests.streetSynonymsMultiplexerFilter = function (test, common) { }; // cycle through all analyzers and ensure the corrsponding token filters are globally defined -module.exports.tests.allTokenFiltersPresent = function(test, common) { - var ES_INBUILT_FILTERS = [ +module.exports.tests.allTokenFiltersPresent = (test, common) => { + const 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]; + test('all token filters present', t => { + const s = settings(); + for( const analyzerName in s.analysis.analyzer ){ + const analyzer = s.analysis.analyzer[analyzerName]; if( Array.isArray( analyzer.filter ) ){ - analyzer.filter.forEach( function( tokenFilterName ){ - var filterExists = ( + analyzer.filter.forEach( tokenFilterName => { + const filterExists = ( s.analysis.filter.hasOwnProperty( tokenFilterName ) || ES_INBUILT_FILTERS.includes( tokenFilterName ) ); @@ -427,16 +427,16 @@ 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 = [ +module.exports.tests.mandatoryTokenFiltersPresent = (test, common) => { + const 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]; + test('mandatory filters present', t => { + const s = settings(); + for (const analyzerName in s.analysis.analyzer) { + const analyzer = s.analysis.analyzer[analyzerName]; if (Array.isArray(analyzer.filter)) { - MANDATORY_FILTERS.forEach(function (filterName) { + MANDATORY_FILTERS.forEach(filterName => { t.true( analyzer.filter.includes(filterName), `mandatory token filter ${filterName} not defined on ${analyzerName}` @@ -449,16 +449,16 @@ module.exports.tests.mandatoryTokenFiltersPresent = function (test, common) { }; // 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]; +module.exports.tests.allCharacterFiltersPresent = (test, common) => { + const ES_INBUILT_FILTERS = []; + test('all character filters present', t => { + const s = settings(); + for( const analyzerName in s.analysis.analyzer ){ + const 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 ) ){ + analyzer.char_filter.forEach( charFilterName => { + let filterExists = s.analysis.char_filter.hasOwnProperty( charFilterName ); + if( !filterExists && ES_INBUILT_FILTERS.includes(charFilterName) ){ filterExists = true; } t.true( filterExists, 'missing character filter: ' + charFilterName ); @@ -473,11 +473,11 @@ module.exports.tests.allCharacterFiltersPresent = function(test, common) { // 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(); +module.exports.tests.punctuationFilter = (test, common) => { + test('has punctuation filter', t => { + const s = settings(); t.equal(typeof s.analysis.filter['synonyms/punctuation'], 'object', 'there is a punctuation filter'); - var filter = s.analysis.filter['synonyms/punctuation']; + const filter = s.analysis.filter['synonyms/punctuation']; t.equal(filter.type, 'synonym'); t.deepEqual(filter.synonyms, [ "&,and", @@ -489,11 +489,11 @@ module.exports.tests.punctuationFilter = function(test, common) { // 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(); +module.exports.tests.notnullFilter = (test, common) => { + test('has notnull filter', t => { + const s = settings(); t.equal(typeof s.analysis.filter.notnull, 'object', 'there is a notnull filter'); - var filter = s.analysis.filter.notnull; + const filter = s.analysis.filter.notnull; t.equal(filter.type, 'length'); t.equal(filter.min, 1); t.end(); @@ -501,11 +501,11 @@ module.exports.tests.notnullFilter = function(test, common) { }; // 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(); +module.exports.tests.peliasOneEdgeGramFilter = (test, common) => { + test('has peliasIndexOneEdgeGram filter', t => { + const s = settings(); t.equal(typeof s.analysis.filter.peliasOneEdgeGramFilter, 'object', 'there is a peliasIndexOneEdgeGram filter'); - var filter = s.analysis.filter.peliasOneEdgeGramFilter; + const filter = s.analysis.filter.peliasOneEdgeGramFilter; t.equal(filter.type, 'edge_ngram'); t.equal(filter.min_gram, 1); t.equal(filter.max_gram, 24); @@ -515,11 +515,11 @@ module.exports.tests.peliasOneEdgeGramFilter = function(test, common) { // 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(); +module.exports.tests.streetSynonymFilter = (test, common) => { + test('has synonyms/streets filter', t => { + const s = settings(); t.equal(typeof s.analysis.filter['synonyms/streets'], 'object', 'there is a synonyms/streets filter'); - var filter = s.analysis.filter['synonyms/streets']; + const filter = s.analysis.filter['synonyms/streets']; t.equal(filter.type, 'synonym'); t.true(Array.isArray(filter.synonyms)); t.equal(filter.synonyms.length, 809); @@ -529,11 +529,11 @@ module.exports.tests.streetSynonymFilter = function(test, common) { // 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(); +module.exports.tests.directionalSynonymFilter = (test, common) => { + test('has directionals filter', t => { + const s = settings(); t.equal(typeof s.analysis.filter['synonyms/directionals'], 'object', 'there is a synonyms/directionals filter'); - var filter = s.analysis.filter['synonyms/directionals']; + const filter = s.analysis.filter['synonyms/directionals']; t.equal(filter.type, 'synonym'); t.true(Array.isArray(filter.synonyms)); t.equal(filter.synonyms.length, 69); @@ -543,11 +543,11 @@ module.exports.tests.directionalSynonymFilter = function(test, common) { // 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(); +module.exports.tests.personalTitleSynonymFilter = (test, common) => { + test('has personal_titles filter', t => { + const 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']; + const filter = s.analysis.filter['synonyms/personal_titles']; t.equal(filter.type, 'synonym'); t.true(Array.isArray(filter.synonyms)); t.equal(filter.synonyms.length, 191); @@ -557,11 +557,11 @@ module.exports.tests.personalTitleSynonymFilter = function (test, common) { // 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(); +module.exports.tests.placeNameSynonymFilter = (test, common) => { + test('has place_names filter', t => { + const 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']; + const filter = s.analysis.filter['synonyms/place_names']; t.equal(filter.type, 'synonym'); t.true(Array.isArray(filter.synonyms)); t.equal(filter.synonyms.length, 314); @@ -571,11 +571,11 @@ module.exports.tests.placeNameSynonymFilter = function (test, common) { // 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(); +module.exports.tests.removeOrdinalsFilter = (test, common) => { + test('has remove_ordinals filter', t => { + const s = settings(); t.equal(typeof s.analysis.filter.remove_ordinals, 'object', 'there is an remove_ordinals filter'); - var filter = s.analysis.filter.remove_ordinals; + const 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'); @@ -587,11 +587,11 @@ module.exports.tests.removeOrdinalsFilter = function(test, common) { // 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(); +module.exports.tests.punctuationCharFilter = (test, common) => { + test('has punctuation char_filter', t => { + const 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; + const 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); @@ -600,11 +600,11 @@ module.exports.tests.punctuationCharFilter = function(test, common) { }; // remove non alphanumeric characters -module.exports.tests.alphanumericCharFilter = function(test, common) { - test('has alphanumeric char_filter', function(t) { - var s = settings(); +module.exports.tests.alphanumericCharFilter = (test, common) => { + test('has alphanumeric char_filter', t => { + const 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; + const 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, ''); @@ -613,11 +613,11 @@ module.exports.tests.alphanumericCharFilter = function(test, common) { }; // replace non-numeric chars with a space -module.exports.tests.numericCharFilter = function(test, common) { - test('has numeric char_filter', function(t) { - var s = settings(); +module.exports.tests.numericCharFilter = (test, common) => { + test('has numeric char_filter', t => { + const 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; + const 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, ' '); @@ -627,11 +627,11 @@ module.exports.tests.numericCharFilter = function(test, common) { // 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(); +module.exports.tests.britishAmericanEnglishSynonymFilter = (test, common) => { + test('has british_american_english filter', t => { + const 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']; + const 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); @@ -642,9 +642,9 @@ module.exports.tests.britishAmericanEnglishSynonymFilter = function (test, commo // -- etc -- // index should always be set -module.exports.tests.index = function(test, common) { - test('has index settings', function(t) { - var s = settings(); +module.exports.tests.index = (test, common) => { + test('has index settings', t => { + const 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'); @@ -653,12 +653,12 @@ module.exports.tests.index = function(test, common) { }; // allow overrides from pelias/config -module.exports.tests.overrides = function(test, common) { - test('override defaults', function(t) { +module.exports.tests.overrides = (test, common) => { + test('override defaults', t => { process.env['PELIAS_CONFIG'] = path.resolve(__dirname + '/fixtures/empty.json'); - var s = settings(); + let s = settings(); t.equal(s.index['number_of_replicas'], '0', 'unchanged'); // set the PELIAS_CONFIG env var @@ -671,11 +671,11 @@ module.exports.tests.overrides = function(test, common) { // unset the PELIAS_CONFIG env var delete process.env['PELIAS_CONFIG']; }); - test('override similarity', function (t) { + test('override similarity', t => { process.env['PELIAS_CONFIG'] = path.resolve(__dirname + '/fixtures/empty.json'); - var s = settings(); + let s = settings(); t.equal(s.index.similarity.peliasDefaultSimilarity.k1, 1.2, 'unchanged'); // set the PELIAS_CONFIG env var @@ -691,13 +691,13 @@ module.exports.tests.overrides = function(test, common) { }); }; -module.exports.all = function (tape, common) { +module.exports.all = (tape, common) => { function test(name, testFunction) { return tape('settings: ' + name, testFunction); } - for( var testCase in module.exports.tests ){ + for( const testCase in module.exports.tests ){ module.exports.tests[testCase](test, common); } }; diff --git a/test/synonyms/parser.js b/test/synonyms/parser.js index 6ce2d201..cd46acaf 100644 --- a/test/synonyms/parser.js +++ b/test/synonyms/parser.js @@ -2,20 +2,20 @@ const parser = require('../../synonyms/parser'); module.exports.tests = {}; -module.exports.tests.load = function(test, common) { - test('load: invalid file', function(t) { +module.exports.tests.load = (test, common) => { + test('load: invalid file', t => { t.throws(() => parser('/invalid/path'), /file not found/, 'invalid file'); t.throws(() => parser('/tmp'), /file not found/, 'directory'); t.end(); }); }; -module.exports.tests.parse = function(test, common) { - test('empty file', function(t) { +module.exports.tests.parse = (test, common) => { + test('empty file', t => { t.deepEqual( parser.parse(``), [] ); t.end(); }); - test('comments and newlines', function(t) { + test('comments and newlines', t => { t.deepEqual( parser.parse(` # foo bar @@ -25,7 +25,7 @@ module.exports.tests.parse = function(test, common) { `), [] ); t.end(); }); - test('lowercase', function(t) { + test('lowercase', t => { t.deepEqual( parser.parse(` Foo => BaR Foo,Bar,Baz @@ -35,7 +35,7 @@ Foo,Bar,Baz ] ); t.end(); }); - test('squash spaces', function(t) { + test('squash spaces', t => { t.deepEqual( parser.parse(` foo bar => foo Foo Bar, Foo @@ -45,7 +45,7 @@ Foo Bar, Foo ] ); t.end(); }); - test('trim commas', function(t) { + test('trim commas', t => { t.deepEqual( parser.parse(` ,foo => bar ,foo, bar, @@ -55,7 +55,7 @@ Foo Bar, Foo ] ); t.end(); }); - test('trim around commas', function(t) { + test('trim around commas', t => { t.deepEqual( parser.parse(` ,foo, bar , baz `), [ @@ -63,7 +63,7 @@ Foo Bar, Foo ] ); t.end(); }); - test('trim around arrows', function(t) { + test('trim around arrows', t => { t.deepEqual( parser.parse(` foo => bar `), [ @@ -73,13 +73,13 @@ Foo Bar, Foo }); }; -module.exports.all = function (tape, common) { +module.exports.all = (tape, common) => { function test(name, testFunction) { return tape('synonyms parser: ' + name, testFunction); } - for( var testCase in module.exports.tests ){ + for( const testCase in module.exports.tests ){ module.exports.tests[testCase](test, common); } }; From 5b11d82521b0e866aba3e6ba5901cd7aea3aa991 Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Sat, 1 Mar 2025 18:23:50 +0100 Subject: [PATCH 2/3] Modernize codebase --- scripts/list_analyzers.js | 6 +++--- test/compile.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/list_analyzers.js b/scripts/list_analyzers.js index 6adaffa9..04abf53d 100644 --- a/scripts/list_analyzers.js +++ b/scripts/list_analyzers.js @@ -83,14 +83,14 @@ const property = (prop, field) => { // more than one dynamic template matches } else if (matches.length > 1) { error({ - field: field, + field, message: 'multiple dynamic_templates matched' }) // no properties object or dynamic template matched } else { error({ - field: field, + field, message: 'missing object properties' }) } @@ -98,7 +98,7 @@ const property = (prop, field) => { } else { // scalar property definition print({ - field: field, + field, type: prop.type, analyzer: prop.analyzer || defaultAnalyzerFor(prop), search_analyzer: prop.search_analyzer || prop.analyzer || defaultAnalyzerFor(prop), diff --git a/test/compile.js b/test/compile.js index 05b9109b..c77d7e13 100644 --- a/test/compile.js +++ b/test/compile.js @@ -85,7 +85,7 @@ module.exports.tests.analyzers = (test, common) => { forEachDeep(schema, (value, key) => { if (!_.isPlainObject(value)) { return; } if (!stringyTypes.includes(_.get(value, 'type', ''))) { return; } - stringyFields.push({ key: key, value: value }); + stringyFields.push({ key, value }); }); stringyFields.forEach(field => { From 0a3786ad486abdd4aa30f41dae24563d58763d21 Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Sat, 1 Mar 2025 18:26:39 +0100 Subject: [PATCH 3/3] Use string template where possible --- settings.js | 2 +- test/compile.js | 6 +++--- test/configValidation.js | 2 +- test/document.js | 22 +++++++++++----------- test/elastictest/Suite.js | 2 +- test/partial-admin.js | 2 +- test/partial-centroid.js | 2 +- test/partial-hash.js | 2 +- test/partial-keyword.js | 2 +- test/settings.js | 14 +++++++------- test/synonyms/parser.js | 2 +- 11 files changed, 29 insertions(+), 29 deletions(-) diff --git a/settings.js b/settings.js index 5208e4fb..2323edc6 100644 --- a/settings.js +++ b/settings.js @@ -243,7 +243,7 @@ function generate(){ "char_filter": { "punctuation" : { "type" : "mapping", - "mappings" : punctuation.blacklist.map(c => c + '=>') + "mappings" : punctuation.blacklist.map(c => `${c}=>`) }, "alphanumeric" : { "type" : "pattern_replace", diff --git a/test/compile.js b/test/compile.js index c77d7e13..921c4dd6 100644 --- a/test/compile.js +++ b/test/compile.js @@ -119,7 +119,7 @@ module.exports.tests.current_schema = (test, common) => { const schemaCopy = JSON.parse( JSON.stringify( schema ) ); // use the pelias config fixture instead of the local config - overridePeliasConfig(path.resolve( __dirname + '/fixtures/config.json' ), () => { + overridePeliasConfig(path.resolve( `${__dirname}/fixtures/config.json` ), () => { schemaCopy.settings = require('../settings')(); }); @@ -141,7 +141,7 @@ module.exports.tests.current_schema = (test, common) => { const schemaCopy = JSON.parse( JSON.stringify( schema ) ); // use the pelias config fixture instead of the local config - overridePeliasConfig(path.resolve( __dirname + '/fixtures/config-icu-tokenizer.json' ), () => { + overridePeliasConfig(path.resolve( `${__dirname}/fixtures/config-icu-tokenizer.json` ), () => { schemaCopy.settings = require('../settings')(); }); @@ -161,7 +161,7 @@ module.exports.tests.current_schema = (test, common) => { module.exports.all = (tape, common) => { function test(name, testFunction) { - return tape('compile: ' + name, testFunction); + return tape(`compile: ${name}`, testFunction); } for( const testCase in module.exports.tests ){ diff --git a/test/configValidation.js b/test/configValidation.js index 66cb33d9..fa7b5b88 100644 --- a/test/configValidation.js +++ b/test/configValidation.js @@ -89,7 +89,7 @@ module.exports.tests.interface = (test, common) => { module.exports.all = (tape, common) => { function test(name, testFunction) { - return tape('configValidation: ' + name, testFunction); + return tape(`configValidation: ${name}`, testFunction); } for( const testCase in module.exports.tests ){ diff --git a/test/document.js b/test/document.js index d004a685..6c9ddb1e 100644 --- a/test/document.js +++ b/test/document.js @@ -145,12 +145,12 @@ module.exports.tests.parent_analysis = (test, common) => { let expectedNgramSearchAnalyzer = 'peliasAdmin'; // id field - t.equal(prop[field+'_id'].type, 'keyword', `${field}_id type is keyword`); - t.equal(prop[field+'_id'].index, undefined, `${field}_id index left at default`); + t.equal(prop[`${field}_id`].type, 'keyword', `${field}_id type is keyword`); + t.equal(prop[`${field}_id`].index, undefined, `${field}_id index left at default`); // source field - t.equal(prop[field + '_source'].type, 'keyword', `${field}_source type is keyword`); - t.equal(prop[field + '_source'].index, undefined, `${field}_source index left at default`); + t.equal(prop[`${field}_source`].type, 'keyword', `${field}_source type is keyword`); + t.equal(prop[`${field}_source`].index, undefined, `${field}_source index left at default`); // fulltext field eg. parent.region t.equal(prop[field].type, 'text', `${field} is set to text type`); @@ -172,14 +172,14 @@ module.exports.tests.parent_analysis = (test, common) => { } // abbreviaton - t.equal(prop[field + '_a'].type, 'text', `${field}_a type is text`); - t.equal(prop[field + '_a'].analyzer, expectedFullTextIndexAnalyzer, `${field}_a analyzer`); - t.equal(prop[field + '_a'].search_analyzer, expectedFullTextSearchAnalyzer, `${field}_a analyzer`); + t.equal(prop[`${field}_a`].type, 'text', `${field}_a type is text`); + t.equal(prop[`${field}_a`].analyzer, expectedFullTextIndexAnalyzer, `${field}_a analyzer`); + t.equal(prop[`${field}_a`].search_analyzer, expectedFullTextSearchAnalyzer, `${field}_a analyzer`); // abbreviaton ngram subfield - t.equal(prop[field + '_a'].fields.ngram.type, 'text', `${field}_a.ngram type is full text`); - t.equal(prop[field + '_a'].fields.ngram.analyzer, expectedNgramIndexAnalyzer, `${field}_a.ngram analyzer`); - t.equal(prop[field + '_a'].fields.ngram.search_analyzer, expectedNgramSearchAnalyzer, `${field}_a.ngram analyzer`); + t.equal(prop[`${field}_a`].fields.ngram.type, 'text', `${field}_a.ngram type is full text`); + t.equal(prop[`${field}_a`].fields.ngram.analyzer, expectedNgramIndexAnalyzer, `${field}_a.ngram analyzer`); + t.equal(prop[`${field}_a`].fields.ngram.search_analyzer, expectedNgramSearchAnalyzer, `${field}_a.ngram analyzer`); t.end(); }); @@ -255,7 +255,7 @@ module.exports.tests._source = (test, common) => { module.exports.all = (tape, common) => { function test(name, testFunction) { - return tape('document: ' + name, testFunction); + return tape(`document: ${name}`, testFunction); } for( const testCase in module.exports.tests ){ diff --git a/test/elastictest/Suite.js b/test/elastictest/Suite.js index 6a52ba68..16114615 100644 --- a/test/elastictest/Suite.js +++ b/test/elastictest/Suite.js @@ -13,7 +13,7 @@ function Suite (clientOpts, props) { }) this.props = props || {} if (!_.has(this, 'props.index')) { - this.props.index = 'testindex-' + randomstring.generate(7).toLowerCase() + this.props.index = `testindex-${randomstring.generate(7).toLowerCase()}` } } diff --git a/test/partial-admin.js b/test/partial-admin.js index bee5ae6d..bdb094a8 100644 --- a/test/partial-admin.js +++ b/test/partial-admin.js @@ -45,7 +45,7 @@ module.exports.tests.analysis = (test, common) => { module.exports.all = (tape, common) => { function test(name, testFunction) { - return tape('admin: ' + name, testFunction); + return tape(`admin: ${name}`, testFunction); } for( const testCase in module.exports.tests ){ diff --git a/test/partial-centroid.js b/test/partial-centroid.js index 8c3d8d7f..7fff502f 100644 --- a/test/partial-centroid.js +++ b/test/partial-centroid.js @@ -22,7 +22,7 @@ module.exports.tests.type = (test, common) => { module.exports.all = (tape, common) => { function test(name, testFunction) { - return tape('centroid: ' + name, testFunction); + return tape(`centroid: ${name}`, testFunction); } for( const testCase in module.exports.tests ){ diff --git a/test/partial-hash.js b/test/partial-hash.js index 1338db8b..e6df5319 100644 --- a/test/partial-hash.js +++ b/test/partial-hash.js @@ -30,7 +30,7 @@ module.exports.tests.dynamic = (test, common) => { module.exports.all = (tape, common) => { function test(name, testFunction) { - return tape('hash: ' + name, testFunction); + return tape(`hash: ${name}`, testFunction); } for( const testCase in module.exports.tests ){ diff --git a/test/partial-keyword.js b/test/partial-keyword.js index 62587cd3..fce32d48 100644 --- a/test/partial-keyword.js +++ b/test/partial-keyword.js @@ -36,7 +36,7 @@ module.exports.tests.analysis = (test, common) => { module.exports.all = (tape, common) => { function test(name, testFunction) { - return tape('keyword: ' + name, testFunction); + return tape(`keyword: ${name}`, testFunction); } for( const testCase in module.exports.tests ){ diff --git a/test/settings.js b/test/settings.js index dc95ac19..3d175d21 100644 --- a/test/settings.js +++ b/test/settings.js @@ -418,7 +418,7 @@ module.exports.tests.allTokenFiltersPresent = (test, common) => { s.analysis.filter.hasOwnProperty( tokenFilterName ) || ES_INBUILT_FILTERS.includes( tokenFilterName ) ); - t.true( filterExists, 'token filter exists: ' + tokenFilterName ); + t.true( filterExists, `token filter exists: ${tokenFilterName}` ); }); } } @@ -461,7 +461,7 @@ module.exports.tests.allCharacterFiltersPresent = (test, common) => { if( !filterExists && ES_INBUILT_FILTERS.includes(charFilterName) ){ filterExists = true; } - t.true( filterExists, 'missing character filter: ' + charFilterName ); + t.true( filterExists, `missing character filter: ${charFilterName}` ); }); } } @@ -656,13 +656,13 @@ module.exports.tests.index = (test, common) => { module.exports.tests.overrides = (test, common) => { test('override defaults', t => { - process.env['PELIAS_CONFIG'] = path.resolve(__dirname + '/fixtures/empty.json'); + process.env['PELIAS_CONFIG'] = path.resolve(`${__dirname}/fixtures/empty.json`); let 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' ); + process.env['PELIAS_CONFIG'] = path.resolve( `${__dirname}/fixtures/config.json` ); s = settings(); t.equal(s.index['number_of_replicas'], '999', 'changed'); @@ -673,13 +673,13 @@ module.exports.tests.overrides = (test, common) => { }); test('override similarity', t => { - process.env['PELIAS_CONFIG'] = path.resolve(__dirname + '/fixtures/empty.json'); + process.env['PELIAS_CONFIG'] = path.resolve(`${__dirname}/fixtures/empty.json`); let 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'); + process.env['PELIAS_CONFIG'] = path.resolve(`${__dirname}/fixtures/similarity.json`); s = settings(); t.equal(s.index.similarity.peliasDefaultSimilarity.k1, 0, 'changed'); @@ -694,7 +694,7 @@ module.exports.tests.overrides = (test, common) => { module.exports.all = (tape, common) => { function test(name, testFunction) { - return tape('settings: ' + name, testFunction); + return tape(`settings: ${name}`, testFunction); } for( const testCase in module.exports.tests ){ diff --git a/test/synonyms/parser.js b/test/synonyms/parser.js index cd46acaf..2dd1ae05 100644 --- a/test/synonyms/parser.js +++ b/test/synonyms/parser.js @@ -76,7 +76,7 @@ Foo Bar, Foo module.exports.all = (tape, common) => { function test(name, testFunction) { - return tape('synonyms parser: ' + name, testFunction); + return tape(`synonyms parser: ${name}`, testFunction); } for( const testCase in module.exports.tests ){