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. 40
      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) { if (params.input_admin) {
var admin_fields = get_layers(['admin','admin1_abbr','alpha3']); var adminFieldWeights = {
query.query.filtered.query.bool.should = []; admin0: 20,
alpha3: 20,
admin_fields.forEach(function(admin_field) { admin1: 10,
var match = {}; admin1_abbr: 10,
match[admin_field] = params.input_admin; admin2: 5,
query.query.filtered.query.bool.should.push({ locality: 1,
'match': match 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); query.sort = query.sort.concat(sort);
// console.log( JSON.stringify( query, null, 2 ) );
return query; return query;
} }

40
test/unit/query/search.js

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

Loading…
Cancel
Save