Browse Source

Merge pull request #765 from pelias/master

Merge master to staging
pull/764/head
Julian Simioni 8 years ago committed by GitHub
parent
commit
e6c25b2b92
  1. 3
      controller/search.js
  2. 2
      package.json
  3. 21
      query/autocomplete.js
  4. 30
      query/reverse.js
  5. 38
      query/search.js
  6. 31
      query/search_original.js

3
controller/search.js

@ -64,6 +64,9 @@ function setup( config, backend, query ){
res.meta = meta || {}; res.meta = meta || {};
// store the query_type for subsequent middleware // store the query_type for subsequent middleware
res.meta.query_type = renderedQuery.type; 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); logger.debug('[ES response]', docs);
next(); next();

2
package.json

@ -55,7 +55,7 @@
"pelias-config": "2.4.0", "pelias-config": "2.4.0",
"pelias-labels": "1.5.1", "pelias-labels": "1.5.1",
"pelias-logger": "0.1.0", "pelias-logger": "0.1.0",
"pelias-model": "4.3.0", "pelias-model": "4.4.0",
"pelias-query": "8.11.0", "pelias-query": "8.11.0",
"pelias-text-analyzer": "1.7.0", "pelias-text-analyzer": "1.7.0",
"stats-lite": "2.0.3", "stats-lite": "2.0.3",

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)

30
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
vs.var( 'sources', clean.sources); if( check.array(clean.sources) && clean.sources.length ) {
vs.var('sources', clean.sources);
logStr += '[param:sources] ';
}
// layers // 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 // 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)

38
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
vs.var( 'sources', clean.sources); if( check.array(clean.sources) && clean.sources.length ) {
vs.var( 'sources', clean.sources);
logStr += '[param:sources] ';
}
// layers // layers
vs.var( 'layers', clean.layers); if( check.array(clean.layers) && clean.layers.length ) {
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;
} }

31
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
vs.var( 'sources', clean.sources); if( check.array(clean.sources) && clean.sources.length ) {
vs.var( 'sources', clean.sources);
logStr += '[param:sources] ';
}
// layers // layers
vs.var( 'layers', clean.layers); if( check.array(clean.layers) && clean.layers.length ) {
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