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 api output and queries #1052

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions controller/libpostal.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var field_mapping = {
island: 'island',
category: 'category',
house: 'query',
unit: 'unit',
house_number: 'number',
road: 'street',
suburb: 'neighbourhood',
Expand Down
5 changes: 5 additions & 0 deletions helper/diffPlaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ function assertAddressMatch(item1, item2) {
propMatch(item1.address_parts, item2.address_parts, 'zip');
}

// only compare unit if both records have it, otherwise just ignore and assume it's the same
if (item1.address_parts.hasOwnProperty('unit') && item2.address_parts.hasOwnProperty('unit')) {
propMatch(item1.address_parts, item2.address_parts, 'unit');
}

return false;
}

Expand Down
1 change: 1 addition & 0 deletions helper/geojsonify_place_details.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const _ = require('lodash');
// If a property is identified as a single string, assume it should be presented as a string in response
// If something other than string is desired, use the following structure: { name: 'category', type: 'array' }
const DETAILS_PROPS = [
{ name: 'unit', type: 'string' },
{ name: 'housenumber', type: 'string' },
{ name: 'street', type: 'string' },
{ name: 'postalcode', type: 'string' },
Expand Down
14 changes: 12 additions & 2 deletions middleware/localNamingConventions.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,18 @@ function applyLocalNamingConventions(req, res, next) {
// flip the housenumber and street name
// eg. '101 Grolmanstraße' -> 'Grolmanstraße 101'
function flipNumberAndStreet(place) {
var standard = ( place.address_parts.number + ' ' + place.address_parts.street ),
flipped = ( place.address_parts.street + ' ' + place.address_parts.number );
var standard = ( [ place.address_parts.number, place.address_parts.street ] ),
flipped = ( [ place.address_parts.street, place.address_parts.number ] );

// unit attribte added if set
if(place.address_parts.hasOwnProperty('unit')) {
standard.push(place.address_parts.unit);
flipped.push(place.address_parts.unit);
}

// join into strings
standard = standard.join(' ');
flipped = flipped.join(' ');

// flip street name and housenumber
if( place.name.default === standard ){
Expand Down
1 change: 1 addition & 0 deletions middleware/renamePlacenames.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const _ = require('lodash');
const PARENT_PROPS = require('../helper/placeTypes');

const ADDRESS_PROPS = [
{ name: 'unit', newName: 'unit' },
{ name: 'number', newName: 'housenumber' },
{ name: 'zip', newName: 'postalcode', transform: (value) => { return [value]; } },
{ name: 'street', newName: 'street' }
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
"pelias-labels": "1.7.0",
"pelias-logger": "0.3.0",
"pelias-microservice-wrapper": "1.3.0",
"pelias-model": "5.2.0",
"pelias-query": "9.1.1",
"pelias-model": "sweco-semhul/model#adding-address-unit",
"pelias-query": "sweco-semhul/query#adding-address-unit",
"pelias-sorting": "1.1.0",
"predicates": "^2.0.0",
"retry": "^0.10.1",
Expand Down
4 changes: 4 additions & 0 deletions query/autocomplete_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ module.exports = _.merge({}, peliasQuery.defaults, {
'function_score:score_mode': 'avg',
'function_score:boost_mode': 'replace',

'address:unit:analyzer': 'peliasUnit',
'address:unit:field': 'address_parts.unit',
'address:unit:boost': 2,

'address:housenumber:analyzer': 'peliasHousenumber',
'address:housenumber:field': 'address_parts.number',
'address:housenumber:boost': 2,
Expand Down
4 changes: 4 additions & 0 deletions query/reverse_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ module.exports = _.merge({}, peliasQuery.defaults, {
'function_score:score_mode': 'avg',
'function_score:boost_mode': 'replace',

'address:unit:analyzer': 'peliasUnit',
'address:unit:field': 'address_parts.unit',
'address:unit:boost': 2,

'address:housenumber:analyzer': 'peliasHousenumber',
'address:housenumber:field': 'address_parts.number',
'address:housenumber:boost': 2,
Expand Down
4 changes: 4 additions & 0 deletions query/search_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ module.exports = _.merge({}, peliasQuery.defaults, {
'function_score:score_mode': 'avg',
'function_score:boost_mode': 'replace',

'address:unit:analyzer': 'peliasUnit',
'address:unit:field': 'address_parts.unit',
'address:unit:boost': 2,

'address:housenumber:analyzer': 'peliasHousenumber',
'address:housenumber:field': 'address_parts.number',
'address:housenumber:boost': 2,
Expand Down
1 change: 1 addition & 0 deletions query/search_original.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ query.score( peliasQuery.view.popularity( peliasQuery.view.phrase ) );
query.score( peliasQuery.view.population( peliasQuery.view.phrase ) );

// address components
query.score( peliasQuery.view.address('unit') );
query.score( peliasQuery.view.address('housenumber') );
query.score( peliasQuery.view.address('street') );
query.score( peliasQuery.view.address('postcode') );
Expand Down
5 changes: 5 additions & 0 deletions query/text_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ function addParsedVariablesToQueryVariables( parsed_text, vs ){
vs.var( 'input:address', parsed_text.address );
}

// unit - an apartment, unit, office, lot, or other secondary unit designator
if( ! _.isEmpty(parsed_text.unit) ){
vs.var( 'input:unit', parsed_text.unit );
}

// house number
if( ! _.isEmpty(parsed_text.number) ){
vs.var( 'input:housenumber', parsed_text.number );
Expand Down
5 changes: 5 additions & 0 deletions query/text_parser_addressit.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ function addParsedVariablesToQueryVariables( parsed_text, vs ){

// ==== add parsed matches [address components] ====

// unit
if( parsed_text.hasOwnProperty('unit') ){
vs.var( 'input:unit', parsed_text.unit );
}

// house number
if( parsed_text.hasOwnProperty('number') ){
vs.var( 'input:housenumber', parsed_text.number );
Expand Down
1 change: 1 addition & 0 deletions sanitizer/_text_addressit.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ function parse(query) {
_.extend(addressWithAdminParts, addressWithAddressParts);

var address_parts = [ 'name',
'unit',
'number',
'street',
'city',
Expand Down
6 changes: 5 additions & 1 deletion service/configurations/Interpolation.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ class Language extends ServiceConfiguration {
}

getParameters(req, hit) {
return {
let res = {
number: req.clean.parsed_text.number,
street: hit.address_parts.street || req.clean.parsed_text.street,
lat: hit.center_point.lat,
lon: hit.center_point.lon
};
if(req.clean.parsed_text.hasOwnProperty('unit')) {
res.unit = req.clean.parsed_text.unit;
}
return res;

}

Expand Down
5 changes: 5 additions & 0 deletions test/unit/controller/libpostal.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ module.exports.tests.success_conditions = (test, common) => {
label: 'house',
value: 'house value'
},
{
label: 'unit',
value: 'unit value'
},
{
label: 'house_number',
value: 'house_number value'
Expand Down Expand Up @@ -244,6 +248,7 @@ module.exports.tests.success_conditions = (test, common) => {
island: 'island value',
category: 'category value',
query: 'house value',
unit: 'unit value',
number: 'house_number value',
street: 'road value',
neighbourhood: 'suburb value',
Expand Down
161 changes: 161 additions & 0 deletions test/unit/fixture/search_full_address_original_with_unit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
var vs = require('../../../query/search_defaults');

module.exports = {
'query': {
'bool': {
'must': [
{
'match': {
'name.default': {
'analyzer': 'peliasQueryFullToken',
'boost': 1,
'query': '431 St Kilda Rd'
}
}
}
],
'should': [
{
'match': {
'phrase.default': {
'analyzer': 'peliasPhrase',
'type': 'phrase',
'boost': 1,
'slop': 2,
'query': '431 St Kilda Rd'
}
}
},
{
'function_score': {
'query': {
'match': {
'phrase.default': {
'analyzer': 'peliasPhrase',
'type': 'phrase',
'boost': 1,
'slop': 2,
'query': '431 St Kilda Rd'
}
}
},
'max_boost': 20,
'functions': [
{
'field_value_factor': {
'modifier': 'log1p',
'field': 'popularity',
'missing': 1
},
'weight': 1
}
],
'score_mode': 'first',
'boost_mode': 'replace'
}
},
{
'function_score': {
'query': {
'match': {
'phrase.default': {
'analyzer': 'peliasPhrase',
'type': 'phrase',
'boost': 1,
'slop': 2,
'query': '431 St Kilda Rd'
}
}
},
'max_boost': 20,
'functions': [
{
'field_value_factor': {
'modifier': 'log1p',
'field': 'population',
'missing': 1
},
'weight': 2
}
],
'score_mode': 'first',
'boost_mode': 'replace'
}
},
{
'match': {
'address_parts.unit': {
'analyzer': vs['address:unit:analyzer'],
'boost': vs['address:unit:boost'],
'query': '8'
}
}
},
{
'match': {
'address_parts.number': {
'analyzer': vs['address:housenumber:analyzer'],
'boost': vs['address:housenumber:boost'],
'query': '431'
}
}
},
{
'match': {
'address_parts.street': {
'analyzer': vs['address:street:analyzer'],
'boost': vs['address:street:boost'],
'query': 'St Kilda Rd'
}
}
},
{
'match': {
'parent.region_a': {
'analyzer': vs['admin:region_a:analyzer'],
'boost': vs['admin:region_a:boost'],
'query': 'Melbourne'
}
}
},
{
'multi_match': {
'fields': [
'parent.country^1',
'parent.region^1',
'parent.county^1',
'parent.localadmin^1',
'parent.locality^1',
'parent.borough^1',
'parent.neighbourhood^1',
'parent.region_a^1'
],
'query': 'Melbourne',
'analyzer': 'peliasAdmin'
}
}
],
'filter': [
{
'terms': {
'layer': [
'address',
'venue',
'country',
'region',
'county',
'neighbourhood',
'locality',
'localadmin'
]
}
}
]
}
},
'size': 10,
'track_scores': true,
'sort': [
'_score'
]
};
44 changes: 44 additions & 0 deletions test/unit/helper/diffPlaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,50 @@ module.exports.tests.dedupe = function(test, common) {
t.false(isDifferent(item1, item2), 'should be the same');
t.end();
});

test('catch diff address by unit', function(t) {
var item1 = {
'address_parts': {
'unit': 'A',
'number': '1',
'street': 'Main Street',
'zip': '90210'
}
};
var item2 = {
'address_parts': {
'unit': 'B',
'number': '1',
'street': 'Main Street',
'zip': '90210'
}
};

t.true(isDifferent(item1, item2), 'should be different');
t.end();
});

test('catch diff address by unit', function(t) {
var item1 = {
'address_parts': {
'unit': 'A',
'number': '1',
'street': 'Main Street',
'zip': '90210'
}
};
var item2 = {
'address_parts': {
'unit': 'A',
'number': '1',
'street': 'Main Street',
'zip': '90210'
}
};

t.false(isDifferent(item1, item2), 'should be the same');
t.end();
});
};

module.exports.all = function (tape, common) {
Expand Down
Loading