Browse Source

fix: add parser and query param logging

pull/761/head
Diana Shkolnikov 8 years ago
parent
commit
4fa7fae546
  1. 21
      query/autocomplete.js
  2. 26
      query/reverse.js
  3. 34
      query/search.js
  4. 27
      query/search_original.js

21
query/autocomplete.js

@ -1,8 +1,10 @@
'use strict';
var peliasQuery = require('pelias-query'), const peliasQuery = require('pelias-query');
defaults = require('./autocomplete_defaults'), const defaults = require('./autocomplete_defaults');
textParser = require('./text_parser_addressit'), const textParser = require('./text_parser_addressit');
check = require('check-types'); 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) // additional views (these may be merged in to pelias/query at a later date)
var views = { var views = {
@ -59,16 +61,20 @@ query.filter( peliasQuery.view.boundary_rect );
**/ **/
function generateQuery( clean ){ function generateQuery( clean ){
var vs = new peliasQuery.Vars( defaults ); const vs = new peliasQuery.Vars( defaults );
let logStr = '[query:autocomplete] [parser:addressit] ';
// sources // sources
if( check.array(clean.sources) && clean.sources.length ){ if( check.array(clean.sources) && clean.sources.length ){
vs.var( 'sources', clean.sources ); vs.var( 'sources', clean.sources );
logStr += '[param:sources] ';
} }
// layers // layers
if( check.array(clean.layers) && clean.layers.length ){ if( check.array(clean.layers) && clean.layers.length ){
vs.var( 'layers', clean.layers); vs.var( 'layers', clean.layers);
logStr += '[param:layers] ';
} }
// boundary country // boundary country
@ -76,6 +82,7 @@ function generateQuery( clean ){
vs.set({ vs.set({
'boundary:country': clean['boundary.country'] 'boundary:country': clean['boundary.country']
}); });
logStr += '[param:boundary_country] ';
} }
// pass the input tokens to the views so they can choose which tokens // 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:lat': clean['focus.point.lat'],
'focus:point:lon': clean['focus.point.lon'] 'focus:point:lon': clean['focus.point.lon']
}); });
logStr += '[param:focus_point] ';
} }
// boundary rect // boundary rect
@ -121,6 +129,7 @@ function generateQuery( clean ){
'boundary:rect:bottom': clean['boundary.rect.min_lat'], 'boundary:rect:bottom': clean['boundary.rect.min_lat'],
'boundary:rect:left': clean['boundary.rect.min_lon'] 'boundary:rect:left': clean['boundary.rect.min_lon']
}); });
logStr += '[param:boundary_rect] ';
} }
// run the address parser // run the address parser
@ -128,6 +137,8 @@ function generateQuery( clean ){
textParser( clean.parsed_text, vs ); textParser( clean.parsed_text, vs );
} }
logger.info(logStr);
return { return {
type: 'autocomplete', type: 'autocomplete',
body: query.render(vs) body: query.render(vs)

26
query/reverse.js

@ -1,6 +1,9 @@
var peliasQuery = require('pelias-query'), 'use strict';
defaults = require('./reverse_defaults'),
check = require('check-types'); 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 // reverse geocode query
@ -23,18 +26,27 @@ query.filter( peliasQuery.view.categories );
function generateQuery( clean ){ function generateQuery( clean ){
var vs = new peliasQuery.Vars( defaults ); const vs = new peliasQuery.Vars( defaults );
let logStr = '[query:reverse] ';
// set size // set size
if( clean.querySize ){ if( clean.querySize ){
vs.var( 'size', clean.querySize); vs.var( 'size', clean.querySize);
logStr += '[param:querySize] ';
} }
// sources // sources
if( check.array(clean.sources) && clean.sources.length ) {
vs.var('sources', clean.sources); vs.var('sources', clean.sources);
logStr += '[param:sources] ';
}
// layers // layers
if( check.array(clean.layers) && clean.layers.length ) {
vs.var( 'layers', clean.layers); vs.var( 'layers', clean.layers);
logStr += '[param:layers] ';
}
// focus point to score by distance // focus point to score by distance
if( check.number(clean['point.lat']) && if( check.number(clean['point.lat']) &&
@ -43,6 +55,7 @@ function generateQuery( clean ){
'focus:point:lat': clean['point.lat'], 'focus:point:lat': clean['point.lat'],
'focus:point:lon': clean['point.lon'] 'focus:point:lon': clean['point.lon']
}); });
logStr += '[param:focus_point] ';
} }
// bounding circle // bounding circle
@ -57,6 +70,7 @@ function generateQuery( clean ){
'boundary:circle:lon': clean['boundary.circle.lon'], 'boundary:circle:lon': clean['boundary.circle.lon'],
'boundary:circle:radius': clean['boundary.circle.radius'] + 'km' 'boundary:circle:radius': clean['boundary.circle.radius'] + 'km'
}); });
logStr += '[param:boundary_circle] ';
} }
// boundary country // boundary country
@ -64,13 +78,17 @@ function generateQuery( clean ){
vs.set({ vs.set({
'boundary:country': clean['boundary.country'] 'boundary:country': clean['boundary.country']
}); });
logStr += '[param:boundary_country] ';
} }
// categories // categories
if (clean.categories) { if (clean.categories) {
vs.var('input:categories', clean.categories); vs.var('input:categories', clean.categories);
logStr += '[param:categories] ';
} }
logger.info(logStr);
return { return {
type: 'reverse', type: 'reverse',
body: query.render(vs) body: query.render(vs)

34
query/search.js

@ -1,7 +1,10 @@
var peliasQuery = require('pelias-query'), 'use strict';
defaults = require('./search_defaults'),
textParser = require('./text_parser'), const peliasQuery = require('pelias-query');
check = require('check-types'); 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 // general-purpose search query
@ -41,25 +44,35 @@ geodisambiguationQuery.filter( peliasQuery.view.categories );
**/ **/
function generateQuery( clean ){ function generateQuery( clean ){
var vs = new peliasQuery.Vars( defaults ); const vs = new peliasQuery.Vars( defaults );
let logStr = '[query:search] [parser:libpostal] ';
// input text // input text
vs.var( 'input:name', clean.text ); vs.var( 'input:name', clean.text );
// sources // sources
if( check.array(clean.sources) && clean.sources.length ) {
vs.var( 'sources', clean.sources); vs.var( 'sources', clean.sources);
logStr += '[param:sources] ';
}
// layers // layers
if( check.array(clean.layers) && clean.layers.length ) {
vs.var('layers', clean.layers); vs.var('layers', clean.layers);
logStr += '[param:layers] ';
}
// categories // categories
if (clean.categories) { if (clean.categories) {
vs.var('input:categories', clean.categories); vs.var('input:categories', clean.categories);
logStr += '[param:categories] ';
} }
// size // size
if( clean.querySize ) { if( clean.querySize ) {
vs.var( 'size', clean.querySize ); vs.var( 'size', clean.querySize );
logStr += '[param:querySize] ';
} }
// focus point // focus point
@ -69,6 +82,7 @@ function generateQuery( clean ){
'focus:point:lat': clean['focus.point.lat'], 'focus:point:lat': clean['focus.point.lat'],
'focus:point:lon': clean['focus.point.lon'] 'focus:point:lon': clean['focus.point.lon']
}); });
logStr += '[param:focus_point] ';
} }
// boundary rect // boundary rect
@ -82,6 +96,7 @@ function generateQuery( clean ){
'boundary:rect:bottom': clean['boundary.rect.min_lat'], 'boundary:rect:bottom': clean['boundary.rect.min_lat'],
'boundary:rect:left': clean['boundary.rect.min_lon'] 'boundary:rect:left': clean['boundary.rect.min_lon']
}); });
logStr += '[param:boundary_rect] ';
} }
// boundary circle // boundary circle
@ -98,6 +113,7 @@ function generateQuery( clean ){
'boundary:circle:radius': Math.round( clean['boundary.circle.radius'] ) + 'km' 'boundary:circle:radius': Math.round( clean['boundary.circle.radius'] ) + 'km'
}); });
} }
logStr += '[param:boundary_circle] ';
} }
// boundary country // boundary country
@ -105,6 +121,7 @@ function generateQuery( clean ){
vs.set({ vs.set({
'boundary:country': clean['boundary.country'] 'boundary:country': clean['boundary.country']
}); });
logStr += '[param:boundary_country] ';
} }
// run the address parser // run the address parser
@ -116,6 +133,13 @@ function generateQuery( clean ){
//console.log(JSON.stringify(q, null, 2)); //console.log(JSON.stringify(q, null, 2));
if (q !== undefined) {
logger.info(logStr);
}
else {
logger.info('[parser:libpostal] query type not supported');
}
return q; return q;
} }

