|
|
@ -3,6 +3,8 @@ const logger = require( 'pelias-logger' ).get( 'api' ); |
|
|
|
const source_mapping = require('../helper/type_mapping').source_mapping; |
|
|
|
const source_mapping = require('../helper/type_mapping').source_mapping; |
|
|
|
const _ = require('lodash'); |
|
|
|
const _ = require('lodash'); |
|
|
|
const stable = require('stable'); |
|
|
|
const stable = require('stable'); |
|
|
|
|
|
|
|
const Debug = require('../helper/debug'); |
|
|
|
|
|
|
|
const debugLog = new Debug('middleware:interpolate'); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
example response from interpolation web service: |
|
|
|
example response from interpolation web service: |
|
|
@ -57,6 +59,7 @@ function setup(service, should_execute) { |
|
|
|
|
|
|
|
|
|
|
|
// perform interpolations asynchronously for all relevant hits
|
|
|
|
// perform interpolations asynchronously for all relevant hits
|
|
|
|
const start = (new Date()).getTime(); |
|
|
|
const start = (new Date()).getTime(); |
|
|
|
|
|
|
|
const initialTime = debugLog.beginTimer(req); |
|
|
|
|
|
|
|
|
|
|
|
logger.info(`[interpolation] [street_results] count=${street_results.length}`); |
|
|
|
logger.info(`[interpolation] [street_results] count=${street_results.length}`); |
|
|
|
|
|
|
|
|
|
|
@ -71,12 +74,14 @@ function setup(service, should_execute) { |
|
|
|
// note: leave this hit unmodified
|
|
|
|
// note: leave this hit unmodified
|
|
|
|
if (!_.has(interpolation_result, 'properties')) { |
|
|
|
if (!_.has(interpolation_result, 'properties')) { |
|
|
|
logger.debug(`[interpolation] [miss] ${req.clean.parsed_text}`); |
|
|
|
logger.debug(`[interpolation] [miss] ${req.clean.parsed_text}`); |
|
|
|
|
|
|
|
debugLog.push(req, 'miss'); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// the interpolation service returned a valid result, debug log for posterity
|
|
|
|
// the interpolation service returned a valid result, debug log for posterity
|
|
|
|
// note: we now merge those values with the existing 'street' record
|
|
|
|
// note: we now merge those values with the existing 'street' record
|
|
|
|
logger.debug(`[interpolation] [hit] ${req.clean.parsed_text} ${JSON.stringify(interpolation_result)}`); |
|
|
|
logger.debug(`[interpolation] [hit] ${req.clean.parsed_text} ${JSON.stringify(interpolation_result)}`); |
|
|
|
|
|
|
|
debugLog.push(req, interpolation_result); |
|
|
|
|
|
|
|
|
|
|
|
// -- metadata --
|
|
|
|
// -- metadata --
|
|
|
|
source_result.layer = 'address'; |
|
|
|
source_result.layer = 'address'; |
|
|
@ -126,6 +131,7 @@ function setup(service, should_execute) { |
|
|
|
|
|
|
|
|
|
|
|
// log the execution time, continue
|
|
|
|
// log the execution time, continue
|
|
|
|
logger.info( `[interpolation] [took] ${(new Date()).getTime() - start} ms`); |
|
|
|
logger.info( `[interpolation] [took] ${(new Date()).getTime() - start} ms`); |
|
|
|
|
|
|
|
debugLog.stopTimer(req, initialTime); |
|
|
|
next(); |
|
|
|
next(); |
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|