Browse Source

Add tests for autocomplete custom boosts

configurable-boosts
Julian Simioni 6 years ago
parent
commit
bb605acb3f
No known key found for this signature in database
GPG Key ID: B9EEB0C6EE0910A1
  1. 106
      test/unit/fixture/autocomplete_custom_boosts.json
  2. 54
      test/unit/query/autocomplete_with_custom_boosts.js
  3. 1
      test/unit/run.js

106
test/unit/fixture/autocomplete_custom_boosts.json

@ -0,0 +1,106 @@
{
"type": "autocomplete",
"body": {
"query": {
"bool": {
"must": [
{
"match": {
"name.default": {
"analyzer": "peliasQueryFullToken",
"type": "phrase",
"boost": 1,
"slop": 3,
"query": "foo"
}
}
}
],
"should": [
{
"match": {
"phrase.default": {
"analyzer": "peliasPhrase",
"type": "phrase",
"boost": 1,
"slop": 3,
"query": "foo"
}
}
},
{
"function_score": {
"query": {
"match_all": {}
},
"max_boost": 20,
"functions": [
{
"field_value_factor": {
"modifier": "log1p",
"field": "popularity",
"missing": 1
},
"weight": 1
}
],
"score_mode": "first",
"boost_mode": "replace"
}
},
{
"function_score": {
"query": {
"match_all": {}
},
"max_boost": 20,
"functions": [
{
"field_value_factor": {
"modifier": "log1p",
"field": "population",
"missing": 1
},
"weight": 3
}
],
"score_mode": "first",
"boost_mode": "replace"
}
},
{
"bool": {
"should": [
{
"constant_score": {
"boost": 5,
"query": {
"term": {
"source": "openstreetmap"
}
}
}
},
{
"constant_score": {
"boost": 3,
"query": {
"term": {
"layer": "transit"
}
}
}
}
]
}
}
]
}
},
"size": 20,
"track_scores": true,
"sort": [
"_score"
]
}
}

54
test/unit/query/autocomplete_with_custom_boosts.js

@ -0,0 +1,54 @@
const proxyquire = require('proxyquire');
module.exports.tests = {};
module.exports.tests.query = function(test, common) {
test('valid autocomplete with custom boosts', function(t) {
const clean = {
tokens: ['foo'],
tokens_complete: ['foo'],
tokens_incomplete: [],
text: 'test',
querySize: 10
};
const config_with_boosts = {
generate: function() {
return {
api: {
customBoosts: {
source: {
openstreetmap: 5
},
layer: {
transit: 3
}
}
}
};
}
};
var expected_query = require('../fixture/autocomplete_custom_boosts.json');
const autocomplete_query_module = proxyquire('../../../query/autocomplete', {
'pelias-config': config_with_boosts
});
const actual_query = JSON.parse( JSON.stringify( autocomplete_query_module(clean) ) );
t.deepEqual(actual_query, expected_query, 'query as expected');
t.pass();
t.end();
});
};
module.exports.all = function (tape, common) {
function test(name, testFunction) {
return tape('autocomplete with custom boosts query ' + name, testFunction);
}
for( var testCase in module.exports.tests ){
module.exports.tests[testCase](test, common);
}
};

1
test/unit/run.js

@ -64,6 +64,7 @@ var tests = [
require('./query/address_search_using_ids'), require('./query/address_search_using_ids'),
require('./query/autocomplete'), require('./query/autocomplete'),
require('./query/autocomplete_defaults'), require('./query/autocomplete_defaults'),
require('./query/autocomplete_with_custom_boosts'),
require('./query/reverse'), require('./query/reverse'),
require('./query/reverse_defaults'), require('./query/reverse_defaults'),
require('./query/search'), require('./query/search'),

Loading…
Cancel
Save