Browse Source

Boost results with exact text matches when _score ties.

query/sort.js
	-Use the elasticsearch script introduced in
	https://github.com/pelias/scripts/pull/7 to boost results with
	exact text matches when documents' `_score`s are tied.
	-Make `query/sort` export a function that creates the `sort`
	query component, rather than the query component as a singleton,
	to allow it to optionally add the exact-match script (that is,
	when an `input` is present in `params`).
pull/113/head
Severyn Kozak 10 years ago
parent
commit
144b72cb16
  1. 4
      query/reverse.js
  2. 4
      query/search.js
  3. 79
      query/sort.js

4
query/reverse.js

@ -11,9 +11,9 @@ function generate( params ){
}; };
var query = queries.distance( centroid, { size: params.size || 1 } ); var query = queries.distance( centroid, { size: params.size || 1 } );
query.sort = query.sort.concat(sort); query.sort = query.sort.concat( sort() );
return query; return query;
} }
module.exports = generate; module.exports = generate;

4
query/search.js

@ -45,9 +45,9 @@ function generate( params ){
}); });
} }
query.sort = query.sort.concat(sort); query.sort = query.sort.concat( sort( params ) );
return query; return query;
} }
module.exports = generate; module.exports = generate;

79
query/sort.js

@ -3,36 +3,53 @@ var population = 'population';
var popularity = 'popularity'; var popularity = 'popularity';
var weights = require('pelias-suggester-pipeline').weights; var weights = require('pelias-suggester-pipeline').weights;
module.exports = [ module.exports = function( params ){
{ var scriptsConfig = [
'_script': { {
'file': admin_boost, '_script': {
'type': 'number', 'file': admin_boost,
'order': 'desc' 'type': 'number',
} 'order': 'desc'
}, }
{ },
'_script': { {
'file': population, '_script': {
'type': 'number', 'file': population,
'order': 'desc' 'type': 'number',
} 'order': 'desc'
}, }
{ },
'_script': { {
'file': popularity, '_script': {
'type': 'number', 'file': popularity,
'order': 'desc' 'type': 'number',
} 'order': 'desc'
}, }
{ },
'_script': { {
'params': { '_script': {
'weights': weights 'params': {
}, 'weights': weights
'file': 'weights', },
'type': 'number', 'file': 'weights',
'order': 'desc' 'type': 'number',
'order': 'desc'
}
} }
];
if( typeof params === 'object' && params.hasOwnProperty( 'input' ) ){
scriptsConfig.push({
_script: {
params: {
input: params.input
},
file: 'exact_match',
type: 'number',
order: 'desc'
}
});
} }
];
return scriptsConfig;
};

Loading…
Cancel
Save