Browse Source

Merge pull request #640 from pelias/master

Merge master into staging
pull/641/head
Julian Simioni 8 years ago committed by GitHub
parent
commit
43a07edfde
  1. 2
      .travis.yml
  2. 2
      package.json
  3. 8
      query/autocomplete.js
  4. 1
      sanitiser/autocomplete.js
  5. 68
      test/unit/fixture/autocomplete_boundary_country.js
  6. 16
      test/unit/query/autocomplete.js
  7. 31
      test/unit/query/search.js
  8. 2
      test/unit/sanitiser/autocomplete.js

2
.travis.yml

@ -8,12 +8,10 @@ notifications:
node_js:
- 0.12
- 4
- 5
- 6
matrix:
fast_finish: true
allow_failures:
- node_js: 6
env:
global:
- CXX=g++-4.8

2
package.json

@ -54,7 +54,7 @@
"pelias-config": "2.1.0",
"pelias-logger": "0.0.8",
"pelias-model": "4.2.0",
"pelias-query": "8.3.0",
"pelias-query": "8.5.0",
"pelias-text-analyzer": "1.3.0",
"stats-lite": "2.0.3",
"through2": "2.0.1"

8
query/autocomplete.js

@ -22,6 +22,7 @@ var query = new peliasQuery.layout.FilteredBooleanQuery();
// mandatory matches
query.score( views.phrase_first_tokens_only, 'must' );
query.score( views.ngrams_last_token_only, 'must' );
query.score( peliasQuery.view.boundary_country, 'must' );
// address components
query.score( peliasQuery.view.address('housenumber') );
@ -69,6 +70,13 @@ function generateQuery( clean ){
vs.var( 'layers', clean.layers);
}
// boundary country
if( check.string(clean['boundary.country']) ){
vs.set({
'boundary:country': clean['boundary.country']
});
}
// pass the input tokens to the views so they can choose which tokens
// are relevant for their specific function.
if( check.array( clean.tokens ) ){

1
sanitiser/autocomplete.js

@ -12,6 +12,7 @@ var sanitizeAll = require('../sanitiser/sanitizeAll'),
sources_and_layers: require('../sanitiser/_sources_and_layers'),
private: require('../sanitiser/_flag_bool')('private', false),
geo_autocomplete: require('../sanitiser/_geo_autocomplete'),
boundary_country: require('../sanitiser/_boundary_country'),
categories: require('../sanitiser/_categories')
};

68
test/unit/fixture/autocomplete_boundary_country.js

@ -0,0 +1,68 @@
module.exports = {
'query': {
'bool': {
'must': [{
'constant_score': {
'query': {
'match': {
'name.default': {
'analyzer': 'peliasQueryPartialToken',
'boost': 100,
'query': 'test',
'type': 'phrase',
'operator': 'and',
'slop': 3
}
}
}
}
}, {
'match': {
'parent.country_a': {
'analyzer': 'standard',
'query': 'ABC'
}
}
}],
'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
}]
}
}]
}
},
'sort': [ '_score' ],
'size': 20,
'track_scores': true
};

16
test/unit/query/autocomplete.js

@ -164,6 +164,22 @@ module.exports.tests.query = function(test, common) {
t.deepEqual(compiled, expected, 'autocomplete_single_character_street');
t.end();
});
test('valid boundary.country search', function(t) {
var query = generate({
text: 'test',
tokens: ['test'],
tokens_complete: [],
tokens_incomplete: ['test'],
'boundary.country': 'ABC'
});
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/autocomplete_boundary_country');
t.deepEqual(compiled, expected, 'autocomplete: valid boundary.country query');
t.end();
});
};
module.exports.all = function (tape, common) {

31
test/unit/query/search.js

@ -1,5 +1,4 @@
var generate = require('../../../query/search');
var text_analyzer = require('pelias-text-analyzer');
module.exports.tests = {};
@ -88,11 +87,17 @@ module.exports.tests.query = function(test, common) {
});
test('valid query with a full valid address', function(t) {
var address = '123 main st new york ny 10010 US';
var query = generate({ text: address,
var query = generate({ text: '123 main st new york ny 10010 US',
layers: [ 'address', 'venue', 'country', 'region', 'county', 'neighbourhood', 'locality', 'localadmin' ],
querySize: 10,
parsed_text: text_analyzer.parse(address),
parsed_text: {
number: '123',
street: 'main st',
state: 'NY',
country: 'USA',
postalcode: '10010',
regions: [ 'new york' ]
}
});
var compiled = JSON.parse( JSON.stringify( query ) );
@ -103,11 +108,14 @@ module.exports.tests.query = function(test, common) {
});
test('valid query with partial address', function(t) {
var partial_address = 'soho grand, new york';
var query = generate({ text: partial_address,
var query = generate({ text: 'soho grand, new york',
layers: [ 'address', 'venue', 'country', 'region', 'county', 'neighbourhood', 'locality', 'localadmin' ],
querySize: 10,
parsed_text: text_analyzer.parse(partial_address),
parsed_text: { name: 'soho grand',
state: 'NY',
regions: [ 'soho grand' ],
admin_parts: 'new york'
}
});
var compiled = JSON.parse( JSON.stringify( query ) );
@ -118,11 +126,14 @@ module.exports.tests.query = function(test, common) {
});
test('valid query with regions in address', function(t) {
var partial_address = '1 water st manhattan ny';
var query = generate({ text: partial_address,
var query = generate({ text: '1 water st manhattan ny',
layers: [ 'address', 'venue', 'country', 'region', 'county', 'neighbourhood', 'locality', 'localadmin' ],
querySize: 10,
parsed_text: text_analyzer.parse(partial_address),
parsed_text: { number: '1',
street: 'water st',
state: 'NY',
regions: [ 'manhattan' ]
},
});
var compiled = JSON.parse( JSON.stringify( query ) );

2
test/unit/sanitiser/autocomplete.js

@ -6,7 +6,7 @@ module.exports.tests.sanitisers = function(test, common) {
test('check sanitiser list', function (t) {
var expected = [
'singleScalarParameters', 'text', 'tokenizer', 'size', 'layers', 'sources',
'sources_and_layers', 'private', 'geo_autocomplete', 'categories'
'sources_and_layers', 'private', 'geo_autocomplete', 'boundary_country', 'categories'
];
t.deepEqual(Object.keys(autocomplete.sanitiser_list), expected);
t.end();

Loading…
Cancel
Save