|
|
@ -1,194 +1,177 @@ |
|
|
|
/* eslint-disable */ |
|
|
|
/* eslint-disable */ |
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// 'use strict';
|
|
|
|
'use strict'; |
|
|
|
//
|
|
|
|
|
|
|
|
// const peliasQuery = require('pelias-query');
|
|
|
|
const peliasQuery = require('pelias-query'); |
|
|
|
// const defaults = require('./search_defaults');
|
|
|
|
const defaults = require('./search_defaults'); |
|
|
|
// const textParser = require('./text_parser');
|
|
|
|
const textParser = require('./text_parser'); |
|
|
|
// const check = require('check-types');
|
|
|
|
const check = require('check-types'); |
|
|
|
// const logger = require('pelias-logger').get('api');
|
|
|
|
const logger = require('pelias-logger').get('api'); |
|
|
|
//
|
|
|
|
|
|
|
|
// //------------------------------
|
|
|
|
//------------------------------
|
|
|
|
// // general-purpose search query
|
|
|
|
// general-purpose search query
|
|
|
|
// //------------------------------
|
|
|
|
//------------------------------
|
|
|
|
// var fallbackQuery = new peliasQuery.layout.FallbackQuery();
|
|
|
|
var fallbackQuery = new peliasQuery.layout.FallbackQuery(); |
|
|
|
//
|
|
|
|
|
|
|
|
// // scoring boost
|
|
|
|
// scoring boost
|
|
|
|
// fallbackQuery.score( peliasQuery.view.focus_only_function( peliasQuery.view.phrase ) );
|
|
|
|
fallbackQuery.score( peliasQuery.view.focus_only_function( peliasQuery.view.phrase ) ); |
|
|
|
// fallbackQuery.score( peliasQuery.view.popularity_only_function );
|
|
|
|
fallbackQuery.score( peliasQuery.view.popularity_only_function ); |
|
|
|
// fallbackQuery.score( peliasQuery.view.population_only_function );
|
|
|
|
fallbackQuery.score( peliasQuery.view.population_only_function ); |
|
|
|
// // --------------------------------
|
|
|
|
// --------------------------------
|
|
|
|
//
|
|
|
|
|
|
|
|
// // non-scoring hard filters
|
|
|
|
// non-scoring hard filters
|
|
|
|
// fallbackQuery.filter( peliasQuery.view.boundary_country );
|
|
|
|
fallbackQuery.filter( peliasQuery.view.boundary_country ); |
|
|
|
// fallbackQuery.filter( peliasQuery.view.boundary_circle );
|
|
|
|
fallbackQuery.filter( peliasQuery.view.boundary_circle ); |
|
|
|
// fallbackQuery.filter( peliasQuery.view.boundary_rect );
|
|
|
|
fallbackQuery.filter( peliasQuery.view.boundary_rect ); |
|
|
|
// fallbackQuery.filter( peliasQuery.view.sources );
|
|
|
|
fallbackQuery.filter( peliasQuery.view.sources ); |
|
|
|
// fallbackQuery.filter( peliasQuery.view.layers );
|
|
|
|
fallbackQuery.filter( peliasQuery.view.layers ); |
|
|
|
// fallbackQuery.filter( peliasQuery.view.categories );
|
|
|
|
fallbackQuery.filter( peliasQuery.view.categories ); |
|
|
|
// // --------------------------------
|
|
|
|
// --------------------------------
|
|
|
|
//
|
|
|
|
|
|
|
|
// /**
|
|
|
|
/** |
|
|
|
// map request variables to query variables for all inputs
|
|
|
|
map request variables to query variables for all inputs |
|
|
|
// provided by this HTTP request.
|
|
|
|
provided by this HTTP request. |
|
|
|
// **/
|
|
|
|
**/ |
|
|
|
// function generateQuery( clean ){
|
|
|
|
function generateQuery( clean ){ |
|
|
|
//
|
|
|
|
|
|
|
|
// console.log("I am in intersections query");
|
|
|
|
const vs = new peliasQuery.Vars( defaults ); |
|
|
|
//
|
|
|
|
|
|
|
|
// const vs = new peliasQuery.Vars( defaults );
|
|
|
|
let logStr = '[query:search] [parser:intersections_parser] '; |
|
|
|
//
|
|
|
|
|
|
|
|
// let logStr = '[query:search] [parser:intersections_parser] ';
|
|
|
|
// input text
|
|
|
|
//
|
|
|
|
vs.var( 'input:name', clean.text ); |
|
|
|
// // input text
|
|
|
|
|
|
|
|
// vs.var( 'input:name', clean.text );
|
|
|
|
// sources
|
|
|
|
//
|
|
|
|
if( check.array(clean.sources) && clean.sources.length ) { |
|
|
|
// // sources
|
|
|
|
vs.var( 'sources', clean.sources); |
|
|
|
// if( check.array(clean.sources) && clean.sources.length ) {
|
|
|
|
logStr += '[param:sources] '; |
|
|
|
// vs.var( 'sources', clean.sources);
|
|
|
|
} |
|
|
|
// logStr += '[param:sources] ';
|
|
|
|
|
|
|
|
// }
|
|
|
|
// layers
|
|
|
|
//
|
|
|
|
if( check.array(clean.layers) && clean.layers.length ) { |
|
|
|
// // layers
|
|
|
|
vs.var('layers', clean.layers); |
|
|
|
// if( check.array(clean.layers) && clean.layers.length ) {
|
|
|
|
logStr += '[param:layers] '; |
|
|
|
// vs.var('layers', clean.layers);
|
|
|
|
} |
|
|
|
// logStr += '[param:layers] ';
|
|
|
|
|
|
|
|
// }
|
|
|
|
// categories
|
|
|
|
//
|
|
|
|
if (clean.categories) { |
|
|
|
// // categories
|
|
|
|
vs.var('input:categories', clean.categories); |
|
|
|
// if (clean.categories) {
|
|
|
|
logStr += '[param:categories] '; |
|
|
|
// vs.var('input:categories', clean.categories);
|
|
|
|
} |
|
|
|
// logStr += '[param:categories] ';
|
|
|
|
|
|
|
|
// }
|
|
|
|
// size
|
|
|
|
//
|
|
|
|
if( clean.querySize ) { |
|
|
|
// // size
|
|
|
|
vs.var( 'size', clean.querySize ); |
|
|
|
// if( clean.querySize ) {
|
|
|
|
logStr += '[param:querySize] '; |
|
|
|
// vs.var( 'size', clean.querySize );
|
|
|
|
} |
|
|
|
// logStr += '[param:querySize] ';
|
|
|
|
|
|
|
|
// }
|
|
|
|
// focus point
|
|
|
|
//
|
|
|
|
if( check.number(clean['focus.point.lat']) && |
|
|
|
// // focus point
|
|
|
|
check.number(clean['focus.point.lon']) ){ |
|
|
|
// if( check.number(clean['focus.point.lat']) &&
|
|
|
|
vs.set({ |
|
|
|
// check.number(clean['focus.point.lon']) ){
|
|
|
|
'focus:point:lat': clean['focus.point.lat'], |
|
|
|
// vs.set({
|
|
|
|
'focus:point:lon': clean['focus.point.lon'] |
|
|
|
// 'focus:point:lat': clean['focus.point.lat'],
|
|
|
|
}); |
|
|
|
// 'focus:point:lon': clean['focus.point.lon']
|
|
|
|
logStr += '[param:focus_point] '; |
|
|
|
// });
|
|
|
|
} |
|
|
|
// logStr += '[param:focus_point] ';
|
|
|
|
|
|
|
|
// }
|
|
|
|
// boundary rect
|
|
|
|
//
|
|
|
|
if( check.number(clean['boundary.rect.min_lat']) && |
|
|
|
// // boundary rect
|
|
|
|
check.number(clean['boundary.rect.max_lat']) && |
|
|
|
// if( check.number(clean['boundary.rect.min_lat']) &&
|
|
|
|
check.number(clean['boundary.rect.min_lon']) && |
|
|
|
// check.number(clean['boundary.rect.max_lat']) &&
|
|
|
|
check.number(clean['boundary.rect.max_lon']) ){ |
|
|
|
// check.number(clean['boundary.rect.min_lon']) &&
|
|
|
|
vs.set({ |
|
|
|
// check.number(clean['boundary.rect.max_lon']) ){
|
|
|
|
'boundary:rect:top': clean['boundary.rect.max_lat'], |
|
|
|
// vs.set({
|
|
|
|
'boundary:rect:right': clean['boundary.rect.max_lon'], |
|
|
|
// 'boundary:rect:top': clean['boundary.rect.max_lat'],
|
|
|
|
'boundary:rect:bottom': clean['boundary.rect.min_lat'], |
|
|
|
// 'boundary:rect:right': clean['boundary.rect.max_lon'],
|
|
|
|
'boundary:rect:left': clean['boundary.rect.min_lon'] |
|
|
|
// 'boundary:rect:bottom': clean['boundary.rect.min_lat'],
|
|
|
|
}); |
|
|
|
// 'boundary:rect:left': clean['boundary.rect.min_lon']
|
|
|
|
logStr += '[param:boundary_rect] '; |
|
|
|
// });
|
|
|
|
} |
|
|
|
// logStr += '[param:boundary_rect] ';
|
|
|
|
|
|
|
|
// }
|
|
|
|
// boundary circle
|
|
|
|
//
|
|
|
|
// @todo: change these to the correct request variable names
|
|
|
|
// // boundary circle
|
|
|
|
if( check.number(clean['boundary.circle.lat']) && |
|
|
|
// // @todo: change these to the correct request variable names
|
|
|
|
check.number(clean['boundary.circle.lon']) ){ |
|
|
|
// if( check.number(clean['boundary.circle.lat']) &&
|
|
|
|
vs.set({ |
|
|
|
// check.number(clean['boundary.circle.lon']) ){
|
|
|
|
'boundary:circle:lat': clean['boundary.circle.lat'], |
|
|
|
// vs.set({
|
|
|
|
'boundary:circle:lon': clean['boundary.circle.lon'] |
|
|
|
// 'boundary:circle:lat': clean['boundary.circle.lat'],
|
|
|
|
}); |
|
|
|
// 'boundary:circle:lon': clean['boundary.circle.lon']
|
|
|
|
|
|
|
|
// });
|
|
|
|
if( check.number(clean['boundary.circle.radius']) ){ |
|
|
|
//
|
|
|
|
vs.set({ |
|
|
|
// if( check.number(clean['boundary.circle.radius']) ){
|
|
|
|
'boundary:circle:radius': Math.round( clean['boundary.circle.radius'] ) + 'km' |
|
|
|
// vs.set({
|
|
|
|
}); |
|
|
|
// 'boundary:circle:radius': Math.round( clean['boundary.circle.radius'] ) + 'km'
|
|
|
|
} |
|
|
|
// });
|
|
|
|
logStr += '[param:boundary_circle] '; |
|
|
|
// }
|
|
|
|
} |
|
|
|
// logStr += '[param:boundary_circle] ';
|
|
|
|
|
|
|
|
// }
|
|
|
|
// boundary country
|
|
|
|
//
|
|
|
|
if( check.string(clean['boundary.country']) ){ |
|
|
|
// // boundary country
|
|
|
|
vs.set({ |
|
|
|
// if( check.string(clean['boundary.country']) ){
|
|
|
|
'boundary:country': clean['boundary.country'] |
|
|
|
// vs.set({
|
|
|
|
}); |
|
|
|
// 'boundary:country': clean['boundary.country']
|
|
|
|
logStr += '[param:boundary_country] '; |
|
|
|
// });
|
|
|
|
} |
|
|
|
// logStr += '[param:boundary_country] ';
|
|
|
|
|
|
|
|
// }
|
|
|
|
// run the address parser
|
|
|
|
//
|
|
|
|
if( clean.parsed_text ){ |
|
|
|
// // run the address parser
|
|
|
|
textParser( clean.parsed_text, vs ); |
|
|
|
// if( clean.parsed_text ){
|
|
|
|
} |
|
|
|
// textParser( clean.parsed_text, vs );
|
|
|
|
|
|
|
|
// }
|
|
|
|
var q = getQuery(vs,clean); |
|
|
|
//
|
|
|
|
|
|
|
|
// var q = getQuery(vs);
|
|
|
|
//console.log(JSON.stringify(q, null, 2));
|
|
|
|
//
|
|
|
|
|
|
|
|
// //console.log(JSON.stringify(q, null, 2));
|
|
|
|
if (q !== undefined) { |
|
|
|
//
|
|
|
|
logger.info(logStr); |
|
|
|
// if (q !== undefined) {
|
|
|
|
} |
|
|
|
// logger.info(logStr);
|
|
|
|
else { |
|
|
|
// }
|
|
|
|
logger.info('[parser:intersections] query type not supported'); |
|
|
|
// else {
|
|
|
|
} |
|
|
|
// logger.info('[parser:intersections] query type not supported');
|
|
|
|
|
|
|
|
// }
|
|
|
|
return q; |
|
|
|
//
|
|
|
|
} |
|
|
|
// return q;
|
|
|
|
|
|
|
|
// }
|
|
|
|
function getQuery(vs, clean) { |
|
|
|
//
|
|
|
|
|
|
|
|
// function getQuery(vs) {
|
|
|
|
logger.info(`[query:search] [search_input_type:${determineQueryType(vs)}]`); |
|
|
|
//
|
|
|
|
|
|
|
|
// logger.info(`[query:search] [search_input_type:${determineQueryType(vs)}]`);
|
|
|
|
if (hasIntersection(vs)) { |
|
|
|
//
|
|
|
|
return generateQuery(clean); |
|
|
|
// if (hasStreet(vs) || isPostalCodeOnly(vs)) {
|
|
|
|
} |
|
|
|
// return {
|
|
|
|
|
|
|
|
// type: 'fallback',
|
|
|
|
// returning undefined is a signal to a later step that the addressit-parsed
|
|
|
|
// body: fallbackQuery.render(vs)
|
|
|
|
// query should be queried for
|
|
|
|
// };
|
|
|
|
return undefined; |
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
} |
|
|
|
// // returning undefined is a signal to a later step that the addressit-parsed
|
|
|
|
|
|
|
|
// // query should be queried for
|
|
|
|
function determineQueryType(vs) { |
|
|
|
// return undefined;
|
|
|
|
if (vs.isset('input:housenumber') && vs.isset('input:street')) { |
|
|
|
//
|
|
|
|
return 'address'; |
|
|
|
// }
|
|
|
|
} |
|
|
|
//
|
|
|
|
else if (vs.isset('input:street')) { |
|
|
|
// function determineQueryType(vs) {
|
|
|
|
return 'street'; |
|
|
|
// if (vs.isset('input:housenumber') && vs.isset('input:street')) {
|
|
|
|
} |
|
|
|
// return 'address';
|
|
|
|
else if (vs.isset('input:street1') || vs.isset('input:street2')) { |
|
|
|
// }
|
|
|
|
return 'intersection'; |
|
|
|
// else if (vs.isset('input:street')) {
|
|
|
|
} |
|
|
|
// return 'street';
|
|
|
|
else if (vs.isset('input:query')) { |
|
|
|
// }
|
|
|
|
return 'venue'; |
|
|
|
// else if (vs.isset('input:street1') || vs.isset('input:street2')) {
|
|
|
|
} |
|
|
|
// return 'intersection';
|
|
|
|
else if (['neighbourhood', 'borough', 'postcode', 'county', 'region','country'].some( |
|
|
|
// }
|
|
|
|
layer => vs.isset(`input:${layer}`) |
|
|
|
// else if (vs.isset('input:query')) {
|
|
|
|
)) { |
|
|
|
// return 'venue';
|
|
|
|
return 'admin'; |
|
|
|
// }
|
|
|
|
} |
|
|
|
// else if (['neighbourhood', 'borough', 'postcode', 'county', 'region','country'].some(
|
|
|
|
return 'other'; |
|
|
|
// layer => vs.isset(`input:${layer}`)
|
|
|
|
} |
|
|
|
// )) {
|
|
|
|
|
|
|
|
// return 'admin';
|
|
|
|
function hasIntersection(vs) { |
|
|
|
// }
|
|
|
|
return vs.isset('input:street1') && vs.isset('input:street2'); |
|
|
|
// return 'other';
|
|
|
|
} |
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// function hasStreet(vs) {
|
|
|
|
|
|
|
|
// return vs.isset('input:street') || vs.isset('input:street1') || vs.isset('input:street2');
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// function isPostalCodeOnly(vs) {
|
|
|
|
|
|
|
|
// var isSet = layer => vs.isset(`input:${layer}`);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// var allowedFields = ['postcode'];
|
|
|
|
|
|
|
|
// var disallowedFields = ['query', 'category', 'housenumber', 'street',
|
|
|
|
|
|
|
|
// 'neighbourhood', 'borough', 'county', 'region', 'country'];
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// return allowedFields.every(isSet) &&
|
|
|
|
|
|
|
|
// !disallowedFields.some(isSet);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function generateQuery(clean) { |
|
|
|
function generateQuery(clean) { |
|
|
|
return { |
|
|
|
return { |
|
|
|