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

enable autocomplete of country-codes #1616

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
1 change: 0 additions & 1 deletion query/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const toSingleField = require('./view/helper').toSingleField;
// additional views (these may be merged in to pelias/query at a later date)
var views = {
custom_boosts: require('./view/boost_sources_and_layers'),
ngrams_strict: require('./view/ngrams_strict'),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this wasn't used by anything 🤷

ngrams_last_token_only: require('./view/ngrams_last_token_only'),
ngrams_last_token_only_multi: require('./view/ngrams_last_token_only_multi'),
admin_multi_match_first: require('./view/admin_multi_match_first'),
Expand Down
13 changes: 13 additions & 0 deletions query/view/ngrams_strict.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const _ = require('lodash');
const peliasQuery = require('pelias-query');
const toMultiFields = require('./helper').toMultiFields;

Expand All @@ -18,6 +19,18 @@ module.exports = function( vs ){
vs.var('multi_match:ngrams_strict:input', vs.var('input:name').get());
vs.var('multi_match:ngrams_strict:fields', toMultiFields(vs.var('ngram:field').get(), vs.var('lang').get()));

// if the input is a single incomplete token then add
// a field targeting country-code abbreviations.
var incomplete = vs.var('input:name:tokens_incomplete').get();
var complete = vs.var('input:name:tokens_complete').get();
if (_.size(incomplete) === 1 && _.size(complete) === 0) {
vs.var('multi_match:ngrams_strict:fields', vs.var('multi_match:ngrams_strict:fields')
.get().concat([
vs.var('admin:country_a:field').get()
])
);
}

vs.var('multi_match:ngrams_strict:analyzer', vs.var('ngram:analyzer').get());
vs.var('multi_match:ngrams_strict:slop', vs.var('phrase:slop').get());
vs.var('multi_match:ngrams_strict:boost', vs.var('ngram:boost').get());
Expand Down
2 changes: 1 addition & 1 deletion test/unit/fixture/autocomplete_boundary_country.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
'constant_score': {
'filter': {
'multi_match': {
'fields': ['name.default', 'name.en'],
'fields': ['name.default', 'name.en', 'parent.country_a.ngram'],
'analyzer': 'peliasQuery',
'query': 'test',
'boost': 100,
Expand Down
2 changes: 1 addition & 1 deletion test/unit/fixture/autocomplete_boundary_gid.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
'constant_score': {
'filter': {
'multi_match': {
'fields': ['name.default', 'name.en'],
'fields': ['name.default', 'name.en', 'parent.country_a.ngram'],
'analyzer': 'peliasQuery',
'query': 'test',
'boost': 100,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
'constant_score': {
'filter': {
'multi_match': {
'fields': ['name.default', 'name.en'],
'fields': ['name.default', 'name.en', 'parent.country_a.ngram'],
'analyzer': 'peliasQuery',
'query': 'test',
'boost': 100,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
'constant_score': {
'filter': {
'multi_match': {
'fields': ['name.default', 'name.en'],
'fields': ['name.default', 'name.en', 'parent.country_a.ngram'],
'analyzer': 'peliasQuery',
'query': 'test',
'boost': 100,
Expand Down
2 changes: 1 addition & 1 deletion test/unit/fixture/autocomplete_linguistic_focus.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
'constant_score': {
'filter': {
'multi_match': {
'fields': ['name.default', 'name.en'],
'fields': ['name.default', 'name.en', 'parent.country_a.ngram'],
'analyzer': 'peliasQuery',
'query': 'test',
'boost': 100,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
'constant_score': {
'filter': {
'multi_match': {
'fields': ['name.default', 'name.en'],
'fields': ['name.default', 'name.en', 'parent.country_a.ngram'],
'analyzer': 'peliasQuery',
'query': 'test',
'boost': 100,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
'constant_score': {
'filter': {
'multi_match': {
'fields': ['name.default', 'name.en'],
'fields': ['name.default', 'name.en', 'parent.country_a.ngram'],
'analyzer': 'peliasQuery',
'query': 't',
'boost': 100,
Expand Down
2 changes: 1 addition & 1 deletion test/unit/fixture/autocomplete_linguistic_only.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
'constant_score': {
'filter': {
'multi_match': {
'fields': ['name.default', 'name.en'],
'fields': ['name.default', 'name.en', 'parent.country_a.ngram'],
'analyzer': 'peliasQuery',
'query': 'test',
'boost': 100,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
'constant_score': {
'filter': {
'multi_match': {
'fields': ['name.default', 'name.en'],
'fields': ['name.default', 'name.en', 'parent.country_a.ngram'],
'analyzer': 'peliasQuery',
'query': 'tes',
'boost': 100,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
'constant_score': {
'filter': {
'multi_match': {
'fields': ['name.default', 'name.en'],
'fields': ['name.default', 'name.en', 'parent.country_a.ngram'],
'analyzer': 'peliasQuery',
'query': 'te',
'boost': 100,
Expand Down
2 changes: 1 addition & 1 deletion test/unit/fixture/autocomplete_with_category_filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
'constant_score': {
'filter': {
'multi_match': {
'fields': ['name.default', 'name.en'],
'fields': ['name.default', 'name.en', 'parent.country_a.ngram'],
'analyzer': 'peliasQuery',
'query': 'test',
'boost': 100,
Expand Down
2 changes: 1 addition & 1 deletion test/unit/fixture/autocomplete_with_layer_filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
'constant_score': {
'filter': {
'multi_match': {
'fields': ['name.default', 'name.en'],
'fields': ['name.default', 'name.en', 'parent.country_a.ngram'],
'analyzer': 'peliasQuery',
'query': 'test',
'boost': 100,
Expand Down
2 changes: 1 addition & 1 deletion test/unit/fixture/autocomplete_with_source_filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
'constant_score': {
'filter': {
'multi_match': {
'fields': ['name.default', 'name.en'],
'fields': ['name.default', 'name.en', 'parent.country_a.ngram'],
'analyzer': 'peliasQuery',
'query': 'test',
'boost': 100,
Expand Down