Browse Source

switch importance of address/street

pull/736/head
Stephen Hess 8 years ago
parent
commit
da72a968f9
  1. 4
      middleware/trimByGranularityComponent.js
  2. 24
      test/unit/middleware/trimByGranularityComponent.js

4
middleware/trimByGranularityComponent.js

@ -22,8 +22,8 @@ const _ = require('lodash');
// supplied we want to retain borough=Manhattan and city=Manhattan results // supplied we want to retain borough=Manhattan and city=Manhattan results
const layers = [ const layers = [
'venue', 'venue',
'street',
'address', 'address',
'street',
'neighbourhood', 'neighbourhood',
['borough', 'locality'], ['borough', 'locality'],
'localadmin', 'localadmin',
@ -44,8 +44,8 @@ const layers = [
// city=Manhattan // city=Manhattan
const explicit_borough_layers = [ const explicit_borough_layers = [
'venue', 'venue',
'street',
'address', 'address',
'street',
'neighbourhood', 'neighbourhood',
'borough', 'borough',
'locality', 'locality',

24
test/unit/middleware/trimByGranularityComponent.js

@ -19,8 +19,8 @@ module.exports.tests.trimByGranularity = function(test, common) {
data: [ data: [
{ name: 'venue 1', _matched_queries: ['fallback.venue'] }, { name: 'venue 1', _matched_queries: ['fallback.venue'] },
{ name: 'venue 2', _matched_queries: ['fallback.venue'] }, { name: 'venue 2', _matched_queries: ['fallback.venue'] },
{ name: 'street 1', _matched_queries: ['fallback.street'] },
{ name: 'address 1', _matched_queries: ['fallback.address'] }, { name: 'address 1', _matched_queries: ['fallback.address'] },
{ name: 'street 1', _matched_queries: ['fallback.street'] },
{ name: 'neighbourhood 1', _matched_queries: ['fallback.neighbourhood'] }, { name: 'neighbourhood 1', _matched_queries: ['fallback.neighbourhood'] },
{ name: 'borough 1', _matched_queries: ['fallback.borough'] }, { name: 'borough 1', _matched_queries: ['fallback.borough'] },
{ name: 'locality 1', _matched_queries: ['fallback.locality'] }, { name: 'locality 1', _matched_queries: ['fallback.locality'] },
@ -55,9 +55,9 @@ module.exports.tests.trimByGranularity = function(test, common) {
var res = { var res = {
data: [ data: [
{ name: 'street 1', _matched_queries: ['fallback.street'] },
{ name: 'street 2', _matched_queries: ['fallback.street'] },
{ name: 'address 1', _matched_queries: ['fallback.address'] }, { name: 'address 1', _matched_queries: ['fallback.address'] },
{ name: 'address 2', _matched_queries: ['fallback.address'] },
{ name: 'street 1', _matched_queries: ['fallback.street'] },
{ name: 'neighbourhood 1', _matched_queries: ['fallback.neighbourhood'] }, { name: 'neighbourhood 1', _matched_queries: ['fallback.neighbourhood'] },
{ name: 'borough 1', _matched_queries: ['fallback.borough'] }, { name: 'borough 1', _matched_queries: ['fallback.borough'] },
{ name: 'locality 1', _matched_queries: ['fallback.locality'] }, { name: 'locality 1', _matched_queries: ['fallback.locality'] },
@ -73,13 +73,13 @@ module.exports.tests.trimByGranularity = function(test, common) {
}; };
var expected_data = [ var expected_data = [
{ name: 'street 1', _matched_queries: ['fallback.street'] }, { name: 'address 1', _matched_queries: ['fallback.address'] },
{ name: 'street 2', _matched_queries: ['fallback.street'] } { name: 'address 2', _matched_queries: ['fallback.address'] }
]; ];
function testIt() { function testIt() {
trimByGranularity(req, res, function() { trimByGranularity(req, res, function() {
t.deepEquals(res.data, expected_data, 'only street records should be here'); t.deepEquals(res.data, expected_data, 'only address records should be here');
t.end(); t.end();
}); });
} }
@ -87,13 +87,13 @@ module.exports.tests.trimByGranularity = function(test, common) {
testIt(); testIt();
}); });
test('all records with fallback.* matched_queries name should retain only address when they are most granular', function(t) { test('all records with fallback.* matched_queries name should retain only street when they are most granular', function(t) {
var req = { clean: {} }; var req = { clean: {} };
var res = { var res = {
data: [ data: [
{ name: 'address 1', _matched_queries: ['fallback.address'] }, { name: 'street 1', _matched_queries: ['fallback.street'] },
{ name: 'address 2', _matched_queries: ['fallback.address'] }, { name: 'street 2', _matched_queries: ['fallback.street'] },
{ name: 'neighbourhood 1', _matched_queries: ['fallback.neighbourhood'] }, { name: 'neighbourhood 1', _matched_queries: ['fallback.neighbourhood'] },
{ name: 'borough 1', _matched_queries: ['fallback.borough'] }, { name: 'borough 1', _matched_queries: ['fallback.borough'] },
{ name: 'locality 1', _matched_queries: ['fallback.locality'] }, { name: 'locality 1', _matched_queries: ['fallback.locality'] },
@ -109,13 +109,13 @@ module.exports.tests.trimByGranularity = function(test, common) {
}; };
var expected_data = [ var expected_data = [
{ name: 'address 1', _matched_queries: ['fallback.address'] }, { name: 'street 1', _matched_queries: ['fallback.street'] },
{ name: 'address 2', _matched_queries: ['fallback.address'] }, { name: 'street 2', _matched_queries: ['fallback.street'] },
]; ];
function testIt() { function testIt() {
trimByGranularity(req, res, function() { trimByGranularity(req, res, function() {
t.deepEquals(res.data, expected_data, 'only address records should be here'); t.deepEquals(res.data, expected_data, 'only street records should be here');
t.end(); t.end();
}); });
} }

Loading…
Cancel
Save