From 4fa7fae546f6a6871ee06751eaf0592bd6af4a33 Mon Sep 17 00:00:00 2001 From: Diana Shkolnikov Date: Thu, 8 Dec 2016 23:07:04 -0500 Subject: [PATCH] fix: add parser and query param logging --- query/autocomplete.js | 21 ++++++++++++++++----- query/reverse.js | 30 ++++++++++++++++++++++++------ query/search.js | 38 +++++++++++++++++++++++++++++++------- query/search_original.js | 31 +++++++++++++++++++++++++------ 4 files changed, 96 insertions(+), 24 deletions(-) diff --git a/query/autocomplete.js b/query/autocomplete.js index 951962be..e7dbed3f 100644 --- a/query/autocomplete.js +++ b/query/autocomplete.js @@ -1,8 +1,10 @@ +'use strict'; -var peliasQuery = require('pelias-query'), - defaults = require('./autocomplete_defaults'), - textParser = require('./text_parser_addressit'), - check = require('check-types'); +const peliasQuery = require('pelias-query'); +const defaults = require('./autocomplete_defaults'); +const textParser = require('./text_parser_addressit'); +const check = require('check-types'); +const logger = require('pelias-logger').get('api'); // additional views (these may be merged in to pelias/query at a later date) var views = { @@ -59,16 +61,20 @@ query.filter( peliasQuery.view.boundary_rect ); **/ function generateQuery( clean ){ - var vs = new peliasQuery.Vars( defaults ); + const vs = new peliasQuery.Vars( defaults ); + + let logStr = '[query:autocomplete] [parser:addressit] '; // sources if( check.array(clean.sources) && clean.sources.length ){ vs.var( 'sources', clean.sources ); + logStr += '[param:sources] '; } // layers if( check.array(clean.layers) && clean.layers.length ){ vs.var( 'layers', clean.layers); + logStr += '[param:layers] '; } // boundary country @@ -76,6 +82,7 @@ function generateQuery( clean ){ vs.set({ 'boundary:country': clean['boundary.country'] }); + logStr += '[param:boundary_country] '; } // pass the input tokens to the views so they can choose which tokens @@ -108,6 +115,7 @@ function generateQuery( clean ){ 'focus:point:lat': clean['focus.point.lat'], 'focus:point:lon': clean['focus.point.lon'] }); + logStr += '[param:focus_point] '; } // boundary rect @@ -121,6 +129,7 @@ function generateQuery( clean ){ 'boundary:rect:bottom': clean['boundary.rect.min_lat'], 'boundary:rect:left': clean['boundary.rect.min_lon'] }); + logStr += '[param:boundary_rect] '; } // run the address parser @@ -128,6 +137,8 @@ function generateQuery( clean ){ textParser( clean.parsed_text, vs ); } + logger.info(logStr); + return { type: 'autocomplete', body: query.render(vs) diff --git a/query/reverse.js b/query/reverse.js index 8cb2fa44..72a3c3a6 100644 --- a/query/reverse.js +++ b/query/reverse.js @@ -1,6 +1,9 @@ -var peliasQuery = require('pelias-query'), - defaults = require('./reverse_defaults'), - check = require('check-types'); +'use strict'; + +const peliasQuery = require('pelias-query'); +const defaults = require('./reverse_defaults'); +const check = require('check-types'); +const logger = require('pelias-logger').get('api'); //------------------------------ // reverse geocode query @@ -23,18 +26,27 @@ query.filter( peliasQuery.view.categories ); function generateQuery( clean ){ - var vs = new peliasQuery.Vars( defaults ); + const vs = new peliasQuery.Vars( defaults ); + + let logStr = '[query:reverse] '; // set size if( clean.querySize ){ vs.var( 'size', clean.querySize); + logStr += '[param:querySize] '; } // sources - vs.var( 'sources', clean.sources); + if( check.array(clean.sources) && clean.sources.length ) { + vs.var('sources', clean.sources); + logStr += '[param:sources] '; + } // layers - vs.var( 'layers', clean.layers); + if( check.array(clean.layers) && clean.layers.length ) { + vs.var( 'layers', clean.layers); + logStr += '[param:layers] '; + } // focus point to score by distance if( check.number(clean['point.lat']) && @@ -43,6 +55,7 @@ function generateQuery( clean ){ 'focus:point:lat': clean['point.lat'], 'focus:point:lon': clean['point.lon'] }); + logStr += '[param:focus_point] '; } // bounding circle @@ -57,6 +70,7 @@ function generateQuery( clean ){ 'boundary:circle:lon': clean['boundary.circle.lon'], 'boundary:circle:radius': clean['boundary.circle.radius'] + 'km' }); + logStr += '[param:boundary_circle] '; } // boundary country @@ -64,13 +78,17 @@ function generateQuery( clean ){ vs.set({ 'boundary:country': clean['boundary.country'] }); + logStr += '[param:boundary_country] '; } // categories if (clean.categories) { vs.var('input:categories', clean.categories); + logStr += '[param:categories] '; } + logger.info(logStr); + return { type: 'reverse', body: query.render(vs) diff --git a/query/search.js b/query/search.js index 41e5775f..48b47f31 100644 --- a/query/search.js +++ b/query/search.js @@ -1,7 +1,10 @@ -var peliasQuery = require('pelias-query'), - defaults = require('./search_defaults'), - textParser = require('./text_parser'), - check = require('check-types'); +'use strict'; + +const peliasQuery = require('pelias-query'); +const defaults = require('./search_defaults'); +const textParser = require('./text_parser'); +const check = require('check-types'); +const logger = require('pelias-logger').get('api'); //------------------------------ // general-purpose search query @@ -41,25 +44,35 @@ geodisambiguationQuery.filter( peliasQuery.view.categories ); **/ function generateQuery( clean ){ - var vs = new peliasQuery.Vars( defaults ); + const vs = new peliasQuery.Vars( defaults ); + + let logStr = '[query:search] [parser:libpostal] '; // input text vs.var( 'input:name', clean.text ); // sources - vs.var( 'sources', clean.sources); + if( check.array(clean.sources) && clean.sources.length ) { + vs.var( 'sources', clean.sources); + logStr += '[param:sources] '; + } // layers - vs.var( 'layers', clean.layers); + if( check.array(clean.layers) && clean.layers.length ) { + vs.var('layers', clean.layers); + logStr += '[param:layers] '; + } // categories if (clean.categories) { vs.var('input:categories', clean.categories); + logStr += '[param:categories] '; } // size if( clean.querySize ) { vs.var( 'size', clean.querySize ); + logStr += '[param:querySize] '; } // focus point @@ -69,6 +82,7 @@ function generateQuery( clean ){ 'focus:point:lat': clean['focus.point.lat'], 'focus:point:lon': clean['focus.point.lon'] }); + logStr += '[param:focus_point] '; } // boundary rect @@ -82,6 +96,7 @@ function generateQuery( clean ){ 'boundary:rect:bottom': clean['boundary.rect.min_lat'], 'boundary:rect:left': clean['boundary.rect.min_lon'] }); + logStr += '[param:boundary_rect] '; } // boundary circle @@ -98,6 +113,7 @@ function generateQuery( clean ){ 'boundary:circle:radius': Math.round( clean['boundary.circle.radius'] ) + 'km' }); } + logStr += '[param:boundary_circle] '; } // boundary country @@ -105,6 +121,7 @@ function generateQuery( clean ){ vs.set({ 'boundary:country': clean['boundary.country'] }); + logStr += '[param:boundary_country] '; } // run the address parser @@ -116,6 +133,13 @@ function generateQuery( clean ){ //console.log(JSON.stringify(q, null, 2)); + if (q !== undefined) { + logger.info(logStr); + } + else { + logger.info('[parser:libpostal] query type not supported'); + } + return q; } diff --git a/query/search_original.js b/query/search_original.js index e4a0dc66..a6b666d6 100644 --- a/query/search_original.js +++ b/query/search_original.js @@ -1,7 +1,10 @@ -var peliasQuery = require('pelias-query'), - defaults = require('./search_defaults'), - textParser = require('./text_parser_addressit'), - check = require('check-types'); +'use strict'; + +const peliasQuery = require('pelias-query'); +const defaults = require('./search_defaults'); +const textParser = require('./text_parser_addressit'); +const check = require('check-types'); +const logger = require('pelias-logger').get('api'); var placeTypes = require('../helper/placeTypes'); @@ -56,23 +59,33 @@ function generateQuery( clean ){ var vs = new peliasQuery.Vars( defaults ); + let logStr = '[query:search] [parser:addressit] '; + // input text vs.var( 'input:name', clean.text ); // sources - vs.var( 'sources', clean.sources); + if( check.array(clean.sources) && clean.sources.length ) { + vs.var( 'sources', clean.sources); + logStr += '[param:sources] '; + } // layers - vs.var( 'layers', clean.layers); + if( check.array(clean.layers) && clean.layers.length ) { + vs.var( 'layers', clean.layers); + logStr += '[param:layers] '; + } // categories if (clean.categories) { vs.var('input:categories', clean.categories); + logStr += '[param:categories] '; } // size if( clean.querySize ) { vs.var( 'size', clean.querySize ); + logStr += '[param:size] '; } // focus point @@ -82,6 +95,7 @@ function generateQuery( clean ){ 'focus:point:lat': clean['focus.point.lat'], 'focus:point:lon': clean['focus.point.lon'] }); + logStr += '[param:focus_point] '; } // boundary rect @@ -95,6 +109,7 @@ function generateQuery( clean ){ 'boundary:rect:bottom': clean['boundary.rect.min_lat'], 'boundary:rect:left': clean['boundary.rect.min_lon'] }); + logStr += '[param:boundary_rect] '; } // boundary circle @@ -111,6 +126,7 @@ function generateQuery( clean ){ 'boundary:circle:radius': Math.round( clean['boundary.circle.radius'] ) + 'km' }); } + logStr += '[param:boundary_circle] '; } // boundary country @@ -118,6 +134,7 @@ function generateQuery( clean ){ vs.set({ 'boundary:country': clean['boundary.country'] }); + logStr += '[param:boundary_country] '; } // run the address parser @@ -125,6 +142,8 @@ function generateQuery( clean ){ textParser( clean.parsed_text, vs ); } + logger.info(logStr); + return { type: 'original', body: query.render(vs)