Browse Source

Merge pull request #113 from pelias/boost-exact-matches#5

Boost exact matches#5
pull/131/head
Severyn Kozak 10 years ago
parent
commit
57d133b813
  1. 2
      query/reverse.js
  2. 2
      query/search.js
  3. 20
      query/sort.js
  4. 10
      test/unit/query/search.js
  5. 25
      test/unit/query/sort.js

2
query/reverse.js

@ -10,7 +10,7 @@ function generate( params ){
};
var query = queries.distance( centroid, { size: params.size || 1 } );
query.sort = query.sort.concat(sort);
query.sort = query.sort.concat( sort( params ) );
if ( params.categories && params.categories.length > 0 ) {
addCategoriesFilter( query, params.categories );

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;
}

20
query/sort.js

@ -4,8 +4,10 @@ var popularity = 'popularity';
var category = 'category';
var category_weights = require('../helper/category_weights');
var weights = require('pelias-suggester-pipeline').weights;
var isObject = require( 'is-object' );
module.exports = [
module.exports = function( params ){
var scriptsConfig = [
{
'_script': {
'file': admin_boost,
@ -48,3 +50,19 @@ module.exports = [
}
}
];
if( isObject( params ) && params.hasOwnProperty( 'input' ) ){
scriptsConfig.push({
'_script': {
'params': {
'input': params.input
},
'file': 'exact_match',
'type': 'number',
'order': 'desc'
}
});
}
return scriptsConfig;
};

10
test/unit/query/search.js

@ -58,6 +58,16 @@ var sort = [
'type': 'number',
'order': 'desc'
}
},
{
'_script': {
'params': {
'input': 'test'
},
'file': 'exact_match',
'type': 'number',
'order': 'desc'
}
}
];

25
test/unit/query/sort.js

@ -11,7 +11,8 @@ module.exports.tests = {};
module.exports.tests.interface = function(test, common) {
test('valid interface', function(t) {
t.equal(typeof generate, 'object', 'valid object');
t.equal(typeof generate(), 'object', 'valid object');
t.equal(typeof generate({input: 'foobar'}), 'object', 'valid object');
t.end();
});
};
@ -62,8 +63,26 @@ var expected = [
module.exports.tests.query = function(test, common) {
test('valid part of query', function(t) {
var sort = generate;
t.deepEqual(sort, expected, 'valid sort part of the query');
t.deepEqual(generate(), expected, 'valid sort part of the query');
t.deepEqual(generate( {} ), expected, 'valid sort part of the query');
t.end();
});
};
module.exports.tests.queryWithInput = function ( test, common ){
test( 'Valid sort query component when input is present.', function ( t ){
var expectedWithInput = expected.slice();
expectedWithInput.push({
_script: {
params: {
input: 'foobar'
},
file: 'exact_match',
type: 'number',
order: 'desc'
}
});
t.deepEqual(generate({ input: 'foobar' }), expectedWithInput, 'valid sort part of the query');
t.end();
});
};

Loading…
Cancel
Save