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. 4
      query/reverse.js
  2. 4
      query/search.js
  3. 100
      query/sort.js
  4. 12
      test/unit/query/search.js
  5. 27
      test/unit/query/sort.js

4
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 );
@ -25,4 +25,4 @@ function addCategoriesFilter( query, categories ) {
});
}
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;

100
query/sort.js

@ -4,47 +4,65 @@ 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 = [
{
'_script': {
'file': admin_boost,
'type': 'number',
'order': 'desc'
}
},
{
'_script': {
'file': population,
'type': 'number',
'order': 'desc'
}
},
{
'_script': {
'file': popularity,
'type': 'number',
'order': 'desc'
}
},
{
'_script': {
'params': {
'category_weights': category_weights
},
'file': category,
'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': {
'category_weights': category_weights
},
'file': category,
'type': 'number',
'order': 'desc'
}
},
{
'_script': {
'params': {
'weights': weights
},
'file': 'weights',
'type': 'number',
'order': 'desc'
}
}
];
if( isObject( params ) && params.hasOwnProperty( 'input' ) ){
scriptsConfig.push({
'_script': {
'params': {
'input': params.input
},
'file': 'exact_match',
'type': 'number',
'order': 'desc'
}
});
}
];
return scriptsConfig;
};

12
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'
}
}
];
@ -239,4 +249,4 @@ module.exports.all = function (tape, common) {
for( var testCase in module.exports.tests ){
module.exports.tests[testCase](test, common);
}
};
};

27
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();
});
};
@ -77,4 +96,4 @@ module.exports.all = function (tape, common) {
for( var testCase in module.exports.tests ){
module.exports.tests[testCase](test, common);
}
};
};

Loading…
Cancel
Save