Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding address unit attribute to schema #258

Merged
merged 2 commits into from
Nov 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@trescube do you think we would ever need non-alphanumeric characters in unit numbers? Maybe - or /?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've had a discussion and are pretty sure analyzing alphanumeric characters only will work well enough to start :)

"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