Browse Source

Merge pull request #481 from pelias/multi_match_admin_parts

Use multi_match query for admin fields
pull/534/head
Julian Simioni 9 years ago
parent
commit
833d3a7109
  1. 18
      query/search.js
  2. 10
      query/search_defaults.js
  3. 65
      test/unit/fixture/search_full_address.js
  4. 71
      test/unit/fixture/search_partial_address.js
  5. 65
      test/unit/fixture/search_regions_address.js

18
query/search.js

@ -3,6 +3,13 @@ var peliasQuery = require('pelias-query'),
textParser = require('./text_parser'),
check = require('check-types'),
geolib = require('geolib');
var placeTypes = require('../helper/placeTypes');
// region_a is also an admin field. addressit tries to detect
// region_a, in which case we use a match query specifically for it.
// but address it doesn't know about all of them so it helps to search
// against this with the other admin parts as a fallback
var adminFields = placeTypes.concat(['region_a']);
//------------------------------
// general-purpose search query
@ -25,15 +32,12 @@ query.score( peliasQuery.view.address('street') );
query.score( peliasQuery.view.address('postcode') );
// admin components
query.score( peliasQuery.view.admin('country') );
// country_a and region_a are left as matches here because the text-analyzer
// can sometimes detect them, in which case a query more specific than a
// multi_match is appropriate.
query.score( peliasQuery.view.admin('country_a') );
query.score( peliasQuery.view.admin('region') );
query.score( peliasQuery.view.admin('region_a') );
query.score( peliasQuery.view.admin('county') );
query.score( peliasQuery.view.admin('borough') );
query.score( peliasQuery.view.admin('localadmin') );
query.score( peliasQuery.view.admin('locality') );
query.score( peliasQuery.view.admin('neighbourhood') );
query.score( peliasQuery.view.admin_multi_match(adminFields), 'peliasAdmin' );
// non-scoring hard filters
query.filter( peliasQuery.view.boundary_circle );

10
query/search_defaults.js

@ -52,23 +52,23 @@ module.exports = _.merge({}, peliasQuery.defaults, {
'admin:country_a:analyzer': 'standard',
'admin:country_a:field': 'parent.country_a',
'admin:country_a:boost': 5,
'admin:country_a:boost': 1,
'admin:country:analyzer': 'peliasAdmin',
'admin:country:field': 'parent.country',
'admin:country:boost': 4,
'admin:country:boost': 1,
'admin:region:analyzer': 'peliasAdmin',
'admin:region:field': 'parent.region',
'admin:region:boost': 3,
'admin:region:boost': 1,
'admin:region_a:analyzer': 'peliasAdmin',
'admin:region_a:field': 'parent.region_a',
'admin:region_a:boost': 3,
'admin:region_a:boost': 1,
'admin:county:analyzer': 'peliasAdmin',
'admin:county:field': 'parent.county',
'admin:county:boost': 2,
'admin:county:boost': 1,
'admin:localadmin:analyzer': 'peliasAdmin',
'admin:localadmin:field': 'parent.localadmin',

65
test/unit/fixture/search_full_address.js

@ -99,14 +99,6 @@ module.exports = {
'analyzer': vs['address:postcode:analyzer']
}
}
}, {
'match': {
'parent.country': {
'query': 'new york',
'boost': vs['admin:country:boost'],
'analyzer': vs['admin:country:analyzer']
}
}
}, {
'match': {
'parent.country_a': {
@ -115,14 +107,6 @@ module.exports = {
'analyzer': vs['admin:country_a:analyzer']
}
}
}, {
'match': {
'parent.region': {
'query': 'new york',
'boost': vs['admin:region:boost'],
'analyzer': vs['admin:region:analyzer']
}
}
}, {
'match': {
'parent.region_a': {
@ -132,44 +116,19 @@ module.exports = {
}
}
}, {
'match': {
'parent.county': {
'query': 'new york',
'boost': vs['admin:county:boost'],
'analyzer': vs['admin:county:analyzer']
}
}
}, {
'match': {
'parent.borough': {
'query': 'new york',
'boost': vs['admin:borough:boost'],
'analyzer': vs['admin:borough:analyzer']
}
}
}, {
'match': {
'parent.localadmin': {
'query': 'new york',
'boost': vs['admin:localadmin:boost'],
'analyzer': vs['admin:localadmin:analyzer']
}
}
}, {
'match': {
'parent.locality': {
'query': 'new york',
'boost': vs['admin:locality:boost'],
'analyzer': vs['admin:locality:analyzer']
}
}
}, {
'match': {
'parent.neighbourhood': {
'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': 'new york',
'boost': vs['admin:neighbourhood:boost'],
'analyzer': vs['admin:neighbourhood:analyzer']
}
'analyzer': 'peliasAdmin'
}
}]
}

