Browse Source

query module support + some minor changes

pull/1058/head
Alex Loyko 7 years ago
parent
commit
24e54144c8
  1. 31
      controller/intersections.js
  2. 6
      controller/predicates/is_intersection_layer.js
  3. 4
      query/search_intersections.js
  4. 4
      routes/v1.js

31
controller/intersections.js

@ -1,33 +1,6 @@
const _ = require('lodash'); const _ = require('lodash');
const iso3166 = require('iso3166-1'); const iso3166 = require('iso3166-1');
const util = require('../util/arrayHelper'); const intersectionsParser = require('../helper/intersectionsParsing');
/*
this function returns an object that denotes an intersection of form:
{
street1: value1,
street2: value2
}
*/
function parseIntersections(text) {
var str1 = '', str2 = '';
if(text.trim().length > 1) {
var words = text.toLowerCase().split(' ');
// remove all the whitespaces
words = util.removeWhitespaceElements(words);
words = util.EWStreetsSanitizer(words);
words = util.addOrdinality(words);
// only treat input as intersection if contains '&' or 'and'
const delimiter = _.includes(text, '&') ? '&' : 'and';
const delimiterIndex = words.indexOf(delimiter);
str1 = util.wordsToSentence(words, 0, delimiterIndex);
str2 = util.wordsToSentence(words, delimiterIndex+1, words.length);
} else {
throw 'Missing streets in the intersection';
}
return { street1: str1, street2: str2 };
}
function setup(should_execute) { function setup(should_execute) {
function controller( req, res, next ){ function controller( req, res, next ){
@ -38,7 +11,7 @@ function setup(should_execute) {
// parse text with query parser // parse text with query parser
//const parsed_text = text_analyzer.parse(req.clean.text); //const parsed_text = text_analyzer.parse(req.clean.text);
const parsed_text = parseIntersections(req.clean.text); const parsed_text = intersectionsParser(req.clean.text);
if (parsed_text !== undefined) { if (parsed_text !== undefined) {
// if a known ISO2 country was parsed, convert it to ISO3 // if a known ISO2 country was parsed, convert it to ISO3

6
controller/predicates/is_intersection_layer.js

@ -1,5 +1,9 @@
const _ = require('lodash'); const _ = require('lodash');
module.exports = (request, response) => { module.exports = (request, response) => {
return _.includes(request.query.text, '&') || _.includes(request.query.text, ' and '); if(request) {
return _.includes(request.query.text, '&') || _.includes(request.query.text, ' and ');
}
return false;
}; };

4
query/search_intersections.js

@ -195,8 +195,8 @@ function generateQuery(clean) {
] ]
} } } }
] ]
} }
} }
}; };
} }

4
routes/v1.js

@ -132,7 +132,7 @@ function addRoutes(app, peliasConfig) {
); );
// defines whether to skip libpostal and control should be switched to intersection processing // defines whether to skip libpostal and control should be switched to intersection processing
const IntersectionParserShouldExecute = all ( const intersectionParserShouldExecute = all (
isIntersectionLayer, isIntersectionLayer,
not(hasRequestErrors) not(hasRequestErrors)
); );
@ -274,7 +274,7 @@ function addRoutes(app, peliasConfig) {
sanitizers.search.middleware(peliasConfig.api), sanitizers.search.middleware(peliasConfig.api),
middleware.requestLanguage, middleware.requestLanguage,
middleware.calcSize(), middleware.calcSize(),
controllers.intersection(IntersectionParserShouldExecute), controllers.intersection(intersectionParserShouldExecute),
controllers.libpostal(libpostalShouldExecute), controllers.libpostal(libpostalShouldExecute),
controllers.placeholder(placeholderService, geometricFiltersApply, placeholderGeodisambiguationShouldExecute), controllers.placeholder(placeholderService, geometricFiltersApply, placeholderGeodisambiguationShouldExecute),
controllers.placeholder(placeholderService, geometricFiltersDontApply, placeholderIdsLookupShouldExecute), controllers.placeholder(placeholderService, geometricFiltersDontApply, placeholderIdsLookupShouldExecute),

Loading…
Cancel
Save