diff --git a/query/autocomplete.js b/query/autocomplete.js index d0e766f3..951962be 100644 --- a/query/autocomplete.js +++ b/query/autocomplete.js @@ -49,6 +49,7 @@ query.score( peliasQuery.view.population( views.pop_subquery ) ); // non-scoring hard filters query.filter( peliasQuery.view.sources ); query.filter( peliasQuery.view.layers ); +query.filter( peliasQuery.view.boundary_rect ); // -------------------------------- @@ -109,6 +110,19 @@ function generateQuery( clean ){ }); } + // boundary rect + if( check.number(clean['boundary.rect.min_lat']) && + check.number(clean['boundary.rect.max_lat']) && + check.number(clean['boundary.rect.min_lon']) && + check.number(clean['boundary.rect.max_lon']) ){ + vs.set({ + 'boundary:rect:top': clean['boundary.rect.max_lat'], + 'boundary:rect:right': clean['boundary.rect.max_lon'], + 'boundary:rect:bottom': clean['boundary.rect.min_lat'], + 'boundary:rect:left': clean['boundary.rect.min_lon'] + }); + } + // run the address parser if( clean.parsed_text ){ textParser( clean.parsed_text, vs ); @@ -120,4 +134,4 @@ function generateQuery( clean ){ }; } -module.exports = generateQuery; \ No newline at end of file +module.exports = generateQuery; diff --git a/test/unit/fixture/autocomplete_linguistic_bbox_san_francisco.js b/test/unit/fixture/autocomplete_linguistic_bbox_san_francisco.js new file mode 100644 index 00000000..5e47e603 --- /dev/null +++ b/test/unit/fixture/autocomplete_linguistic_bbox_san_francisco.js @@ -0,0 +1,71 @@ +module.exports = { + 'query': { + 'bool': { + 'must': [{ + 'constant_score': { + 'query': { + 'match': { + 'name.default': { + 'analyzer': 'peliasQueryPartialToken', + 'boost': 100, + 'query': 'test', + 'type': 'phrase', + 'operator': 'and', + 'slop': 3 + } + } + } + } + }], + 'should':[{ + 'function_score': { + 'query': { + 'match_all': {} + }, + 'max_boost': 20, + 'score_mode': 'first', + 'boost_mode': 'replace', + 'functions': [{ + 'field_value_factor': { + 'modifier': 'log1p', + 'field': 'popularity', + 'missing': 1 + }, + 'weight': 1 + }] + } + },{ + 'function_score': { + 'query': { + 'match_all': {} + }, + 'max_boost': 20, + 'score_mode': 'first', + 'boost_mode': 'replace', + 'functions': [{ + 'field_value_factor': { + 'modifier': 'log1p', + 'field': 'population', + 'missing': 1 + }, + 'weight': 3 + }] + } + }], + 'filter': [{ + 'geo_bounding_box': { + 'type': 'indexed', + 'center_point': { + 'top': 37.83239, + 'right': -122.35698, + 'bottom': 37.70808, + 'left': -122.51489 + } + } + }] + } + }, + 'sort': [ '_score' ], + 'size': 20, + 'track_scores': true +}; diff --git a/test/unit/query/autocomplete.js b/test/unit/query/autocomplete.js index 64b6c447..3903d468 100644 --- a/test/unit/query/autocomplete.js +++ b/test/unit/query/autocomplete.js @@ -189,6 +189,26 @@ module.exports.tests.query = function(test, common) { t.deepEqual(compiled.body, expected, 'autocomplete: valid boundary.country query'); t.end(); }); + + test('autocomplete + bbox around San Francisco', function(t) { + var query = generate({ + text: 'test', + 'boundary.rect.max_lat': 37.83239, + 'boundary.rect.max_lon': -122.35698, + 'boundary.rect.min_lat': 37.70808, + 'boundary.rect.min_lon': -122.51489, + tokens: ['test'], + tokens_complete: [], + tokens_incomplete: ['test'] + }); + + var compiled = JSON.parse( JSON.stringify( query ) ); + var expected = require('../fixture/autocomplete_linguistic_bbox_san_francisco'); + + t.deepEqual(compiled.type, 'autocomplete', 'query type set'); + t.deepEqual(compiled.body, expected, 'autocomplete_linguistic_focus_null_island'); + t.end(); + }); }; module.exports.all = function (tape, common) {