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. 2
      query/reverse.js
  2. 2
      query/search.js
  3. 19
      query/sort.js

2
query/reverse.js

@ -11,7 +11,7 @@ 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;
} }

2
query/search.js

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

19
query/sort.js

@ -3,7 +3,8 @@ 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': { '_script': {
'file': admin_boost, 'file': admin_boost,
@ -36,3 +37,19 @@ module.exports = [
} }
} }
]; ];
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