Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add boundary.country filter to /v1/autocomplete #634

Merged
merged 1 commit into from
Aug 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions query/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') );
Expand Down Expand Up @@ -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 ) ){
Expand Down
1 change: 1 addition & 0 deletions sanitiser/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
};

Expand Down
68 changes: 68 additions & 0 deletions test/unit/fixture/autocomplete_boundary_country.js
Original file line number Diff line number Diff line change
@@ -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 changes: 16 additions & 0 deletions test/unit/query/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/sanitiser/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down