Browse Source

Use multi_match query for admin fields

pull/481/head
Julian Simioni 9 years ago committed by Julian Simioni
parent
commit
ab19a12e1c
No known key found for this signature in database
GPG Key ID: 6DAD08919FDBF563
  1. 18
      query/search.js
  2. 65
      test/unit/fixture/search_full_address.js
  3. 71
      test/unit/fixture/search_partial_address.js
  4. 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'), textParser = require('./text_parser'),
check = require('check-types'), check = require('check-types'),
geolib = require('geolib'); 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 // general-purpose search query
@ -25,15 +32,12 @@ query.score( peliasQuery.view.address('street') );
query.score( peliasQuery.view.address('postcode') ); query.score( peliasQuery.view.address('postcode') );
// admin components // 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('country_a') );
query.score( peliasQuery.view.admin('region') );
query.score( peliasQuery.view.admin('region_a') ); query.score( peliasQuery.view.admin('region_a') );
query.score( peliasQuery.view.admin('county') ); query.score( peliasQuery.view.admin_multi_match(adminFields), 'peliasAdmin' );
query.score( peliasQuery.view.admin('borough') );
query.score( peliasQuery.view.admin('localadmin') );
query.score( peliasQuery.view.admin('locality') );
query.score( peliasQuery.view.admin('neighbourhood') );
// non-scoring hard filters // non-scoring hard filters
query.filter( peliasQuery.view.boundary_circle ); query.filter( peliasQuery.view.boundary_circle );

65
test/unit/fixture/search_full_address.js

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

71
test/unit/fixture/search_partial_address.js

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

65
test/unit/fixture/search_regions_address.js

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

Loading…
Cancel
Save