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 } );
query.sort = query.sort.concat(sort);
query.sort = query.sort.concat( sort() );
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;
}
module.exports = generate;
module.exports = generate;

79
query/sort.js

@ -3,36 +3,53 @@ var population = 'population';
var popularity = 'popularity';
var weights = require('pelias-suggester-pipeline').weights;
module.exports = [
{
'_script': {
'file': admin_boost,
'type': 'number',
'order': 'desc'
}
},
{
'_script': {
'file': population,
'type': 'number',
'order': 'desc'
}
},
{
'_script': {
'file': popularity,
'type': 'number',
'order': 'desc'
}
},
{
'_script': {
'params': {
'weights': weights
},
'file': 'weights',
'type': 'number',
'order': 'desc'
module.exports = function( params ){
var scriptsConfig = [
{
'_script': {
'file': admin_boost,
'type': 'number',
'order': 'desc'
}
},
{
'_script': {
'file': population,
'type': 'number',
'order': 'desc'
}
},
{
'_script': {
'file': popularity,
'type': 'number',
'order': 'desc'
}
},
{
'_script': {
'params': {
'weights': weights
},
'file': 'weights',
'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