27
query/search_original.js

@ -1,7 +1,10 @@
var peliasQuery = require('pelias-query'), 'use strict';
defaults = require('./search_defaults'),
textParser = require('./text_parser_addressit'), const peliasQuery = require('pelias-query');
check = require('check-types'); 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'); var placeTypes = require('../helper/placeTypes');
@ -56,23 +59,33 @@ function generateQuery( clean ){
var vs = new peliasQuery.Vars( defaults ); var vs = new peliasQuery.Vars( defaults );
let logStr = '[query:search] [parser:addressit] ';
// input text // input text
vs.var( 'input:name', clean.text ); vs.var( 'input:name', clean.text );
// sources // sources
if( check.array(clean.sources) && clean.sources.length ) {
vs.var( 'sources', clean.sources); vs.var( 'sources', clean.sources);
logStr += '[param:sources] ';
}
// layers // layers
if( check.array(clean.layers) && clean.layers.length ) {
vs.var( 'layers', clean.layers); vs.var( 'layers', clean.layers);
logStr += '[param:layers] ';
}
// categories // categories
if (clean.categories) { if (clean.categories) {
vs.var('input:categories', clean.categories); vs.var('input:categories', clean.categories);
logStr += '[param:categories] ';
} }
// size // size
if( clean.querySize ) { if( clean.querySize ) {
vs.var( 'size', clean.querySize ); vs.var( 'size', clean.querySize );
logStr += '[param:size] ';
} }
// focus point // focus point
@ -82,6 +95,7 @@ function generateQuery( clean ){
'focus:point:lat': clean['focus.point.lat'], 'focus:point:lat': clean['focus.point.lat'],
'focus:point:lon': clean['focus.point.lon'] 'focus:point:lon': clean['focus.point.lon']
}); });
logStr += '[param:focus_point] ';
} }
// boundary rect // boundary rect
@ -95,6 +109,7 @@ function generateQuery( clean ){
'boundary:rect:bottom': clean['boundary.rect.min_lat'], 'boundary:rect:bottom': clean['boundary.rect.min_lat'],
'boundary:rect:left': clean['boundary.rect.min_lon'] 'boundary:rect:left': clean['boundary.rect.min_lon']
}); });
logStr += '[param:boundary_rect] ';
} }
// boundary circle // boundary circle
@ -111,6 +126,7 @@ function generateQuery( clean ){
'boundary:circle:radius': Math.round( clean['boundary.circle.radius'] ) + 'km' 'boundary:circle:radius': Math.round( clean['boundary.circle.radius'] ) + 'km'
}); });
} }
logStr += '[param:boundary_circle] ';
} }
// boundary country // boundary country
@ -118,6 +134,7 @@ function generateQuery( clean ){
vs.set({ vs.set({
'boundary:country': clean['boundary.country'] 'boundary:country': clean['boundary.country']
}); });
logStr += '[param:boundary_country] ';
} }
// run the address parser // run the address parser
@ -125,6 +142,8 @@ function generateQuery( clean ){
textParser( clean.parsed_text, vs ); textParser( clean.parsed_text, vs );
} }
logger.info(logStr);
return { return {
type: 'original', type: 'original',
body: query.render(vs) body: query.render(vs)

Loading…
Cancel
Save