diff --git a/query/autocomplete.js b/query/autocomplete.js index f7ec02fdf..4c5806227 100644 --- a/query/autocomplete.js +++ b/query/autocomplete.js @@ -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'), 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'), diff --git a/query/view/ngrams_strict.js b/query/view/ngrams_strict.js index 06400e559..60f571999 100644 --- a/query/view/ngrams_strict.js +++ b/query/view/ngrams_strict.js @@ -18,6 +18,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 (incomplete.length === 1 && complete.length === 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()); diff --git a/test/unit/fixture/autocomplete_boundary_country.js b/test/unit/fixture/autocomplete_boundary_country.js index 64a70552c..6eb7a690b 100644 --- a/test/unit/fixture/autocomplete_boundary_country.js +++ b/test/unit/fixture/autocomplete_boundary_country.js @@ -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, diff --git a/test/unit/fixture/autocomplete_boundary_gid.js b/test/unit/fixture/autocomplete_boundary_gid.js index 5ccb058ca..8443960e0 100644 --- a/test/unit/fixture/autocomplete_boundary_gid.js +++ b/test/unit/fixture/autocomplete_boundary_gid.js @@ -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, diff --git a/test/unit/fixture/autocomplete_linguistic_bbox_san_francisco.js b/test/unit/fixture/autocomplete_linguistic_bbox_san_francisco.js index 787450f4a..c36b46f3f 100644 --- a/test/unit/fixture/autocomplete_linguistic_bbox_san_francisco.js +++ b/test/unit/fixture/autocomplete_linguistic_bbox_san_francisco.js @@ -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, diff --git a/test/unit/fixture/autocomplete_linguistic_circle_san_francisco.js b/test/unit/fixture/autocomplete_linguistic_circle_san_francisco.js index fdeb8757f..35f356a3f 100644 --- a/test/unit/fixture/autocomplete_linguistic_circle_san_francisco.js +++ b/test/unit/fixture/autocomplete_linguistic_circle_san_francisco.js @@ -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, diff --git a/test/unit/fixture/autocomplete_linguistic_focus.js b/test/unit/fixture/autocomplete_linguistic_focus.js index bfde87014..ec2aa6aed 100644 --- a/test/unit/fixture/autocomplete_linguistic_focus.js +++ b/test/unit/fixture/autocomplete_linguistic_focus.js @@ -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, diff --git a/test/unit/fixture/autocomplete_linguistic_focus_null_island.js b/test/unit/fixture/autocomplete_linguistic_focus_null_island.js index 5ceed3548..9bfe2fd38 100644 --- a/test/unit/fixture/autocomplete_linguistic_focus_null_island.js +++ b/test/unit/fixture/autocomplete_linguistic_focus_null_island.js @@ -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, diff --git a/test/unit/fixture/autocomplete_linguistic_one_char_token.js b/test/unit/fixture/autocomplete_linguistic_one_char_token.js index 7a4286910..463fca132 100644 --- a/test/unit/fixture/autocomplete_linguistic_one_char_token.js +++ b/test/unit/fixture/autocomplete_linguistic_one_char_token.js @@ -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, diff --git a/test/unit/fixture/autocomplete_linguistic_only.js b/test/unit/fixture/autocomplete_linguistic_only.js index b8c50a99d..486fe473c 100644 --- a/test/unit/fixture/autocomplete_linguistic_only.js +++ b/test/unit/fixture/autocomplete_linguistic_only.js @@ -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, diff --git a/test/unit/fixture/autocomplete_linguistic_three_char_token.js b/test/unit/fixture/autocomplete_linguistic_three_char_token.js index 79b2dea27..2136231c3 100644 --- a/test/unit/fixture/autocomplete_linguistic_three_char_token.js +++ b/test/unit/fixture/autocomplete_linguistic_three_char_token.js @@ -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, diff --git a/test/unit/fixture/autocomplete_linguistic_two_char_token.js b/test/unit/fixture/autocomplete_linguistic_two_char_token.js index b95dafacd..9670a92d4 100644 --- a/test/unit/fixture/autocomplete_linguistic_two_char_token.js +++ b/test/unit/fixture/autocomplete_linguistic_two_char_token.js @@ -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, diff --git a/test/unit/fixture/autocomplete_with_category_filtering.js b/test/unit/fixture/autocomplete_with_category_filtering.js index 5ee33d85a..afadbad65 100644 --- a/test/unit/fixture/autocomplete_with_category_filtering.js +++ b/test/unit/fixture/autocomplete_with_category_filtering.js @@ -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, diff --git a/test/unit/fixture/autocomplete_with_layer_filtering.js b/test/unit/fixture/autocomplete_with_layer_filtering.js index 916e5925a..0121166a6 100644 --- a/test/unit/fixture/autocomplete_with_layer_filtering.js +++ b/test/unit/fixture/autocomplete_with_layer_filtering.js @@ -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, diff --git a/test/unit/fixture/autocomplete_with_source_filtering.js b/test/unit/fixture/autocomplete_with_source_filtering.js index af3eea8c2..49f88526a 100644 --- a/test/unit/fixture/autocomplete_with_source_filtering.js +++ b/test/unit/fixture/autocomplete_with_source_filtering.js @@ -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,