Browse Source

Fine-tune the admin boosting query.

query/search.js
	-Follow up on @hkrishna's work and fine-tune the admin-boosting
	query by:

		* not searching for `neighborhood` matches
		* assigning boost values to each `should` clause, with
		higher values for higher admin levels.

	-These changes fix the `West New York` in `New Jersey`
	regression pointed out in https://github.com/pelias/api/issues/91
search-all-admins
Severyn Kozak 10 years ago
parent
commit
332597c653
  1. 33
      query/search.js
  2. 38
      test/unit/query/search.js

33
query/search.js

@ -33,22 +33,33 @@ function generate( params ){
}
};
/**
* If the query contained an administrative region name, boost results that
* contain a matching admin value, assigning higher values to higher admin
* levels (admin0 carries more weight than locality, for instance).
*/
if (params.input_admin) {
var admin_fields = get_layers(['admin','admin1_abbr','alpha3']);
query.query.filtered.query.bool.should = [];
admin_fields.forEach(function(admin_field) {
var match = {};
match[admin_field] = params.input_admin;
query.query.filtered.query.bool.should.push({
'match': match
});
var adminFieldWeights = {
admin0: 20,
alpha3: 20,
admin1: 10,
admin1_abbr: 10,
admin2: 5,
locality: 1,
local_admin: 1
};
query.query.filtered.query.bool.should = Object.keys( adminFieldWeights ).map( function ( field ){
var boostFactor = adminFieldWeights[ field ];
var shouldClause = { match: { } };
shouldClause.match[ field ] = {
query: params.input_admin,
boost: boostFactor
};
return shouldClause;
});
}
query.sort = query.sort.concat(sort);
// console.log( JSON.stringify( query, null, 2 ) );
return query;
}

38
test/unit/query/search.js

@ -238,42 +238,58 @@ module.exports.tests.query = function(test, common) {
'should': [
{
'match': {
'admin1_abbr': 'usa'
'admin0': {
'query': 'usa',
'boost': 20
}
},
{
'match': {
'alpha3': 'usa'
}
},
{
'match': {
'admin0': 'usa'
'alpha3': {
'query': 'usa',
'boost': 20
}
}
},
{
'match': {
'admin1': 'usa'
'admin1': {
'query': 'usa',
'boost': 10
}
}
},
{
'match': {
'admin2': 'usa'
'admin1_abbr': {
'query': 'usa',
'boost': 10
}
}
},
{
'match': {
'neighborhood': 'usa'
'admin2': {
'query': 'usa',
'boost': 5
}
}
},
{
'match': {
'locality': 'usa'
'locality': {
'query': 'usa',
'boost': 1
}
}
},
{
'match': {
'local_admin': 'usa'
'local_admin': {
'query': 'usa',
'boost': 1
}
}
}
]

Loading…
Cancel
Save