Browse Source

Adding unit attribute for addresses in api search

pull/1052/head
sweco-semhul 7 years ago
parent
commit
9d1c507d5f
  1. 4
      query/autocomplete_defaults.js
  2. 4
      query/reverse_defaults.js
  3. 4
      query/search_defaults.js
  4. 1
      query/search_original.js
  5. 5
      query/text_parser.js
  6. 5
      query/text_parser_addressit.js
  7. 161
      test/unit/fixture/search_full_address_original_with_unit.js
  8. 23
      test/unit/query/search_original.js
  9. 5
      test/unit/query/text_parser.js

4
query/autocomplete_defaults.js

@ -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,

4
query/reverse_defaults.js

@ -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,

4
query/search_defaults.js

@ -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,

1
query/search_original.js

@ -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') );

5
query/text_parser.js

@ -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 );

5
query/text_parser_addressit.js

@ -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 );

161
test/unit/fixture/search_full_address_original_with_unit.js

@ -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'
]
};

23
test/unit/query/search_original.js

@ -113,6 +113,29 @@ module.exports.tests.query = function(test, common) {
t.end();
});
test('valid query with a full valid address with unit', function(t) {
var query = generate({ text: 'Shop 8, 431 St Kilda Rd Melbourne',
layers: [ 'address', 'venue', 'country', 'region', 'county', 'neighbourhood', 'locality', 'localadmin' ],
querySize: 10,
parsed_text: {
unit: '8',
number: '431',
street: 'St Kilda Rd',
regions: [ 'Melbourne' ]
}
});
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_full_address_original_with_unit');
console.log(JSON.stringify( expected , null, 2));
console.log('----');
console.log(JSON.stringify( compiled.body , null, 2));
t.deepEqual(compiled.type, 'original', 'query type set');
t.deepEqual(compiled.body, expected, 'search_full_address');
t.end();
});
test('valid query with partial address', function(t) {
var query = generate({ text: 'soho grand, new york',
layers: [ 'address', 'venue', 'country', 'region', 'county', 'neighbourhood', 'locality', 'localadmin' ],

5
test/unit/query/text_parser.js

@ -19,6 +19,7 @@ module.exports.tests.query = function(test, common) {
t.false(vs.isset('input:query'));
t.false(vs.isset('input:category'));
t.false(vs.isset('input:unit'));
t.false(vs.isset('input:housenumber'));
t.false(vs.isset('input:street'));
t.false(vs.isset('input:address'));
@ -37,6 +38,7 @@ module.exports.tests.query = function(test, common) {
var parsed_text = {
query: 'query value',
category: 'category value',
unit: 'unit value',
number: 'number value',
street: 'street value',
address: 'address value',
@ -54,6 +56,7 @@ module.exports.tests.query = function(test, common) {
t.equals(vs.var('input:query').toString(), 'query value');
t.equals(vs.var('input:category').toString(), 'category value');
t.equals(vs.var('input:unit').toString(), 'unit value');
t.equals(vs.var('input:housenumber').toString(), 'number value');
t.equals(vs.var('input:street').toString(), 'street value');
t.equals(vs.var('input:address').toString(), 'address value');
@ -162,6 +165,7 @@ module.exports.tests.empty_values = function(test, common) {
var parsed_text = {
query: '',
category: '',
unit: '',
number: '',
street: '',
address: '',
@ -183,6 +187,7 @@ module.exports.tests.empty_values = function(test, common) {
t.false(vs.isset('input:query'));
t.false(vs.isset('input:category'));
t.false(vs.isset('input:unit'));
t.false(vs.isset('input:housenumber'));
t.false(vs.isset('input:street'));
t.false(vs.isset('input:address'));

Loading…
Cancel
Save