Browse Source

Remove layers limiting on queries with few tokens

Primarily as a performance optimization, but also to attempt to return
more relevant results, only admin and POI layers were queried when the
text input consisted of only one or two tokens, and there weren't any
numbers. However as shown in #194 that is a bit too optimistic, mostly
in contries other than the USA.

Fixes #194
pull/222/head
Julian Simioni 9 years ago
parent
commit
139cb22127
  1. 3
      helper/query_parser.js
  2. 3
      test/unit/helper/query_parser.js

3
helper/query_parser.js

@ -13,9 +13,6 @@ module.exports.get_layers = function get_layers(query) {
if (query.length <= 3 ) {
// no address parsing required
return get_layers_helper(['admin']);
} else if (tokenized.length === 1 || (tokenized.length < 3 && !hasNumber)) {
// no need to hit address layers if there's only one (or two) token(s)
return get_layers_helper(['admin', 'poi']);
}
};

3
test/unit/helper/query_parser.js

@ -63,6 +63,7 @@ module.exports.tests.parse_one_or_more_tokens = function(test, common) {
var two_tokens_nonum = ['small town', 'biggg city', 'another empire'];
var two_tokens_withnum= ['123 main', 'sixty 1', '123-980 house'];
// parse address is now always true to fix pelias/api#194
var testParse = function(query, parse_address) {
test('query with one or more tokens (' + query + ')', function(t) {
var address = parser.get_parsed_address(query);
@ -83,7 +84,7 @@ module.exports.tests.parse_one_or_more_tokens = function(test, common) {
var queries = one_token_queries.concat(two_tokens_nonum);
for (var key in queries) {
testParse( queries[key] );
testParse( queries[key], true );
}
for (key in two_tokens_withnum) {
testParse( two_tokens_withnum[key], true );

Loading…
Cancel
Save