From c89f97a033e1e63703eed2418d8f44e67c3bb9bf Mon Sep 17 00:00:00 2001 From: sweco-semhul Date: Fri, 27 Oct 2017 12:45:27 +0200 Subject: [PATCH] Adding mappings for unit attribute and tests for it --- mappings/document.js | 4 +++ settings.js | 9 +++++ test/document.js | 9 ++++- test/fixtures/expected.json | 71 +++++++++++++++++++++++++++++++++++++ test/settings.js | 21 +++++++++++ 5 files changed, 113 insertions(+), 1 deletion(-) diff --git a/mappings/document.js b/mappings/document.js index 9e7f5cf2..0189e1d7 100644 --- a/mappings/document.js +++ b/mappings/document.js @@ -27,6 +27,10 @@ var schema = { type: 'string', analyzer: 'keyword', }, + unit: { + type: 'string', + analyzer: 'peliasUnit', + }, number: { type: 'string', analyzer: 'peliasHousenumber', diff --git a/settings.js b/settings.js index a2eaec7a..db0a3d9a 100644 --- a/settings.js +++ b/settings.js @@ -117,6 +117,15 @@ function generate(){ "trim" ] }, + "peliasUnit": { + "type": "custom", + "tokenizer":"keyword", + "char_filter" : ["alphanumeric"], + "filter": [ + "lowercase", + "trim" + ] + }, "peliasHousenumber": { "type": "custom", "tokenizer":"standard", diff --git a/test/document.js b/test/document.js index c57b818f..03a39d0e 100644 --- a/test/document.js +++ b/test/document.js @@ -31,7 +31,7 @@ module.exports.tests.fields = function(test, common) { // should contain the correct address field definitions module.exports.tests.address_fields = function(test, common) { - var fields = ['name','number','street','zip']; + var fields = ['name','unit','number','street','zip']; test('address fields specified', function(t) { t.deepEqual(Object.keys(schema.properties.address_parts.properties), fields); t.end(); @@ -51,6 +51,13 @@ module.exports.tests.address_analysis = function(test, common) { t.end(); }); + // $unit analysis + test('unit', function(t) { + t.equal(prop.unit.type, 'string'); + t.equal(prop.unit.analyzer, 'peliasUnit'); + t.end(); + }); + // $number analysis is discussed in: https://github.com/pelias/schema/pull/77 test('number', function(t) { t.equal(prop.number.type, 'string'); diff --git a/test/fixtures/expected.json b/test/fixtures/expected.json index 6fbd5a8b..6649b2c4 100644 --- a/test/fixtures/expected.json +++ b/test/fixtures/expected.json @@ -120,6 +120,17 @@ "trim" ] }, + "peliasUnit": { + "type": "custom", + "tokenizer": "keyword", + "char_filter": [ + "alphanumeric" + ], + "filter": [ + "lowercase", + "trim" + ] + }, "peliasHousenumber": { "type": "custom", "tokenizer": "standard", @@ -1576,6 +1587,10 @@ "type": "string", "analyzer": "keyword" }, + "unit": { + "type": "string", + "analyzer": "peliasUnit" + }, "number": { "type": "string", "analyzer": "peliasHousenumber" @@ -1869,6 +1884,10 @@ "type": "string", "analyzer": "keyword" }, + "unit": { + "type": "string", + "analyzer": "peliasUnit" + }, "number": { "type": "string", "analyzer": "peliasHousenumber" @@ -2162,6 +2181,10 @@ "type": "string", "analyzer": "keyword" }, + "unit": { + "type": "string", + "analyzer": "peliasUnit" + }, "number": { "type": "string", "analyzer": "peliasHousenumber" @@ -2455,6 +2478,10 @@ "type": "string", "analyzer": "keyword" }, + "unit": { + "type": "string", + "analyzer": "peliasUnit" + }, "number": { "type": "string", "analyzer": "peliasHousenumber" @@ -2748,6 +2775,10 @@ "type": "string", "analyzer": "keyword" }, + "unit": { + "type": "string", + "analyzer": "peliasUnit" + }, "number": { "type": "string", "analyzer": "peliasHousenumber" @@ -3041,6 +3072,10 @@ "type": "string", "analyzer": "keyword" }, + "unit": { + "type": "string", + "analyzer": "peliasUnit" + }, "number": { "type": "string", "analyzer": "peliasHousenumber" @@ -3334,6 +3369,10 @@ "type": "string", "analyzer": "keyword" }, + "unit": { + "type": "string", + "analyzer": "peliasUnit" + }, "number": { "type": "string", "analyzer": "peliasHousenumber" @@ -3627,6 +3666,10 @@ "type": "string", "analyzer": "keyword" }, + "unit": { + "type": "string", + "analyzer": "peliasUnit" + }, "number": { "type": "string", "analyzer": "peliasHousenumber" @@ -3920,6 +3963,10 @@ "type": "string", "analyzer": "keyword" }, + "unit": { + "type": "string", + "analyzer": "peliasUnit" + }, "number": { "type": "string", "analyzer": "peliasHousenumber" @@ -4213,6 +4260,10 @@ "type": "string", "analyzer": "keyword" }, + "unit": { + "type": "string", + "analyzer": "peliasUnit" + }, "number": { "type": "string", "analyzer": "peliasHousenumber" @@ -4506,6 +4557,10 @@ "type": "string", "analyzer": "keyword" }, + "unit": { + "type": "string", + "analyzer": "peliasUnit" + }, "number": { "type": "string", "analyzer": "peliasHousenumber" @@ -4799,6 +4854,10 @@ "type": "string", "analyzer": "keyword" }, + "unit": { + "type": "string", + "analyzer": "peliasUnit" + }, "number": { "type": "string", "analyzer": "peliasHousenumber" @@ -5092,6 +5151,10 @@ "type": "string", "analyzer": "keyword" }, + "unit": { + "type": "string", + "analyzer": "peliasUnit" + }, "number": { "type": "string", "analyzer": "peliasHousenumber" @@ -5385,6 +5448,10 @@ "type": "string", "analyzer": "keyword" }, + "unit": { + "type": "string", + "analyzer": "peliasUnit" + }, "number": { "type": "string", "analyzer": "peliasHousenumber" @@ -5678,6 +5745,10 @@ "type": "string", "analyzer": "keyword" }, + "unit": { + "type": "string", + "analyzer": "peliasUnit" + }, "number": { "type": "string", "analyzer": "peliasHousenumber" diff --git a/test/settings.js b/test/settings.js index d775ffdc..2675cbfb 100644 --- a/test/settings.js +++ b/test/settings.js @@ -147,6 +147,27 @@ module.exports.tests.peliasZipAnalyzer = function(test, common) { }); }; +module.exports.tests.peliasUnitAnalyzer = function(test, common) { + test('has peliasUnit analyzer', function(t) { + var s = settings(); + t.equal(typeof s.analysis.analyzer.peliasUnit, 'object', 'there is a peliasUnit analyzer'); + var analyzer = s.analysis.analyzer.peliasUnit; + t.equal(analyzer.type, 'custom', 'custom analyzer'); + t.equal(typeof analyzer.tokenizer, 'string', 'tokenizer specified'); + t.deepEqual(analyzer.char_filter, ["alphanumeric"], 'alphanumeric filter specified'); + t.true(Array.isArray(analyzer.filter), 'filters specified'); + t.end(); + }); + test('peliasUnit token filters', function(t) { + var analyzer = settings().analysis.analyzer.peliasUnit; + t.deepEqual( analyzer.filter, [ + "lowercase", + "trim" + ]); + t.end(); + }); +}; + module.exports.tests.peliasHousenumberAnalyzer = function(test, common) { test('has peliasHousenumber analyzer', function(t) { var s = settings();