Browse Source

Add boundary.rect handling to query/autocomplete

pull/703/head
Julian Simioni 8 years ago
parent
commit
78cc4a5de3
No known key found for this signature in database
GPG Key ID: B9EEB0C6EE0910A1
  1. 16
      query/autocomplete.js
  2. 71
      test/unit/fixture/autocomplete_linguistic_bbox_san_francisco.js
  3. 20
      test/unit/query/autocomplete.js

16
query/autocomplete.js

@ -49,6 +49,7 @@ query.score( peliasQuery.view.population( views.pop_subquery ) );
// non-scoring hard filters // non-scoring hard filters
query.filter( peliasQuery.view.sources ); query.filter( peliasQuery.view.sources );
query.filter( peliasQuery.view.layers ); 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 // run the address parser
if( clean.parsed_text ){ if( clean.parsed_text ){
textParser( clean.parsed_text, vs ); textParser( clean.parsed_text, vs );
@ -120,4 +134,4 @@ function generateQuery( clean ){
}; };
} }
module.exports = generateQuery; module.exports = generateQuery;

71
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
};

20
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.deepEqual(compiled.body, expected, 'autocomplete: valid boundary.country query');
t.end(); 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) { module.exports.all = function (tape, common) {

Loading…
Cancel
Save