Skip to content

Commit

Permalink
feat: Merge pull request #258 from sweco-semhul/adding-address-unit
Browse files Browse the repository at this point in the history
Adding address unit attribute to schema
  • Loading branch information
orangejulius authored Nov 20, 2017
2 parents 4a5590b + fe6ebd6 commit 9b0b5dd
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 1 deletion.
4 changes: 4 additions & 0 deletions mappings/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ var schema = {
type: 'string',
analyzer: 'keyword',
},
unit: {
type: 'string',
analyzer: 'peliasUnit',
},
number: {
type: 'string',
analyzer: 'peliasHousenumber',
Expand Down
9 changes: 9 additions & 0 deletions settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ function generate(){
"trim"
]
},
"peliasUnit": {
"type": "custom",
"tokenizer":"keyword",
"char_filter" : ["alphanumeric"],
"filter": [
"lowercase",
"trim"
]
},
"peliasHousenumber": {
"type": "custom",
"tokenizer":"standard",
Expand Down
9 changes: 8 additions & 1 deletion test/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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');
Expand Down
71 changes: 71 additions & 0 deletions test/fixtures/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,17 @@
"trim"
]
},
"peliasUnit": {
"type": "custom",
"tokenizer": "keyword",
"char_filter": [
"alphanumeric"
],
"filter": [
"lowercase",
"trim"
]
},
"peliasHousenumber": {
"type": "custom",
"tokenizer": "standard",
Expand Down Expand Up @@ -1576,6 +1587,10 @@
"type": "string",
"analyzer": "keyword"
},
"unit": {
"type": "string",
"analyzer": "peliasUnit"
},
"number": {
"type": "string",
"analyzer": "peliasHousenumber"
Expand Down Expand Up @@ -1869,6 +1884,10 @@
"type": "string",
"analyzer": "keyword"
},
"unit": {
"type": "string",
"analyzer": "peliasUnit"
},
"number": {
"type": "string",
"analyzer": "peliasHousenumber"
Expand Down Expand Up @@ -2162,6 +2181,10 @@
"type": "string",
"analyzer": "keyword"
},
"unit": {
"type": "string",
"analyzer": "peliasUnit"
},
"number": {
"type": "string",
"analyzer": "peliasHousenumber"
Expand Down Expand Up @@ -2455,6 +2478,10 @@
"type": "string",
"analyzer": "keyword"
},
"unit": {
"type": "string",
"analyzer": "peliasUnit"
},
"number": {
"type": "string",
"analyzer": "peliasHousenumber"
Expand Down Expand Up @@ -2748,6 +2775,10 @@
"type": "string",
"analyzer": "keyword"
},
"unit": {
"type": "string",
"analyzer": "peliasUnit"
},
"number": {
"type": "string",
"analyzer": "peliasHousenumber"
Expand Down Expand Up @@ -3041,6 +3072,10 @@
"type": "string",
"analyzer": "keyword"
},
"unit": {
"type": "string",
"analyzer": "peliasUnit"
},
"number": {
"type": "string",
"analyzer": "peliasHousenumber"
Expand Down Expand Up @@ -3334,6 +3369,10 @@
"type": "string",
"analyzer": "keyword"
},
"unit": {
"type": "string",
"analyzer": "peliasUnit"
},
"number": {
"type": "string",
"analyzer": "peliasHousenumber"
Expand Down Expand Up @@ -3627,6 +3666,10 @@
"type": "string",
"analyzer": "keyword"
},
"unit": {
"type": "string",
"analyzer": "peliasUnit"
},
"number": {
"type": "string",
"analyzer": "peliasHousenumber"
Expand Down Expand Up @@ -3920,6 +3963,10 @@
"type": "string",
"analyzer": "keyword"
},
"unit": {
"type": "string",
"analyzer": "peliasUnit"
},
"number": {
"type": "string",
"analyzer": "peliasHousenumber"
Expand Down Expand Up @@ -4213,6 +4260,10 @@
"type": "string",
"analyzer": "keyword"
},
"unit": {
"type": "string",
"analyzer": "peliasUnit"
},
"number": {
"type": "string",
"analyzer": "peliasHousenumber"
Expand Down Expand Up @@ -4506,6 +4557,10 @@
"type": "string",
"analyzer": "keyword"
},
"unit": {
"type": "string",
"analyzer": "peliasUnit"
},
"number": {
"type": "string",
"analyzer": "peliasHousenumber"
Expand Down Expand Up @@ -4799,6 +4854,10 @@
"type": "string",
"analyzer": "keyword"
},
"unit": {
"type": "string",
"analyzer": "peliasUnit"
},
"number": {
"type": "string",
"analyzer": "peliasHousenumber"
Expand Down Expand Up @@ -5092,6 +5151,10 @@
"type": "string",
"analyzer": "keyword"
},
"unit": {
"type": "string",
"analyzer": "peliasUnit"
},
"number": {
"type": "string",
"analyzer": "peliasHousenumber"
Expand Down Expand Up @@ -5385,6 +5448,10 @@
"type": "string",
"analyzer": "keyword"
},
"unit": {
"type": "string",
"analyzer": "peliasUnit"
},
"number": {
"type": "string",
"analyzer": "peliasHousenumber"
Expand Down Expand Up @@ -5678,6 +5745,10 @@
"type": "string",
"analyzer": "keyword"
},
"unit": {
"type": "string",
"analyzer": "peliasUnit"
},
"number": {
"type": "string",
"analyzer": "peliasHousenumber"
Expand Down
21 changes: 21 additions & 0 deletions test/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 9b0b5dd

Please sign in to comment.