71
test/unit/fixture/search_partial_address.js

@ -75,69 +75,28 @@ module.exports = {
'weight': 2
}]
}
},{
'match': {
'parent.country': {
'query': 'new york',
'boost': vs['admin:country:boost'],
'analyzer': vs['admin:country:analyzer']
}
}
}, {
'match': {
'parent.region': {
'query': 'new york',
'boost': vs['admin:region:boost'],
'analyzer': vs['admin:region:analyzer']
}
}
}, {
'match': {
'parent.region_a': {
'query': 'new york',
'boost': vs['admin:region_a:boost'],
'analyzer': vs['admin:region_a:analyzer']
}
}
}, {
'match': {
'parent.county': {
'query': 'new york',
'boost': vs['admin:county:boost'],
'analyzer': vs['admin:county:analyzer']
'analyzer': 'peliasAdmin',
'boost': 1,
'query': 'new york'
}
}
}, {
'match': {
'parent.borough': {
'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': 'new york',
'boost': vs['admin:borough:boost'],
'analyzer': vs['admin:borough:analyzer']
}
}
}, {
'match': {
'parent.localadmin': {
'query': 'new york',
'boost': vs['admin:localadmin:boost'],
'analyzer': vs['admin:localadmin:analyzer']
}
}
}, {
'match': {
'parent.locality': {
'query': 'new york',
'boost': vs['admin:locality:boost'],
'analyzer': vs['admin:locality:analyzer']
}
}
}, {
'match': {
'parent.neighbourhood': {
'query': 'new york',
'boost': vs['admin:neighbourhood:boost'],
'analyzer': vs['admin:neighbourhood:analyzer']
}
'analyzer': 'peliasAdmin'
}
}]
}

65
test/unit/fixture/search_regions_address.js

@ -91,22 +91,6 @@ module.exports = {
'analyzer': vs['address:street:analyzer']
}
}
}, {
'match': {
'parent.country': {
'query': 'manhattan',
'boost': vs['admin:country:boost'],
'analyzer': vs['admin:country:analyzer']
}
}
}, {
'match': {
'parent.region': {
'query': 'manhattan',
'boost': vs['admin:region:boost'],
'analyzer': vs['admin:region:analyzer']
}
}
}, {
'match': {
'parent.region_a': {
@ -116,44 +100,19 @@ module.exports = {
}
}
}, {
'match': {
'parent.county': {
'query': 'manhattan',
'boost': vs['admin:county:boost'],
'analyzer': vs['admin:county:analyzer']
}
}
}, {
'match': {
'parent.borough': {
'query': 'manhattan',
'boost': vs['admin:borough:boost'],
'analyzer': vs['admin:borough:analyzer']
}
}
}, {
'match': {
'parent.localadmin': {
'query': 'manhattan',
'boost': vs['admin:localadmin:boost'],
'analyzer': vs['admin:localadmin:analyzer']
}
}
}, {
'match': {
'parent.locality': {
'query': 'manhattan',
'boost': vs['admin:locality:boost'],
'analyzer': vs['admin:locality:analyzer']
}
}
}, {
'match': {
'parent.neighbourhood': {
'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': 'manhattan',
'boost': vs['admin:neighbourhood:boost'],
'analyzer': vs['admin:neighbourhood:analyzer']
}
'analyzer': 'peliasAdmin'
}
}]
}

Loading…
Cancel
Save