From 7199808f937cce81071929e146accf3b717671c9 Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Thu, 8 Dec 2016 12:55:45 -0500 Subject: [PATCH 1/5] Use a friendly message when Pelias has loaded This makes the message sent to the console when Pelias is done loading slightly friendlier. --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index e5404586..2bd4dcf5 100644 --- a/index.js +++ b/index.js @@ -3,5 +3,5 @@ var app = require('./app'), port = ( process.env.PORT || 3100 ); /** run server on the default setup (single core) **/ -console.log( 'listening on ' + port ); +console.log( 'pelias is now running on port ' + port ); app.listen( port ); From 57c54e2317316ede4a357bd47c29a4bb6e01e525 Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Thu, 8 Dec 2016 16:28:08 -0500 Subject: [PATCH 2/5] chore(package): update pelias-text-analyzer to version 1.7.0 https://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6c99fc04..4fc3ebf4 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "pelias-logger": "0.1.0", "pelias-model": "4.3.0", "pelias-query": "8.11.0", - "pelias-text-analyzer": "1.6.0", + "pelias-text-analyzer": "1.7.0", "stats-lite": "2.0.3", "through2": "^2.0.3" }, From e849710ff5ce99d7e4d8fa8b278b5c75d679b6b3 Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Thu, 8 Dec 2016 16:34:43 -0500 Subject: [PATCH 3/5] chore(package): update pelias-model to version 4.4.0 https://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4fc3ebf4..9059f0a9 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,7 @@ "pelias-config": "2.4.0", "pelias-labels": "1.5.1", "pelias-logger": "0.1.0", - "pelias-model": "4.3.0", + "pelias-model": "4.4.0", "pelias-query": "8.11.0", "pelias-text-analyzer": "1.7.0", "stats-lite": "2.0.3", From 4fa7fae546f6a6871ee06751eaf0592bd6af4a33 Mon Sep 17 00:00:00 2001 From: Diana Shkolnikov Date: Thu, 8 Dec 2016 23:07:04 -0500 Subject: [PATCH 4/5] 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) From ec91f4055f12f16df9360bee64e1fae4b44a112d Mon Sep 17 00:00:00 2001 From: Diana Shkolnikov Date: Thu, 8 Dec 2016 23:35:22 -0500 Subject: [PATCH 5/5] add controller logging --- controller/search.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/controller/search.js b/controller/search.js index 3ac135d4..f4aa3ab5 100644 --- a/controller/search.js +++ b/controller/search.js @@ -64,6 +64,9 @@ function setup( config, backend, query ){ res.meta = meta || {}; // store the query_type for subsequent middleware res.meta.query_type = renderedQuery.type; + + logger.info(`[controller:search] [queryType:${renderedQuery.type}] [es_result_count:` + + (res.data && res.data.length ? res.data.length : 0)); } logger.debug('[ES response]', docs); next();