Browse Source

Merge pull request #293 from pelias/fix-confidence

Fix lost confidence score
pull/299/head
Diana Shkolnikov 9 years ago
parent
commit
0b182e20ed
  1. 1
      controller/search.js
  2. 7
      query/text_parser.js
  3. 31
      test/unit/controller/search.js
  4. 7
      test/unit/service/search.js

1
controller/search.js

@ -36,6 +36,7 @@ function setup( backend, query ){
// set response data
else {
res.data = docs;
res.meta = meta;
}
next();

7
query/text_parser.js

@ -1,4 +1,5 @@
var logger = require('pelias-logger').get('api');
var adminFields = require('../helper/adminFields')();
/**
@ -21,9 +22,9 @@ function addParsedVariablesToQueryVariables( parsed_text, vs ){
// ?
else {
console.warn( 'chaos monkey asks: what happens now?' );
console.log( parsed_text );
try{ throw new Error(); } catch(e){ console.error( e.stack ); } // print a stack trace
logger.warn( 'chaos monkey asks: what happens now?' );
logger.warn( parsed_text );
try{ throw new Error(); } catch(e){ logger.warn( e.stack ); } // print a stack trace
}
// ==== add parsed matches [address components] ====

31
test/unit/controller/search.js

@ -41,6 +41,35 @@ module.exports.tests.functional_success = function(test, common) {
}
}];
var expectedMeta = {
scores: [10, 20]
};
var expectedData = [
{
_id: 'myid1',
_score: 10,
_type: 'mytype1',
admin0: 'country1',
admin1: 'state1',
admin2: 'city1',
center_point: { lat: 100.1, lon: -50.5 },
name: { default: 'test name1' },
value: 1
},
{
_id: 'myid2',
_score: 20,
_type: 'mytype2',
admin0: 'country2',
admin1: 'state2',
admin2: 'city2',
center_point: { lat: 100.2, lon: -51.5 },
name: { default: 'test name2' },
value: 2
}
];
test('functional success', function (t) {
var backend = mockBackend('client/search/ok/1', function (cmd) {
t.deepEqual(cmd, {
@ -66,6 +95,8 @@ module.exports.tests.functional_success = function(test, common) {
var req = { clean: { a: 'b' }, errors: [], warnings: [] };
var next = function next() {
t.equal(req.errors.length, 0, 'next was called without error');
t.deepEqual(res.meta, expectedMeta, 'meta data was set');
t.deepEqual(res.data, expectedData, 'data was set');
t.end();
};
controller(req, res, next);

7
test/unit/service/search.js

@ -35,16 +35,21 @@ module.exports.tests.functional_success = function(test, common) {
}
];
var expectedMeta = {
scores: [10, 20]
};
test('valid ES query', function(t) {
var backend = mockBackend( 'client/search/ok/1', function( cmd ){
t.deepEqual(cmd, example_valid_es_query, 'no change to the command');
});
setup( backend, example_valid_es_query, function(err, data) {
setup( backend, example_valid_es_query, function(err, data, meta) {
t.true(Array.isArray(data), 'returns an array');
data.forEach(function(d) {
t.true(typeof d === 'object', 'valid object');
});
t.deepEqual(data, expected, 'values correctly mapped');
t.deepEqual(meta, expectedMeta, 'meta data correctly mapped');
t.end();
});
});

Loading…
Cancel
Save