Browse Source

treat country and more granular than dependency

this is to ensure that `country=united states` returns the country before any of the US dependencies that happen to contain "United States"
pull/712/head
Stephen Hess 8 years ago
parent
commit
8ae5b5c6f7
  1. 9
      middleware/trimByGranularityComponent.js
  2. 22
      test/unit/middleware/trimByGranularityComponent.js

9
middleware/trimByGranularityComponent.js

@ -13,6 +13,11 @@ const _ = require('lodash');
// this component removes results that aren't the most granular.
// layers in increasing order of granularity
// some places where this list differs in order from trimByGranularity:
// - because house number and street are in a single field, street hits must be considered
// more important than addresses due to how ES matches
// - country outranks dependency, this was done to ensure that "country=United States" doesn't
// bump up US dependencies containing "United States" above the country
const layers = [
'venue',
'street',
@ -25,8 +30,8 @@ const layers = [
'macrocounty',
'region',
'macroregion',
'dependency',
'country'
'country',
'dependency'
];
// this helper method returns `true` if every result has a matched_query

22
test/unit/middleware/trimByGranularityComponent.js

@ -337,26 +337,26 @@ module.exports.tests.trimByGranularity = function(test, common) {
testIt();
});
test('all records with fallback.* matched_queries name should retain only dependencies when they are most granular', function(t) {
test('all records with fallback.* matched_queries name should retain countries over dependencies', function(t) {
var req = { clean: {} };
var res = {
data: [
{ name: 'dependency 1', _matched_queries: ['fallback.dependency'] },
{ name: 'dependency 2', _matched_queries: ['fallback.dependency'] },
{ name: 'country 1', _matched_queries: ['fallback.country'] },
{ name: 'country 2', _matched_queries: ['fallback.country'] },
{ name: 'unknown', _matched_queries: ['fallback.unknown'] }
]
};
var expected_data = [
{ name: 'dependency 1', _matched_queries: ['fallback.dependency'] },
{ name: 'dependency 2', _matched_queries: ['fallback.dependency'] },
{ name: 'country 1', _matched_queries: ['fallback.country'] },
{ name: 'country 2', _matched_queries: ['fallback.country'] },
];
function testIt() {
trimByGranularity(req, res, function() {
t.deepEquals(res.data, expected_data, 'only dependency records should be here');
t.deepEquals(res.data, expected_data, 'only country records should be here');
t.end();
});
}
@ -364,25 +364,25 @@ module.exports.tests.trimByGranularity = function(test, common) {
testIt();
});
test('all records with fallback.* matched_queries name should retain only countries when they are most granular', function(t) {
test('all records with fallback.* matched_queries name should retain only dependencies when they are most granular', function(t) {
var req = { clean: {} };
var res = {
data: [
{ name: 'country 1', _matched_queries: ['fallback.country'] },
{ name: 'country 2', _matched_queries: ['fallback.country'] },
{ name: 'dependency 1', _matched_queries: ['fallback.dependency'] },
{ name: 'dependency 2', _matched_queries: ['fallback.dependency'] },
{ name: 'unknown', _matched_queries: ['fallback.unknown'] }
]
};
var expected_data = [
{ name: 'country 1', _matched_queries: ['fallback.country'] },
{ name: 'country 2', _matched_queries: ['fallback.country'] },
{ name: 'dependency 1', _matched_queries: ['fallback.dependency'] },
{ name: 'dependency 2', _matched_queries: ['fallback.dependency'] },
];
function testIt() {
trimByGranularity(req, res, function() {
t.deepEquals(res.data, expected_data, 'only country records should be here');
t.deepEquals(res.data, expected_data, 'only dependency records should be here');
t.end();
});
}

Loading…
Cancel
Save