|
|
@ -61,12 +61,12 @@ var postProc = { |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// predicates that drive whether controller/search runs
|
|
|
|
// predicates that drive whether controller/search runs
|
|
|
|
const hasData = require('../controller/predicates/has_data'); |
|
|
|
const hasResponseData = require('../controller/predicates/has_response_data'); |
|
|
|
const hasErrors = require('../controller/predicates/has_errors'); |
|
|
|
const hasRequestErrors = require('../controller/predicates/has_request_errors'); |
|
|
|
const isCoarseReverse = require('../controller/predicates/is_coarse_reverse'); |
|
|
|
const isCoarseReverse = require('../controller/predicates/is_coarse_reverse'); |
|
|
|
|
|
|
|
|
|
|
|
// shorthand for standard early-exit conditions
|
|
|
|
// shorthand for standard early-exit conditions
|
|
|
|
const hasDataOrErrors = any(hasData, hasErrors); |
|
|
|
const hasResponseDataOrRequestErrors = any(hasResponseData, hasRequestErrors); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Append routes to app |
|
|
|
* Append routes to app |
|
|
@ -81,14 +81,14 @@ function addRoutes(app, peliasConfig) { |
|
|
|
const pipService = require('../service/pointinpolygon')(peliasConfig.api.pipService); |
|
|
|
const pipService = require('../service/pointinpolygon')(peliasConfig.api.pipService); |
|
|
|
|
|
|
|
|
|
|
|
const coarse_reverse_should_execute = all( |
|
|
|
const coarse_reverse_should_execute = all( |
|
|
|
not(hasErrors), isPipServiceEnabled, isCoarseReverse |
|
|
|
not(hasRequestErrors), isPipServiceEnabled, isCoarseReverse |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// execute under the following conditions:
|
|
|
|
// execute under the following conditions:
|
|
|
|
// - there are no errors or data
|
|
|
|
// - there are no errors or data
|
|
|
|
// - request is not coarse OR pip service is disabled
|
|
|
|
// - request is not coarse OR pip service is disabled
|
|
|
|
const original_reverse_should_execute = all( |
|
|
|
const original_reverse_should_execute = all( |
|
|
|
not(hasDataOrErrors), |
|
|
|
not(hasResponseDataOrRequestErrors), |
|
|
|
any( |
|
|
|
any( |
|
|
|
not(isCoarseReverse), |
|
|
|
not(isCoarseReverse), |
|
|
|
not(isPipServiceEnabled) |
|
|
|
not(isPipServiceEnabled) |
|
|
@ -111,9 +111,9 @@ function addRoutes(app, peliasConfig) { |
|
|
|
middleware.calcSize(), |
|
|
|
middleware.calcSize(), |
|
|
|
// 3rd parameter is which query module to use, use fallback/geodisambiguation
|
|
|
|
// 3rd parameter is which query module to use, use fallback/geodisambiguation
|
|
|
|
// first, then use original search strategy if first query didn't return anything
|
|
|
|
// first, then use original search strategy if first query didn't return anything
|
|
|
|
controllers.search(peliasConfig.api, esclient, queries.libpostal, not(hasDataOrErrors)), |
|
|
|
controllers.search(peliasConfig.api, esclient, queries.libpostal, not(hasResponseDataOrRequestErrors)), |
|
|
|
sanitizers.search_fallback.middleware, |
|
|
|
sanitizers.search_fallback.middleware, |
|
|
|
controllers.search(peliasConfig.api, esclient, queries.fallback_to_old_prod, not(hasDataOrErrors)), |
|
|
|
controllers.search(peliasConfig.api, esclient, queries.fallback_to_old_prod, not(hasResponseDataOrRequestErrors)), |
|
|
|
postProc.trimByGranularity(), |
|
|
|
postProc.trimByGranularity(), |
|
|
|
postProc.distances('focus.point.'), |
|
|
|
postProc.distances('focus.point.'), |
|
|
|
postProc.confidenceScores(peliasConfig.api), |
|
|
|
postProc.confidenceScores(peliasConfig.api), |
|
|
@ -132,7 +132,7 @@ function addRoutes(app, peliasConfig) { |
|
|
|
structured: createRouter([ |
|
|
|
structured: createRouter([ |
|
|
|
sanitizers.structured_geocoding.middleware, |
|
|
|
sanitizers.structured_geocoding.middleware, |
|
|
|
middleware.calcSize(), |
|
|
|
middleware.calcSize(), |
|
|
|
controllers.search(peliasConfig.api, esclient, queries.structured_geocoding, not(hasDataOrErrors)), |
|
|
|
controllers.search(peliasConfig.api, esclient, queries.structured_geocoding, not(hasResponseDataOrRequestErrors)), |
|
|
|
postProc.trimByGranularityStructured(), |
|
|
|
postProc.trimByGranularityStructured(), |
|
|
|
postProc.distances('focus.point.'), |
|
|
|
postProc.distances('focus.point.'), |
|
|
|
postProc.confidenceScores(peliasConfig.api), |
|
|
|
postProc.confidenceScores(peliasConfig.api), |
|
|
@ -150,7 +150,7 @@ function addRoutes(app, peliasConfig) { |
|
|
|
]), |
|
|
|
]), |
|
|
|
autocomplete: createRouter([ |
|
|
|
autocomplete: createRouter([ |
|
|
|
sanitizers.autocomplete.middleware, |
|
|
|
sanitizers.autocomplete.middleware, |
|
|
|
controllers.search(peliasConfig.api, esclient, queries.autocomplete, not(hasDataOrErrors)), |
|
|
|
controllers.search(peliasConfig.api, esclient, queries.autocomplete, not(hasResponseDataOrRequestErrors)), |
|
|
|
postProc.distances('focus.point.'), |
|
|
|
postProc.distances('focus.point.'), |
|
|
|
postProc.confidenceScores(peliasConfig.api), |
|
|
|
postProc.confidenceScores(peliasConfig.api), |
|
|
|
postProc.dedupe(), |
|
|
|
postProc.dedupe(), |
|
|
@ -185,7 +185,7 @@ function addRoutes(app, peliasConfig) { |
|
|
|
nearby: createRouter([ |
|
|
|
nearby: createRouter([ |
|
|
|
sanitizers.nearby.middleware, |
|
|
|
sanitizers.nearby.middleware, |
|
|
|
middleware.calcSize(), |
|
|
|
middleware.calcSize(), |
|
|
|
controllers.search(peliasConfig.api, esclient, queries.reverse, not(hasDataOrErrors)), |
|
|
|
controllers.search(peliasConfig.api, esclient, queries.reverse, not(hasResponseDataOrRequestErrors)), |
|
|
|
postProc.distances('point.'), |
|
|
|
postProc.distances('point.'), |
|
|
|
// reverse confidence scoring depends on distance from origin
|
|
|
|
// reverse confidence scoring depends on distance from origin
|
|
|
|
// so it must be calculated first
|
|
|
|
// so it must be calculated first
|
|
|
|