Browse Source

Merge pull request #577 from pelias/staging

Merge staging into production
pull/745/head
Julian Simioni 8 years ago committed by GitHub
parent
commit
ff97cc4022
  1. 3
      helper/type_mapping.js
  2. 5
      middleware/dedupe.js
  3. 8
      package.json
  4. 4
      query/autocomplete_defaults.js
  5. 4
      query/reverse_defaults.js
  6. 6
      query/search_defaults.js
  7. 6
      query/view/focus_selected_layers.js
  8. 6
      query/view/ngrams_last_token_only.js
  9. 6
      query/view/ngrams_strict.js
  10. 13
      query/view/pop_subquery.js
  11. 8
      sanitiser/_tokenizer.js
  12. 124
      test/unit/fixture/autocomplete_linguistic_final_token.js
  13. 172
      test/unit/fixture/autocomplete_linguistic_focus.js
  14. 172
      test/unit/fixture/autocomplete_linguistic_focus_null_island.js
  15. 137
      test/unit/fixture/autocomplete_linguistic_multiple_tokens.js
  16. 93
      test/unit/fixture/autocomplete_linguistic_only.js
  17. 276
      test/unit/fixture/autocomplete_linguistic_with_admin.js
  18. 268
      test/unit/fixture/autocomplete_single_character_street.js
  19. 103
      test/unit/fixture/autocomplete_with_source_filtering.js
  20. 28
      test/unit/fixture/dedupe_elasticsearch_results.js
  21. 1
      test/unit/fixture/reverse_boundary_circle.js
  22. 34
      test/unit/fixture/reverse_null_island.js
  23. 34
      test/unit/fixture/reverse_standard.js
  24. 49
      test/unit/fixture/reverse_with_boundary_country.js
  25. 44
      test/unit/fixture/reverse_with_source_filtering.js
  26. 144
      test/unit/fixture/search_boundary_country.js
  27. 224
      test/unit/fixture/search_full_address.js
  28. 145
      test/unit/fixture/search_linguistic_bbox.js
  29. 176
      test/unit/fixture/search_linguistic_focus.js
  30. 199
      test/unit/fixture/search_linguistic_focus_bbox.js
  31. 176
      test/unit/fixture/search_linguistic_focus_null_island.js
  32. 120
      test/unit/fixture/search_linguistic_only.js
  33. 188
      test/unit/fixture/search_linguistic_viewport.js
  34. 4
      test/unit/fixture/search_linguistic_viewport_min_diagonal.js
  35. 160
      test/unit/fixture/search_partial_address.js
  36. 192
      test/unit/fixture/search_regions_address.js
  37. 132
      test/unit/fixture/search_with_source_filtering.js
  38. 10
      test/unit/query/reverse.js
  39. 4
      test/unit/query/search.js
  40. 11
      test/unit/sanitiser/_sources_and_layers.js
  41. 6
      test/unit/sanitiser/_tokenizer.js

3
helper/type_mapping.js

@ -47,7 +47,8 @@ var SOURCE_MAPPING = addStandardTargetsToAliases(SOURCES, SOURCE_ALIASES);
var LAYERS_BY_SOURCE = { var LAYERS_BY_SOURCE = {
openstreetmap: [ 'address', 'venue' ], openstreetmap: [ 'address', 'venue' ],
openaddresses: [ 'address' ], openaddresses: [ 'address' ],
geonames: [ 'country', 'region', 'county', 'locality', 'venue' ], geonames: [ 'country','macroregion', 'region', 'county','localadmin',
'locality', 'neighbourhood', 'venue' ],
whosonfirst: [ 'continent', 'country', 'dependency', 'macroregion', 'region', whosonfirst: [ 'continent', 'country', 'dependency', 'macroregion', 'region',
'locality', 'localadmin', 'macrocounty', 'county', 'macrohood', 'borough', 'locality', 'localadmin', 'macrocounty', 'county', 'macrohood', 'borough',
'neighbourhood', 'microhood', 'disputed'] 'neighbourhood', 'microhood', 'disputed']

5
middleware/dedupe.js

@ -51,7 +51,10 @@ function isDifferent(item1, item2) {
if (item1.hasOwnProperty('name') && item2.hasOwnProperty('name')) { if (item1.hasOwnProperty('name') && item2.hasOwnProperty('name')) {
for (var lang in item1.name) { for (var lang in item1.name) {
propMatch(item1.name, item2.name, lang); if(item2.name[lang] || lang === 'default') {
// do not consider absence of an additional name as a difference
propMatch(item1.name, item2.name, lang);
}
} }
} }
else { else {

8
package.json

@ -49,10 +49,10 @@
"lodash": "^4.5.0", "lodash": "^4.5.0",
"markdown": "0.5.0", "markdown": "0.5.0",
"morgan": "1.7.0", "morgan": "1.7.0",
"pelias-config": "^1.0.1", "pelias-config": "~2.0.0",
"pelias-logger": "^0.0.8", "pelias-logger": "^0.0.8",
"pelias-model": "^4.0.0", "pelias-model": "^4.0.0",
"pelias-query": "7.0.1", "pelias-query": "~8.0.0",
"pelias-suggester-pipeline": "2.0.4", "pelias-suggester-pipeline": "2.0.4",
"pelias-text-analyzer": "^1.0.1", "pelias-text-analyzer": "^1.0.1",
"stats-lite": "1.0.3", "stats-lite": "1.0.3",
@ -66,8 +66,10 @@
"nsp": "^2.2.0", "nsp": "^2.2.0",
"precommit-hook": "^3.0.0", "precommit-hook": "^3.0.0",
"proxyquire": "^1.7.7", "proxyquire": "^1.7.7",
"source-map": "^0.5.6",
"tap-dot": "1.0.5", "tap-dot": "1.0.5",
"tape": "^4.5.1" "tape": "^4.5.1",
"uglify-js": "^2.6.2"
}, },
"pre-commit": [ "pre-commit": [
"lint", "lint",

4
query/autocomplete_defaults.js

@ -15,10 +15,8 @@ module.exports = _.merge({}, peliasQuery.defaults, {
'boundary:circle:radius': '50km', 'boundary:circle:radius': '50km',
'boundary:circle:distance_type': 'plane', 'boundary:circle:distance_type': 'plane',
'boundary:circle:optimize_bbox': 'indexed', 'boundary:circle:optimize_bbox': 'indexed',
'boundary:circle:_cache': true,
'boundary:rect:type': 'indexed', 'boundary:rect:type': 'indexed',
'boundary:rect:_cache': true,
'ngram:analyzer': 'peliasQueryPartialToken', 'ngram:analyzer': 'peliasQueryPartialToken',
'ngram:field': 'name.default', 'ngram:field': 'name.default',
@ -36,7 +34,7 @@ module.exports = _.merge({}, peliasQuery.defaults, {
'focus:weight': 40, 'focus:weight': 40,
'function_score:score_mode': 'avg', 'function_score:score_mode': 'avg',
'function_score:boost_mode': 'multiply', 'function_score:boost_mode': 'replace',
'address:housenumber:analyzer': 'peliasHousenumber', 'address:housenumber:analyzer': 'peliasHousenumber',
'address:housenumber:field': 'address_parts.number', 'address:housenumber:field': 'address_parts.number',

4
query/reverse_defaults.js

@ -16,10 +16,8 @@ module.exports = _.merge({}, peliasQuery.defaults, {
'boundary:circle:radius:coarse': '500km', 'boundary:circle:radius:coarse': '500km',
'boundary:circle:distance_type': 'plane', 'boundary:circle:distance_type': 'plane',
'boundary:circle:optimize_bbox': 'indexed', 'boundary:circle:optimize_bbox': 'indexed',
'boundary:circle:_cache': true,
'boundary:rect:type': 'indexed', 'boundary:rect:type': 'indexed',
'boundary:rect:_cache': true,
'ngram:analyzer': 'peliasQueryPartialToken', 'ngram:analyzer': 'peliasQueryPartialToken',
'ngram:field': 'name.default', 'ngram:field': 'name.default',
@ -31,7 +29,7 @@ module.exports = _.merge({}, peliasQuery.defaults, {
'phrase:slop': 2, 'phrase:slop': 2,
'focus:function': 'linear', 'focus:function': 'linear',
'focus:offset': '1km', 'focus:offset': '0km',
'focus:scale': '50km', 'focus:scale': '50km',
'focus:decay': 0.5, 'focus:decay': 0.5,
'focus:weight': 2, 'focus:weight': 2,

6
query/search_defaults.js

@ -15,12 +15,10 @@ module.exports = _.merge({}, peliasQuery.defaults, {
'boundary:circle:radius': '50km', 'boundary:circle:radius': '50km',
'boundary:circle:distance_type': 'plane', 'boundary:circle:distance_type': 'plane',
'boundary:circle:optimize_bbox': 'indexed', 'boundary:circle:optimize_bbox': 'indexed',
'boundary:circle:_cache': true,
'boundary:rect:type': 'indexed', 'boundary:rect:type': 'indexed',
'boundary:rect:_cache': true,
'ngram:analyzer': 'peliasIndexOneEdgeGram', 'ngram:analyzer': 'peliasQueryFullToken',
'ngram:field': 'name.default', 'ngram:field': 'name.default',
'ngram:boost': 1, 'ngram:boost': 1,
@ -30,7 +28,7 @@ module.exports = _.merge({}, peliasQuery.defaults, {
'phrase:slop': 2, 'phrase:slop': 2,
'focus:function': 'linear', 'focus:function': 'linear',
'focus:offset': '1km', 'focus:offset': '0km',
'focus:scale': '50km', 'focus:scale': '50km',
'focus:decay': 0.5, 'focus:decay': 0.5,
'focus:weight': 2, 'focus:weight': 2,

6
query/view/focus_selected_layers.js

@ -14,6 +14,12 @@ var peliasQuery = require('pelias-query');
module.exports = function( subview ){ module.exports = function( subview ){
return function( vs ){ return function( vs ){
// don't perform this query on single character inputs
// as its too unperformant to sort a large part of the index.
if( vs.var('input:name').get().length < 2 ){
return null;
}
if( !subview ){ return null; } // subview validation failed if( !subview ){ return null; } // subview validation failed
var macroView = peliasQuery.view.focus( subview ); var macroView = peliasQuery.view.focus( subview );
if( !macroView ){ return null; } // macroView validation failed if( !macroView ){ return null; } // macroView validation failed

6
query/view/ngrams_last_token_only.js

@ -28,5 +28,9 @@ module.exports = function( vs ){
vsCopy.var('input:name').set( tokens.join(' ') ); vsCopy.var('input:name').set( tokens.join(' ') );
// return the view rendered using the copy // return the view rendered using the copy
return ngrams_strict( vsCopy ); return {
'constant_score': {
'query': ngrams_strict( vsCopy )
}
};
}; };

6
query/view/ngrams_strict.js

@ -10,10 +10,16 @@ var peliasQuery = require('pelias-query');
module.exports = function( vs ){ module.exports = function( vs ){
// validate required params
if( !vs.isset('phrase:slop') ){
return null;
}
var view = peliasQuery.view.ngrams( vs ); var view = peliasQuery.view.ngrams( vs );
view.match['name.default'].type = 'phrase'; view.match['name.default'].type = 'phrase';
view.match['name.default'].operator = 'and'; view.match['name.default'].operator = 'and';
view.match['name.default'].slop = vs.var('phrase:slop');
return view; return view;
}; };

13
query/view/pop_subquery.js

@ -4,14 +4,13 @@ var peliasQuery = require('pelias-query'),
/** /**
Population / Popularity subquery Population / Popularity subquery
**/
module.exports = function( vs ){
var view = peliasQuery.view.ngrams( vs ); In prior versions we have had restricted the population/popularity boost
to only a section of the query results.
view.match['name.default'].analyzer = vs.var('phrase:analyzer'); Currently it is configured to `match_all`, ie. targets all records.
delete view.match['name.default'].boost; **/
return view; module.exports = function( vs ){
return { 'match_all': {} };
}; };

8
sanitiser/_tokenizer.js

@ -92,13 +92,7 @@ function sanitize( raw, clean ){
// set all but the last token as 'complete' // set all but the last token as 'complete'
clean.tokens_complete = tokensCopy; clean.tokens_complete = tokensCopy;
/** if( lastToken ){
if the last token is a single non-numeric character then we must discard it.
at time of writing, single non-numeric ngrams are not stored in the index,
sending them as part of the query would result in 0 documents being returned.
**/
if( lastToken && ( lastToken.length > 1 || lastToken.match(/[0-9]/) ) ){
clean.tokens_incomplete = [ lastToken ]; clean.tokens_incomplete = [ lastToken ];
} }
} }

124
test/unit/fixture/autocomplete_linguistic_final_token.js

@ -1,77 +1,63 @@
module.exports = { module.exports = {
'query': { 'query': {
'filtered': { 'bool': {
'query': { 'must': [{
'bool': { 'match': {
'must': [{ 'name.default': {
'match': { 'analyzer': 'peliasQueryFullToken',
'name.default': { 'boost': 1,
'analyzer': 'peliasQueryFullToken', 'slop': 3,
'boost': 1, 'query': 'one',
'slop': 3, 'type': 'phrase'
'query': 'one', }
'type': 'phrase' }
} }],
} 'should':[{
}], 'match': {
'should':[{ 'phrase.default': {
'match': { 'analyzer': 'peliasPhrase',
'phrase.default': { 'boost': 1,
'analyzer': 'peliasPhrase', 'slop': 3,
'boost': 1, 'query': 'one',
'slop': 3, 'type': 'phrase'
'query': 'one', }
'type': 'phrase' }
} },{
} 'function_score': {
},{ 'query': {
'function_score': { 'match_all': {}
'query': { },
'match': { 'max_boost': 20,
'name.default': { 'score_mode': 'first',
'analyzer': 'peliasQueryFullToken', 'boost_mode': 'replace',
'query': 'one', 'functions': [{
} 'field_value_factor': {
} 'modifier': 'log1p',
}, 'field': 'popularity',
'max_boost': 20, 'missing': 1
'score_mode': 'first', },
'boost_mode': 'replace', 'weight': 1
'functions': [{ }]
'field_value_factor': { }
'modifier': 'log1p', },{
'field': 'popularity', 'function_score': {
'missing': 1 'query': {
}, 'match_all': {}
'weight': 1 },
}] 'max_boost': 20,
} 'score_mode': 'first',
},{ 'boost_mode': 'replace',
'function_score': { 'functions': [{
'query': { 'field_value_factor': {
'match': { 'modifier': 'log1p',
'name.default': { 'field': 'population',
'analyzer': 'peliasQueryFullToken', 'missing': 1
'query': 'one', },
} 'weight': 3
}
},
'max_boost': 20,
'score_mode': 'first',
'boost_mode': 'replace',
'functions': [{
'field_value_factor': {
'modifier': 'log1p',
'field': 'population',
'missing': 1
},
'weight': 3
}]
}
}] }]
} }
} }]
} }
}, },
'sort': [ '_score' ], 'sort': [ '_score' ],

172
test/unit/fixture/autocomplete_linguistic_focus.js

@ -1,111 +1,103 @@
module.exports = { module.exports = {
'query': { 'query': {
'filtered': { 'bool': {
'query': { 'must': [{
'bool': { 'constant_score': {
'must': [{ 'query': {
'match': { 'match': {
'name.default': { 'name.default': {
'analyzer': 'peliasQueryPartialToken', 'analyzer': 'peliasQueryPartialToken',
'boost': 100, 'boost': 100,
'query': 'test', 'query': 'test',
'type': 'phrase', 'type': 'phrase',
'operator': 'and' 'operator': 'and',
'slop': 3
} }
} }
}], }
'should': [{ }
'function_score': { }],
'query': { 'should': [{
'match': { 'function_score': {
'name.default': { 'query': {
'analyzer': 'peliasQueryPartialToken', 'match': {
'boost': 100, 'name.default': {
'query': 'test', 'analyzer': 'peliasQueryPartialToken',
'type': 'phrase', 'boost': 100,
'operator': 'and' 'query': 'test',
} 'type': 'phrase',
} 'operator': 'and',
}, 'slop': 3
'functions': [{
'linear': {
'center_point': {
'origin': {
'lat': 29.49136,
'lon': -82.50622
},
'offset': '0km',
'scale': '250km',
'decay': 0.5
}
},
'weight': 40
}],
'score_mode': 'avg',
'boost_mode': 'multiply',
'filter': {
'or': [
{
'term': {
'layer': 'venue'
}
},
{
'term': {
'layer': 'address'
}
}
]
} }
} }
},{ },
'function_score': { 'functions': [{
'query': { 'linear': {
'match': { 'center_point': {
'name.default': { 'origin': {
'analyzer': 'peliasQueryFullToken', 'lat': 29.49136,
'query': 'test', 'lon': -82.50622
}
}
},
'max_boost': 20,
'score_mode': 'first',
'boost_mode': 'replace',
'functions': [{
'field_value_factor': {
'modifier': 'log1p',
'field': 'popularity',
'missing': 1
}, },
'weight': 1 'offset': '0km',
}] 'scale': '250km',
} 'decay': 0.5
},{ }
'function_score': { },
'query': { 'weight': 40
'match': { }],
'name.default': { 'score_mode': 'avg',
'analyzer': 'peliasQueryFullToken', 'boost_mode': 'replace',
'query': 'test', 'filter': {
} 'or': [
{
'term': {
'layer': 'venue'
} }
}, },
'max_boost': 20, {
'score_mode': 'first', 'term': {
'boost_mode': 'replace', 'layer': 'address'
'functions': [{ }
'field_value_factor': { }
'modifier': 'log1p', ]
'field': 'population', }
'missing': 1 }
}, },{
'weight': 3 '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' ], 'sort': [ '_score' ],

172
test/unit/fixture/autocomplete_linguistic_focus_null_island.js

@ -1,111 +1,103 @@
module.exports = { module.exports = {
'query': { 'query': {
'filtered': { 'bool': {
'query': { 'must': [{
'bool': { 'constant_score': {
'must': [{ 'query': {
'match': { 'match': {
'name.default': { 'name.default': {
'analyzer': 'peliasQueryPartialToken', 'analyzer': 'peliasQueryPartialToken',
'boost': 100, 'boost': 100,
'query': 'test', 'query': 'test',
'type': 'phrase', 'type': 'phrase',
'operator': 'and' 'operator': 'and',
'slop': 3
} }
} }
}], }
'should': [{ }
'function_score': { }],
'query': { 'should': [{
'match': { 'function_score': {
'name.default': { 'query': {
'analyzer': 'peliasQueryPartialToken', 'match': {
'boost': 100, 'name.default': {
'query': 'test', 'analyzer': 'peliasQueryPartialToken',
'type': 'phrase', 'boost': 100,
'operator': 'and' 'query': 'test',
} 'type': 'phrase',
} 'operator': 'and',
}, 'slop': 3
'functions': [{
'linear': {
'center_point': {
'origin': {
'lat': 0,
'lon': 0
},
'offset': '0km',
'scale': '250km',
'decay': 0.5
}
},
'weight': 40
}],
'score_mode': 'avg',
'boost_mode': 'multiply',
'filter': {
'or': [
{
'term': {
'layer': 'venue'
}
},
{
'term': {
'layer': 'address'
}
}
]
} }
} }
},{ },
'function_score': { 'functions': [{
'query': { 'linear': {
'match': { 'center_point': {
'name.default': { 'origin': {
'analyzer': 'peliasQueryFullToken', 'lat': 0,
'query': 'test', 'lon': 0
}
}
},
'max_boost': 20,
'score_mode': 'first',
'boost_mode': 'replace',
'functions': [{
'field_value_factor': {
'modifier': 'log1p',
'field': 'popularity',
'missing': 1
}, },
'weight': 1 'offset': '0km',
}] 'scale': '250km',
} 'decay': 0.5
},{ }
'function_score': { },
'query': { 'weight': 40
'match': { }],
'name.default': { 'score_mode': 'avg',
'analyzer': 'peliasQueryFullToken', 'boost_mode': 'replace',
'query': 'test', 'filter': {
} 'or': [
{
'term': {
'layer': 'venue'
} }
}, },
'max_boost': 20, {
'score_mode': 'first', 'term': {
'boost_mode': 'replace', 'layer': 'address'
'functions': [{ }
'field_value_factor': { }
'modifier': 'log1p', ]
'field': 'population', }
'missing': 1 }
}, },{
'weight': 3 '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' ], 'sort': [ '_score' ],

137
test/unit/fixture/autocomplete_linguistic_multiple_tokens.js

@ -1,90 +1,81 @@
module.exports = { module.exports = {
'query': { 'query': {
'filtered': { 'bool': {
'query': { 'must': [{
'bool': { 'match': {
'must': [{ 'name.default': {
'match': { 'analyzer': 'peliasQueryFullToken',
'name.default': { 'type': 'phrase',
'analyzer': 'peliasQueryFullToken', 'boost': 1,
'type': 'phrase', 'slop': 3,
'boost': 1, 'query': 'one two'
'slop': 3, }
'query': 'one two' }
} },
} {
}, 'constant_score': {
{ 'query': {
'match': { 'match': {
'name.default': { 'name.default': {
'analyzer': 'peliasQueryPartialToken', 'analyzer': 'peliasQueryPartialToken',
'boost': 100, 'boost': 100,
'query': 'three', 'query': 'three',
'type': 'phrase', 'type': 'phrase',
'operator': 'and' 'operator': 'and',
'slop': 3
} }
} }
}], }
'should':[ }
{ }],
'match': { 'should':[
'phrase.default': { {
'analyzer' : 'peliasPhrase', 'match': {
'type' : 'phrase', 'phrase.default': {
'boost' : 1, 'analyzer' : 'peliasPhrase',
'slop' : 3, 'type' : 'phrase',
'query' : 'one two' 'boost' : 1,
} 'slop' : 3,
} 'query' : 'one two'
},
{
'function_score': {
'query': {
'match': {
'name.default': {
'analyzer': 'peliasQueryFullToken',
'query': 'one two three',
}
}
},
'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': {
'name.default': {
'analyzer': 'peliasQueryFullToken',
'query': 'one two three',
}
}
},
'max_boost': 20,
'score_mode': 'first',
'boost_mode': 'replace',
'functions': [{
'field_value_factor': {
'modifier': 'log1p',
'field': 'population',
'missing': 1
},
'weight': 3
}]
} }
}
},
{
'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' ], 'sort': [ '_score' ],

93
test/unit/fixture/autocomplete_linguistic_only.js

@ -1,67 +1,58 @@
module.exports = { module.exports = {
'query': { 'query': {
'filtered': { 'bool': {
'query': { 'must': [{
'bool': { 'constant_score': {
'must': [{ 'query': {
'match': { 'match': {
'name.default': { 'name.default': {
'analyzer': 'peliasQueryPartialToken', 'analyzer': 'peliasQueryPartialToken',
'boost': 100, 'boost': 100,
'query': 'test', 'query': 'test',
'type': 'phrase', 'type': 'phrase',
'operator': 'and' 'operator': 'and',
'slop': 3
} }
} }
}], }
'should':[{ }
'function_score': { }],
'query': { 'should':[{
'match': { 'function_score': {
'name.default': { 'query': {
'analyzer': 'peliasQueryFullToken', 'match_all': {}
'query': 'test', },
} 'max_boost': 20,
} 'score_mode': 'first',
}, 'boost_mode': 'replace',
'max_boost': 20, 'functions': [{
'score_mode': 'first', 'field_value_factor': {
'boost_mode': 'replace', 'modifier': 'log1p',
'functions': [{ 'field': 'popularity',
'field_value_factor': { 'missing': 1
'modifier': 'log1p', },
'field': 'popularity', 'weight': 1
'missing': 1 }]
}, }
'weight': 1 },{
}] 'function_score': {
} 'query': {
},{ 'match_all': {}
'function_score': { },
'query': { 'max_boost': 20,
'match': { 'score_mode': 'first',
'name.default': { 'boost_mode': 'replace',
'analyzer': 'peliasQueryFullToken', 'functions': [{
'query': 'test', 'field_value_factor': {
} 'modifier': 'log1p',
} 'field': 'population',
}, 'missing': 1
'max_boost': 20, },
'score_mode': 'first', 'weight': 3
'boost_mode': 'replace',
'functions': [{
'field_value_factor': {
'modifier': 'log1p',
'field': 'population',
'missing': 1
},
'weight': 3
}]
}
}] }]
} }
} }]
} }
}, },
'sort': [ '_score' ], 'sort': [ '_score' ],

276
test/unit/fixture/autocomplete_linguistic_with_admin.js

@ -1,159 +1,145 @@
module.exports = { module.exports = {
'query': { 'query': {
'filtered': { 'bool': {
'query': { 'must': [
'bool': { {
'must': [ 'match': {
{ 'name.default': {
'match': { 'analyzer': 'peliasQueryFullToken',
'name.default': { 'type': 'phrase',
'analyzer': 'peliasQueryFullToken', 'boost': 1,
'type': 'phrase', 'slop': 3,
'boost': 1, 'query': 'one two'
'slop': 3,
'query': 'one two'
}
}
} }
], }
'should': [ }
{ ],
'match': { 'should': [
'parent.country': { {
'analyzer': 'peliasAdmin', 'match': {
'boost': 800, 'parent.country': {
'query': 'three' 'analyzer': 'peliasAdmin',
} 'boost': 800,
} 'query': 'three'
}, }
{ }
'match': { },
'parent.region': { {
'analyzer': 'peliasAdmin', 'match': {
'boost': 600, 'parent.region': {
'query': 'three' 'analyzer': 'peliasAdmin',
} 'boost': 600,
} 'query': 'three'
}, }
{ }
'match': { },
'parent.region_a': { {
'analyzer': 'peliasAdmin', 'match': {
'boost': 600, 'parent.region_a': {
'query': 'three' 'analyzer': 'peliasAdmin',
} 'boost': 600,
} 'query': 'three'
}, }
{ }
'match': { },
'parent.county': { {
'analyzer': 'peliasAdmin', 'match': {
'boost': 400, 'parent.county': {
'query': 'three' 'analyzer': 'peliasAdmin',
} 'boost': 400,
} 'query': 'three'
}, }
{ }
'match': { },
'parent.borough': { {
'analyzer': 'peliasAdmin', 'match': {
'boost': 600, 'parent.borough': {
'query': 'three' 'analyzer': 'peliasAdmin',
} 'boost': 600,
} 'query': 'three'
}, }
{ }
'match': { },
'parent.localadmin': { {
'analyzer': 'peliasAdmin', 'match': {
'boost': 200, 'parent.localadmin': {
'query': 'three' 'analyzer': 'peliasAdmin',
} 'boost': 200,
} 'query': 'three'
}, }
{ }
'match': { },
'parent.locality': { {
'analyzer': 'peliasAdmin', 'match': {
'boost': 200, 'parent.locality': {
'query': 'three' 'analyzer': 'peliasAdmin',
} 'boost': 200,
} 'query': 'three'
}, }
{ }
'match': { },
'parent.neighbourhood': { {
'analyzer': 'peliasAdmin', 'match': {
'boost': 200, 'parent.neighbourhood': {
'query': 'three' 'analyzer': 'peliasAdmin',
} 'boost': 200,
} 'query': 'three'
}, }
{ }
'match': { },
'phrase.default': { {
'analyzer' : 'peliasPhrase', 'match': {
'type' : 'phrase', 'phrase.default': {
'boost' : 1, 'analyzer' : 'peliasPhrase',
'slop' : 3, 'type' : 'phrase',
'query' : 'one two' 'boost' : 1,
} 'slop' : 3,
} 'query' : 'one two'
}
}
},
{
'function_score': {
'query': {
'match_all': {}
}, },
{ 'max_boost': 20,
'function_score': { 'functions': [
'query': { {
'match': { 'field_value_factor': {
'name.default': { 'modifier': 'log1p',
'analyzer': 'peliasQueryFullToken', 'field': 'popularity',
'query': 'one two', 'missing': 1
}
}
}, },
'max_boost': 20, 'weight': 1
'functions': [
{
'field_value_factor': {
'modifier': 'log1p',
'field': 'popularity',
'missing': 1
},
'weight': 1
}
],
'score_mode': 'first',
'boost_mode': 'replace'
} }
],
'score_mode': 'first',
'boost_mode': 'replace'
}
},
{
'function_score': {
'query': {
'match_all': {}
}, },
{ 'max_boost': 20,
'function_score': { 'functions': [
'query': { {
'match': { 'field_value_factor': {
'name.default': { 'modifier': 'log1p',
'analyzer': 'peliasQueryFullToken', 'field': 'population',
'query': 'one two', 'missing': 1
}
}
}, },
'max_boost': 20, 'weight': 3
'functions': [
{
'field_value_factor': {
'modifier': 'log1p',
'field': 'population',
'missing': 1
},
'weight': 3
}
],
'score_mode': 'first',
'boost_mode': 'replace'
} }
} ],
] 'score_mode': 'first',
'boost_mode': 'replace'
}
} }
} ]
} }
}, },
'size': 20, 'size': 20,

268
test/unit/fixture/autocomplete_single_character_street.js

@ -1,152 +1,138 @@
module.exports = { module.exports = {
'query': { 'query': {
'filtered': { 'bool': {
'query': { 'must': [{
'bool': { 'match': {
'must': [{ 'name.default': {
'match': { 'analyzer': 'peliasQueryFullToken',
'name.default': { 'type': 'phrase',
'analyzer': 'peliasQueryFullToken', 'boost': 1,
'type': 'phrase', 'slop': 3,
'boost': 1, 'query': 'k road'
'slop': 3, }
'query': 'k road' }
} }],
'should':[
{
'match': {
'address_parts.street': {
'query': 'k road',
'boost': 5,
'analyzer': 'peliasStreet'
} }
}], }
'should':[ }, {
{ 'match': {
'match': { 'parent.country': {
'address_parts.street': { 'query': 'laird',
'query': 'k road', 'boost': 800,
'boost': 5, 'analyzer': 'peliasAdmin'
'analyzer': 'peliasStreet' }
} }
} }, {
}, { 'match': {
'match': { 'parent.region': {
'parent.country': { 'query': 'laird',
'query': 'laird', 'boost': 600,
'boost': 800, 'analyzer': 'peliasAdmin'
'analyzer': 'peliasAdmin' }
} }
} }, {
}, { 'match': {
'match': { 'parent.region_a': {
'parent.region': { 'query': 'laird',
'query': 'laird', 'boost': 600,
'boost': 600, 'analyzer': 'peliasAdmin'
'analyzer': 'peliasAdmin' }
} }
} }, {
}, { 'match': {
'match': { 'parent.county': {
'parent.region_a': { 'query': 'laird',
'query': 'laird', 'boost': 400,
'boost': 600, 'analyzer': 'peliasAdmin'
'analyzer': 'peliasAdmin' }
} }
} }, {
}, { 'match': {
'match': { 'parent.borough': {
'parent.county': { 'analyzer': 'peliasAdmin',
'query': 'laird', 'boost': 600,
'boost': 400, 'query': 'laird'
'analyzer': 'peliasAdmin'
}
}
}, {
'match': {
'parent.borough': {
'analyzer': 'peliasAdmin',
'boost': 600,
'query': 'laird'
}
}
}, {
'match': {
'parent.localadmin': {
'query': 'laird',
'boost': 200,
'analyzer': 'peliasAdmin'
}
}
}, {
'match': {
'parent.locality': {
'query': 'laird',
'boost': 200,
'analyzer': 'peliasAdmin'
}
}
}, {
'match': {
'parent.neighbourhood': {
'query': 'laird',
'boost': 200,
'analyzer': 'peliasAdmin'
}
}
},
{
'match': {
'phrase.default': {
'analyzer' : 'peliasPhrase',
'type' : 'phrase',
'boost' : 1,
'slop' : 3,
'query' : 'k road'
}
}
},
{
'function_score': {
'query': {
'match': {
'name.default': {
'analyzer': 'peliasQueryFullToken',
'query': 'k road',
}
}
},
'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': {
'match': { 'parent.localadmin': {
'name.default': { 'query': 'laird',
'analyzer': 'peliasQueryFullToken', 'boost': 200,
'query': 'k road', 'analyzer': 'peliasAdmin'
}
}
},
'max_boost': 20,
'score_mode': 'first',
'boost_mode': 'replace',
'functions': [{
'field_value_factor': {
'modifier': 'log1p',
'field': 'population',
'missing': 1
},
'weight': 3
}]
} }
}
}, {
'match': {
'parent.locality': {
'query': 'laird',
'boost': 200,
'analyzer': 'peliasAdmin'
}
}
}, {
'match': {
'parent.neighbourhood': {
'query': 'laird',
'boost': 200,
'analyzer': 'peliasAdmin'
}
}
},
{
'match': {
'phrase.default': {
'analyzer' : 'peliasPhrase',
'type' : 'phrase',
'boost' : 1,
'slop' : 3,
'query' : 'k road'
}
}
},
{
'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' ], 'sort': [ '_score' ],

103
test/unit/fixture/autocomplete_with_source_filtering.js

@ -1,76 +1,63 @@
module.exports = { module.exports = {
'query': { 'query': {
'filtered': { 'bool': {
'query': { 'must': [{
'bool': { 'constant_score': {
'must': [{ 'query': {
'match': { 'match': {
'name.default': { 'name.default': {
'analyzer': 'peliasQueryPartialToken', 'analyzer': 'peliasQueryPartialToken',
'boost': 100, 'boost': 100,
'query': 'test', 'query': 'test',
'type': 'phrase', 'type': 'phrase',
'operator': 'and' 'operator': 'and',
'slop': 3
} }
} }
}], }
'should':[{ }
'function_score': { }],
'query': { 'should':[{
'match': { 'function_score': {
'name.default': { 'query': {
'analyzer': 'peliasQueryFullToken', 'match_all': {}
'query': 'test', },
} 'max_boost': 20,
} 'score_mode': 'first',
}, 'boost_mode': 'replace',
'max_boost': 20, 'functions': [{
'score_mode': 'first', 'field_value_factor': {
'boost_mode': 'replace', 'modifier': 'log1p',
'functions': [{ 'field': 'popularity',
'field_value_factor': { 'missing': 1
'modifier': 'log1p', },
'field': 'popularity', 'weight': 1
'missing': 1
},
'weight': 1
}]
}
},{
'function_score': {
'query': {
'match': {
'name.default': {
'analyzer': 'peliasQueryFullToken',
'query': 'test',
}
}
},
'max_boost': 20,
'score_mode': 'first',
'boost_mode': 'replace',
'functions': [{
'field_value_factor': {
'modifier': 'log1p',
'field': 'population',
'missing': 1
},
'weight': 3
}]
}
}] }]
} }
}, },{
'filter': { 'function_score': {
'bool': { 'query': {
'must': [{ 'match_all': {}
'terms': { },
'source': ['test_source'] 'max_boost': 20,
} 'score_mode': 'first',
'boost_mode': 'replace',
'functions': [{
'field_value_factor': {
'modifier': 'log1p',
'field': 'population',
'missing': 1
},
'weight': 3
}] }]
} }
} }],
'filter': [{
'terms': {
'source': ['test_source']
}
}]
} }
}, },
'sort': [ '_score' ], 'sort': [ '_score' ],

28
test/unit/fixture/dedupe_elasticsearch_results.js

@ -80,6 +80,34 @@ module.exports = [
'_score': 1.2367082, '_score': 1.2367082,
'confidence': 0.879 'confidence': 0.879
}, },
{ // same as #1, but with an additional name
'center_point': {
'lon': -76.207456,
'lat': 40.039265
},
'address_parts': {},
'parent': {
'localadmin': ['East Lampeter'],
'region_a': ['PA'],
'region': ['Pennsylvania'],
'locality': ['Smoketown'],
'country_a': ['USA'],
'county': ['Lancaster County'],
'country': ['United States'],
'neighbourhood': ['Greenland']
},
'name': {
'default': 'East Lampeter High School',
'alt': 'High School of East Lampeter',
},
'category': [
'education'
],
'_id': '357321757',
'_type': 'venue',
'_score': 1.2367082,
'confidence': 0.879
},
{ {
'center_point': { 'center_point': {
'lon': -76.207456, 'lon': -76.207456,

1
test/unit/fixture/reverse_boundary_circle.js

@ -14,7 +14,6 @@ module.exports = {
'distance': vs.distance, 'distance': vs.distance,
'distance_type': 'plane', 'distance_type': 'plane',
'optimize_bbox': 'indexed', 'optimize_bbox': 'indexed',
'_cache': true,
'center_point': { 'center_point': {
'lat': 29.49136, 'lat': 29.49136,
'lon': -82.50622 'lon': -82.50622

34
test/unit/fixture/reverse_null_island.js

@ -2,30 +2,18 @@ var vs = require('../../../query/reverse_defaults');
module.exports = { module.exports = {
'query': { 'query': {
'filtered': { 'bool': {
'query': { 'filter': [{
'bool': { 'geo_distance': {
'must': [] 'distance': '500km',
'distance_type': 'plane',
'optimize_bbox': 'indexed',
'center_point': {
'lat': 0,
'lon': 0
}
} }
}, }]
'filter': {
'bool': {
'must': [
{
'geo_distance': {
'distance': '500km',
'distance_type': 'plane',
'optimize_bbox': 'indexed',
'_cache': true,
'center_point': {
'lat': 0,
'lon': 0
}
}
}
]
}
}
} }
}, },
'sort': [ 'sort': [

34
test/unit/fixture/reverse_standard.js

@ -2,30 +2,18 @@ var vs = require('../../../query/reverse_defaults');
module.exports = { module.exports = {
'query': { 'query': {
'filtered': { 'bool': {
'query': { 'filter': [{
'bool': { 'geo_distance': {
'must': [] 'distance': '500km',
'distance_type': 'plane',
'optimize_bbox': 'indexed',
'center_point': {
'lat': 29.49136,
'lon': -82.50622
}
} }
}, }]
'filter': {
'bool': {
'must': [
{
'geo_distance': {
'distance': '500km',
'distance_type': 'plane',
'optimize_bbox': 'indexed',
'_cache': true,
'center_point': {
'lat': 29.49136,
'lon': -82.50622
}
}
}
]
}
}
} }
}, },
'sort': [ 'sort': [

49
test/unit/fixture/reverse_with_boundary_country.js

@ -2,39 +2,28 @@ var vs = require('../../../query/reverse_defaults');
module.exports = { module.exports = {
'query': { 'query': {
'filtered': { 'bool': {
'query': { 'must': [
'bool': { {
'must': [ 'match': {
{ 'parent.country_a': {
'match': { 'analyzer': 'standard',
'parent.country_a': { 'query': 'ABC'
'analyzer': 'standard',
'query': 'ABC'
}
}
} }
] }
} }
}, ],
'filter': { 'filter': [{
'bool': { 'geo_distance': {
'must': [ 'distance': '500km',
{ 'distance_type': 'plane',
'geo_distance': { 'optimize_bbox': 'indexed',
'distance': '500km', 'center_point': {
'distance_type': 'plane', 'lat': 29.49136,
'optimize_bbox': 'indexed', 'lon': -82.50622
'_cache': true, }
'center_point': {
'lat': 29.49136,
'lon': -82.50622
}
}
}
]
} }
} }]
} }
}, },
'sort': [ 'sort': [

44
test/unit/fixture/reverse_with_source_filtering.js

@ -2,35 +2,25 @@ var vs = require('../../../query/reverse_defaults');
module.exports = { module.exports = {
'query': { 'query': {
'filtered': { 'bool': {
'query': { 'filter': [
'bool': { {
'must': [] 'geo_distance': {
} 'distance': '500km',
}, 'distance_type': 'plane',
'filter': { 'optimize_bbox': 'indexed',
'bool': { 'center_point': {
'must': [ 'lat': 29.49136,
{ 'lon': -82.50622
'geo_distance': {
'distance': '500km',
'distance_type': 'plane',
'optimize_bbox': 'indexed',
'_cache': true,
'center_point': {
'lat': 29.49136,
'lon': -82.50622
}
}
},
{
'terms': {
'source': ['test']
}
} }
] }
},
{
'terms': {
'source': ['test']
}
} }
} ]
} }
}, },
'sort': [ 'sort': [

144
test/unit/fixture/search_boundary_country.js

@ -1,91 +1,87 @@
module.exports = { module.exports = {
'query': { 'query': {
'filtered': { 'bool': {
'query': { 'must': [
'bool': { {
'must': [ 'match': {
{ 'parent.country_a': {
'match': { 'analyzer': 'standard',
'parent.country_a': { 'query': 'ABC'
'analyzer': 'standard',
'query': 'ABC'
}
}
},
{
'match': {
'name.default': {
'query': 'test',
'boost': 1,
'analyzer': 'peliasIndexOneEdgeGram'
}
}
} }
], }
'should': [{ },
{
'match': {
'name.default': {
'query': 'test',
'boost': 1,
'analyzer': 'peliasQueryFullToken'
}
}
}
],
'should': [{
'match': {
'phrase.default': {
'query': 'test',
'analyzer': 'peliasPhrase',
'type': 'phrase',
'boost': 1,
'slop': 2
}
}
},{
'function_score': {
'query': {
'match': { 'match': {
'phrase.default': { 'phrase.default': {
'query': 'test', 'query': 'test',
'analyzer': 'peliasPhrase', 'analyzer': 'peliasPhrase',
'type': 'phrase', 'type': 'phrase',
'boost': 1, 'slop': 2,
'slop': 2 'boost': 1
} }
} }
},{ },
'function_score': { 'max_boost': 20,
'query': { 'score_mode': 'first',
'match': { 'boost_mode': 'replace',
'phrase.default': { 'functions': [{
'query': 'test', 'field_value_factor': {
'analyzer': 'peliasPhrase', 'modifier': 'log1p',
'type': 'phrase', 'field': 'popularity',
'slop': 2, 'missing': 1
'boost': 1 },
} 'weight': 1
} }]
}, }
'max_boost': 20, },{
'score_mode': 'first', 'function_score': {
'boost_mode': 'replace', 'query': {
'functions': [{ 'match': {
'field_value_factor': { 'phrase.default': {
'modifier': 'log1p', 'query': 'test',
'field': 'popularity', 'analyzer': 'peliasPhrase',
'missing': 1 'type': 'phrase',
}, 'slop': 2,
'weight': 1 'boost': 1
}] }
}
},{
'function_score': {
'query': {
'match': {
'phrase.default': {
'query': 'test',
'analyzer': 'peliasPhrase',
'type': 'phrase',
'slop': 2,
'boost': 1
}
}
},
'max_boost': 20,
'score_mode': 'first',
'boost_mode': 'replace',
'functions': [{
'field_value_factor': {
'modifier': 'log1p',
'field': 'population',
'missing': 1
},
'weight': 2
}]
} }
},
'max_boost': 20,
'score_mode': 'first',
'boost_mode': 'replace',
'functions': [{
'field_value_factor': {
'modifier': 'log1p',
'field': 'population',
'missing': 1
},
'weight': 2
}] }]
} }
} }]
} }
}, },
'sort': [ '_score' ], 'sort': [ '_score' ],

224
test/unit/fixture/search_full_address.js

@ -2,19 +2,55 @@ var vs = require('../../../query/search_defaults');
module.exports = { module.exports = {
'query': { 'query': {
'filtered': { 'bool': {
'query': { 'must': [{
'bool': { 'match': {
'must': [{ 'name.default': {
'query': '123 main st',
'analyzer': 'peliasQueryFullToken',
'boost': 1
}
}
}],
'should': [{
'match': {
'phrase.default': {
'query': '123 main st',
'analyzer': 'peliasPhrase',
'type': 'phrase',
'slop': 2,
'boost': 1
}
}
},
{
'function_score': {
'query': {
'match': { 'match': {
'name.default': { 'phrase.default': {
'query': '123 main st', 'query': '123 main st',
'analyzer': 'peliasIndexOneEdgeGram', 'analyzer': 'peliasPhrase',
'type': 'phrase',
'slop': 2,
'boost': 1 'boost': 1
} }
} }
}], },
'should': [{ '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': { 'match': {
'phrase.default': { 'phrase.default': {
'query': '123 main st', 'query': '123 main st',
@ -25,114 +61,74 @@ module.exports = {
} }
} }
}, },
{ 'max_boost': 20,
'function_score': { 'score_mode': 'first',
'query': { 'boost_mode': 'replace',
'match': { 'functions': [{
'phrase.default': { 'field_value_factor': {
'query': '123 main st', 'modifier': 'log1p',
'analyzer': 'peliasPhrase', 'field': 'population',
'type': 'phrase', 'missing': 1
'slop': 2, },
'boost': 1 'weight': 2
}
}
},
'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': {
'phrase.default': {
'query': '123 main st',
'analyzer': 'peliasPhrase',
'type': 'phrase',
'slop': 2,
'boost': 1
}
}
},
'max_boost': 20,
'score_mode': 'first',
'boost_mode': 'replace',
'functions': [{
'field_value_factor': {
'modifier': 'log1p',
'field': 'population',
'missing': 1
},
'weight': 2
}]
}
},{
'match': {
'address_parts.number': {
'query': '123',
'boost': vs['address:housenumber:boost'],
'analyzer': vs['address:housenumber:analyzer']
}
}
}, {
'match': {
'address_parts.street': {
'query': 'main st',
'boost': vs['address:street:boost'],
'analyzer': vs['address:street:analyzer']
}
}
}, {
'match': {
'address_parts.zip': {
'query': '10010',
'boost': vs['address:postcode:boost'],
'analyzer': vs['address:postcode:analyzer']
}
}
}, {
'match': {
'parent.country_a': {
'query': 'USA',
'boost': vs['admin:country_a:boost'],
'analyzer': vs['admin:country_a:analyzer']
}
}
}, {
'match': {
'parent.region_a': {
'query': 'NY',
'boost': vs['admin:region_a:boost'],
'analyzer': vs['admin:region_a:analyzer']
}
}
}, {
'multi_match': {
'fields': [
'parent.country^1',
'parent.region^1',
'parent.county^1',
'parent.localadmin^1',
'parent.locality^1',
'parent.borough^1',
'parent.neighbourhood^1',
'parent.region_a^1'
],
'query': 'new york',
'analyzer': 'peliasAdmin'
}
}] }]
} }
} },{
'match': {
'address_parts.number': {
'query': '123',
'boost': vs['address:housenumber:boost'],
'analyzer': vs['address:housenumber:analyzer']
}
}
}, {
'match': {
'address_parts.street': {
'query': 'main st',
'boost': vs['address:street:boost'],
'analyzer': vs['address:street:analyzer']
}
}
}, {
'match': {
'address_parts.zip': {
'query': '10010',
'boost': vs['address:postcode:boost'],
'analyzer': vs['address:postcode:analyzer']
}
}
}, {
'match': {
'parent.country_a': {
'query': 'USA',
'boost': vs['admin:country_a:boost'],
'analyzer': vs['admin:country_a:analyzer']
}
}
}, {
'match': {
'parent.region_a': {
'query': 'NY',
'boost': vs['admin:region_a:boost'],
'analyzer': vs['admin:region_a:analyzer']
}
}
}, {
'multi_match': {
'fields': [
'parent.country^1',
'parent.region^1',
'parent.county^1',
'parent.localadmin^1',
'parent.locality^1',
'parent.borough^1',
'parent.neighbourhood^1',
'parent.region_a^1'
],
'query': 'new york',
'analyzer': 'peliasAdmin'
}
}]
} }
}, },
'size': 10, 'size': 10,

145
test/unit/fixture/search_linguistic_bbox.js

@ -1,97 +1,88 @@
module.exports = { module.exports = {
'query': { 'query': {
'filtered': { 'bool': {
'query': { 'must': [{
'bool': { 'match': {
'must': [{ 'name.default': {
'query': 'test',
'boost': 1,
'analyzer': 'peliasQueryFullToken'
}
}
}],
'should': [{
'match': {
'phrase.default': {
'query': 'test',
'analyzer': 'peliasPhrase',
'type': 'phrase',
'boost': 1,
'slop': 2
}
}
},{
'function_score': {
'query': {
'match': { 'match': {
'name.default': { 'phrase.default': {
'query': 'test', 'query': 'test',
'boost': 1, 'analyzer': 'peliasPhrase',
'analyzer': 'peliasIndexOneEdgeGram' 'type': 'phrase',
'slop': 2,
'boost': 1
} }
} }
}], },
'should': [{ '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': { 'match': {
'phrase.default': { 'phrase.default': {
'query': 'test', 'query': 'test',
'analyzer': 'peliasPhrase', 'analyzer': 'peliasPhrase',
'type': 'phrase', 'type': 'phrase',
'boost': 1, 'slop': 2,
'slop': 2 'boost': 1
} }
} }
},{ },
'function_score': { 'max_boost': 20,
'query': { 'score_mode': 'first',
'match': { 'boost_mode': 'replace',
'phrase.default': { 'functions': [{
'query': 'test', 'field_value_factor': {
'analyzer': 'peliasPhrase', 'modifier': 'log1p',
'type': 'phrase', 'field': 'population',
'slop': 2, 'missing': 1
'boost': 1 },
} 'weight': 2
}
},
'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': {
'phrase.default': {
'query': 'test',
'analyzer': 'peliasPhrase',
'type': 'phrase',
'slop': 2,
'boost': 1
}
}
},
'max_boost': 20,
'score_mode': 'first',
'boost_mode': 'replace',
'functions': [{
'field_value_factor': {
'modifier': 'log1p',
'field': 'population',
'missing': 1
},
'weight': 2
}]
}
}] }]
} }
}, }],
'filter': { 'filter': [{
'bool': { 'geo_bounding_box': {
'must': [{ 'center_point': {
'geo_bounding_box': { 'top': 11.51,
'center_point': { 'right': -61.84,
'top': 11.51, 'bottom': 47.47,
'right': -61.84, 'left': -103.16
'bottom': 47.47, },
'left': -103.16 'type': 'indexed'
},
'_cache': true,
'type': 'indexed'
}
}]
} }
} }]
} }
}, },
'sort': [ '_score' ], 'sort': [ '_score' ],

176
test/unit/fixture/search_linguistic_focus.js

@ -1,111 +1,107 @@
module.exports = { module.exports = {
'query': { 'query': {
'filtered': { 'bool': {
'query': { 'must': [{
'bool': { 'match': {
'must': [{ 'name.default': {
'query': 'test',
'boost': 1,
'analyzer': 'peliasQueryFullToken'
}
}
}],
'should': [{
'match': {
'phrase.default': {
'query': 'test',
'analyzer': 'peliasPhrase',
'type': 'phrase',
'boost': 1,
'slop': 2
}
}
}, {
'function_score': {
'query': {
'match': { 'match': {
'name.default': { 'phrase.default': {
'query': 'test', 'analyzer': 'peliasPhrase',
'type': 'phrase',
'boost': 1, 'boost': 1,
'analyzer': 'peliasIndexOneEdgeGram' 'slop': 2,
'query': 'test'
} }
} }
},
'functions': [{
'linear': {
'center_point': {
'origin': {
'lat': 29.49136,
'lon': -82.50622
},
'offset': '0km',
'scale': '50km',
'decay': 0.5
}
},
'weight': 2
}], }],
'should': [{ 'score_mode': 'avg',
'boost_mode': 'replace'
}
},{
'function_score': {
'query': {
'match': { 'match': {
'phrase.default': { 'phrase.default': {
'query': 'test', 'query': 'test',
'analyzer': 'peliasPhrase', 'analyzer': 'peliasPhrase',
'type': 'phrase', 'type': 'phrase',
'boost': 1, 'slop': 2,
'slop': 2 'boost': 1
} }
} }
}, { },
'function_score': { 'max_boost': 20,
'query': { 'score_mode': 'first',
'match': { 'boost_mode': 'replace',
'phrase.default': { 'functions': [{
'analyzer': 'peliasPhrase', 'field_value_factor': {
'type': 'phrase', 'modifier': 'log1p',
'boost': 1, 'field': 'popularity',
'slop': 2, 'missing': 1
'query': 'test' },
} 'weight': 1
} }]
}, }
'functions': [{ },{
'linear': { 'function_score': {
'center_point': { 'query': {
'origin': { 'match': {
'lat': 29.49136, 'phrase.default': {
'lon': -82.50622 'query': 'test',
}, 'analyzer': 'peliasPhrase',
'offset': '1km', 'type': 'phrase',
'scale': '50km', 'slop': 2,
'decay': 0.5 'boost': 1
} }
},
'weight': 2
}],
'score_mode': 'avg',
'boost_mode': 'replace'
}
},{
'function_score': {
'query': {
'match': {
'phrase.default': {
'query': 'test',
'analyzer': 'peliasPhrase',
'type': 'phrase',
'slop': 2,
'boost': 1
}
}
},
'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': {
'phrase.default': {
'query': 'test',
'analyzer': 'peliasPhrase',
'type': 'phrase',
'slop': 2,
'boost': 1
}
}
},
'max_boost': 20,
'score_mode': 'first',
'boost_mode': 'replace',
'functions': [{
'field_value_factor': {
'modifier': 'log1p',
'field': 'population',
'missing': 1
},
'weight': 2
}]
} }
},
'max_boost': 20,
'score_mode': 'first',
'boost_mode': 'replace',
'functions': [{
'field_value_factor': {
'modifier': 'log1p',
'field': 'population',
'missing': 1
},
'weight': 2
}] }]
} }
} }]
} }
}, },
'sort': [ '_score' ], 'sort': [ '_score' ],

199
test/unit/fixture/search_linguistic_focus_bbox.js

@ -1,127 +1,118 @@
module.exports = { module.exports = {
'query': { 'query': {
'filtered': { 'bool': {
'query': { 'must': [{
'bool': { 'match': {
'must': [{ 'name.default': {
'query': 'test',
'boost': 1,
'analyzer': 'peliasQueryFullToken'
}
}
}],
'should': [{
'match': {
'phrase.default': {
'query': 'test',
'analyzer': 'peliasPhrase',
'type': 'phrase',
'boost': 1,
'slop': 2
}
}
}, {
'function_score': {
'query': {
'match': { 'match': {
'name.default': { 'phrase.default': {
'query': 'test', 'analyzer': 'peliasPhrase',
'type': 'phrase',
'boost': 1, 'boost': 1,
'analyzer': 'peliasIndexOneEdgeGram' 'slop': 2,
'query': 'test'
} }
} }
},
'functions': [{
'linear': {
'center_point': {
'origin': {
'lat': 29.49136,
'lon': -82.50622
},
'offset': '0km',
'scale': '50km',
'decay': 0.5
}
},
'weight': 2
}], }],
'should': [{ 'score_mode': 'avg',
'boost_mode': 'replace'
}
},{
'function_score': {
'query': {
'match': { 'match': {
'phrase.default': { 'phrase.default': {
'query': 'test', 'query': 'test',
'analyzer': 'peliasPhrase', 'analyzer': 'peliasPhrase',
'type': 'phrase', 'type': 'phrase',
'boost': 1, 'slop': 2,
'slop': 2 'boost': 1
} }
} }
}, { },
'function_score': { 'max_boost': 20,
'query': { 'score_mode': 'first',
'match': { 'boost_mode': 'replace',
'phrase.default': { 'functions': [{
'analyzer': 'peliasPhrase', 'field_value_factor': {
'type': 'phrase', 'modifier': 'log1p',
'boost': 1, 'field': 'popularity',
'slop': 2, 'missing': 1
'query': 'test' },
} 'weight': 1
}
},
'functions': [{
'linear': {
'center_point': {
'origin': {
'lat': 29.49136,
'lon': -82.50622
},
'offset': '1km',
'scale': '50km',
'decay': 0.5
}
},
'weight': 2
}],
'score_mode': 'avg',
'boost_mode': 'replace'
}
},{
'function_score': {
'query': {
'match': {
'phrase.default': {
'query': 'test',
'analyzer': 'peliasPhrase',
'type': 'phrase',
'slop': 2,
'boost': 1
}
}
},
'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': {
'phrase.default': {
'query': 'test',
'analyzer': 'peliasPhrase',
'type': 'phrase',
'slop': 2,
'boost': 1
}
}
},
'max_boost': 20,
'score_mode': 'first',
'boost_mode': 'replace',
'functions': [{
'field_value_factor': {
'modifier': 'log1p',
'field': 'population',
'missing': 1
},
'weight': 2
}]
}
}] }]
} }
}, },{
'filter': { 'function_score': {
'bool': { 'query': {
'must': [{ 'match': {
'geo_bounding_box': { 'phrase.default': {
'center_point': { 'query': 'test',
'top': 11.51, 'analyzer': 'peliasPhrase',
'right': -61.84, 'type': 'phrase',
'bottom': 47.47, 'slop': 2,
'left': -103.16 'boost': 1
}, }
'_cache': true,
'type': 'indexed'
} }
},
'max_boost': 20,
'score_mode': 'first',
'boost_mode': 'replace',
'functions': [{
'field_value_factor': {
'modifier': 'log1p',
'field': 'population',
'missing': 1
},
'weight': 2
}] }]
} }
} }],
'filter': [{
'geo_bounding_box': {
'center_point': {
'top': 11.51,
'right': -61.84,
'bottom': 47.47,
'left': -103.16
},
'type': 'indexed'
}
}]
} }
}, },
'sort': [ '_score' ], 'sort': [ '_score' ],

176
test/unit/fixture/search_linguistic_focus_null_island.js

@ -1,111 +1,107 @@
module.exports = { module.exports = {
'query': { 'query': {
'filtered': { 'bool': {
'query': { 'must': [{
'bool': { 'match': {
'must': [{ 'name.default': {
'query': 'test',
'boost': 1,
'analyzer': 'peliasQueryFullToken'
}
}
}],
'should': [{
'match': {
'phrase.default': {
'query': 'test',
'analyzer': 'peliasPhrase',
'type': 'phrase',
'boost': 1,
'slop': 2
}
}
}, {
'function_score': {
'query': {
'match': { 'match': {
'name.default': { 'phrase.default': {
'query': 'test', 'analyzer': 'peliasPhrase',
'type': 'phrase',
'boost': 1, 'boost': 1,
'analyzer': 'peliasIndexOneEdgeGram' 'slop': 2,
'query': 'test'
} }
} }
},
'functions': [{
'linear': {
'center_point': {
'origin': {
'lat': 0,
'lon': 0
},
'offset': '0km',
'scale': '50km',
'decay': 0.5
}
},
'weight': 2
}], }],
'should': [{ 'score_mode': 'avg',
'boost_mode': 'replace'
}
},{
'function_score': {
'query': {
'match': { 'match': {
'phrase.default': { 'phrase.default': {
'query': 'test', 'query': 'test',
'analyzer': 'peliasPhrase', 'analyzer': 'peliasPhrase',
'type': 'phrase', 'type': 'phrase',
'boost': 1, 'slop': 2,
'slop': 2 'boost': 1
} }
} }
}, { },
'function_score': { 'max_boost': 20,
'query': { 'score_mode': 'first',
'match': { 'boost_mode': 'replace',
'phrase.default': { 'functions': [{
'analyzer': 'peliasPhrase', 'field_value_factor': {
'type': 'phrase', 'modifier': 'log1p',
'boost': 1, 'field': 'popularity',
'slop': 2, 'missing': 1
'query': 'test' },
} 'weight': 1
} }]
}, }
'functions': [{ },{
'linear': { 'function_score': {
'center_point': { 'query': {
'origin': { 'match': {
'lat': 0, 'phrase.default': {
'lon': 0 'query': 'test',
}, 'analyzer': 'peliasPhrase',
'offset': '1km', 'type': 'phrase',
'scale': '50km', 'slop': 2,
'decay': 0.5 'boost': 1
} }
},
'weight': 2
}],
'score_mode': 'avg',
'boost_mode': 'replace'
}
},{
'function_score': {
'query': {
'match': {
'phrase.default': {
'query': 'test',
'analyzer': 'peliasPhrase',
'type': 'phrase',
'slop': 2,
'boost': 1
}
}
},
'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': {
'phrase.default': {
'query': 'test',
'analyzer': 'peliasPhrase',
'type': 'phrase',
'slop': 2,
'boost': 1
}
}
},
'max_boost': 20,
'score_mode': 'first',
'boost_mode': 'replace',
'functions': [{
'field_value_factor': {
'modifier': 'log1p',
'field': 'population',
'missing': 1
},
'weight': 2
}]
} }
},
'max_boost': 20,
'score_mode': 'first',
'boost_mode': 'replace',
'functions': [{
'field_value_factor': {
'modifier': 'log1p',
'field': 'population',
'missing': 1
},
'weight': 2
}] }]
} }
} }]
} }
}, },
'sort': [ '_score' ], 'sort': [ '_score' ],

120
test/unit/fixture/search_linguistic_only.js

@ -1,81 +1,77 @@
module.exports = { module.exports = {
'query': { 'query': {
'filtered': { 'bool': {
'query': { 'must': [{
'bool': { 'match': {
'must': [{ 'name.default': {
'query': 'test',
'boost': 1,
'analyzer': 'peliasQueryFullToken'
}
}
}],
'should': [{
'match': {
'phrase.default': {
'query': 'test',
'analyzer': 'peliasPhrase',
'type': 'phrase',
'boost': 1,
'slop': 2
}
}
},{
'function_score': {
'query': {
'match': { 'match': {
'name.default': { 'phrase.default': {
'query': 'test', 'query': 'test',
'boost': 1, 'analyzer': 'peliasPhrase',
'analyzer': 'peliasIndexOneEdgeGram' 'type': 'phrase',
'slop': 2,
'boost': 1
} }
} }
}], },
'should': [{ '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': { 'match': {
'phrase.default': { 'phrase.default': {
'query': 'test', 'query': 'test',
'analyzer': 'peliasPhrase', 'analyzer': 'peliasPhrase',
'type': 'phrase', 'type': 'phrase',
'boost': 1, 'slop': 2,
'slop': 2 'boost': 1
} }
} }
},{ },
'function_score': { 'max_boost': 20,
'query': { 'score_mode': 'first',
'match': { 'boost_mode': 'replace',
'phrase.default': { 'functions': [{
'query': 'test', 'field_value_factor': {
'analyzer': 'peliasPhrase', 'modifier': 'log1p',
'type': 'phrase', 'field': 'population',
'slop': 2, 'missing': 1
'boost': 1 },
} 'weight': 2
}
},
'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': {
'phrase.default': {
'query': 'test',
'analyzer': 'peliasPhrase',
'type': 'phrase',
'slop': 2,
'boost': 1
}
}
},
'max_boost': 20,
'score_mode': 'first',
'boost_mode': 'replace',
'functions': [{
'field_value_factor': {
'modifier': 'log1p',
'field': 'population',
'missing': 1
},
'weight': 2
}]
}
}] }]
} }
} }]
} }
}, },
'sort': [ '_score' ], 'sort': [ '_score' ],

188
test/unit/fixture/search_linguistic_viewport.js

@ -1,21 +1,65 @@
module.exports = { module.exports = {
'query': { 'query': {
'filtered': { 'bool': {
'query': { 'must': [
'bool': { {
'must': [ 'match': {
{ 'name.default': {
'analyzer': 'peliasQueryFullToken',
'boost': 1,
'query': 'test'
}
}
}
],
'should': [
{
'match': {
'phrase.default': {
'analyzer': 'peliasPhrase',
'type': 'phrase',
'boost': 1,
'slop': 2,
'query': 'test'
}
}
},
{
'function_score': {
'query': {
'match': { 'match': {
'name.default': { 'phrase.default': {
'analyzer': 'peliasIndexOneEdgeGram', 'analyzer': 'peliasPhrase',
'type': 'phrase',
'boost': 1, 'boost': 1,
'slop': 2,
'query': 'test' 'query': 'test'
} }
} }
} },
], 'functions': [
'should': [ {
{ 'weight': 2,
'linear': {
'center_point': {
'origin': {
'lat': 29.49136,
'lon': -82.50622
},
'offset': '0km',
'scale': '50km',
'decay': 0.5
}
}
}
],
'score_mode': 'avg',
'boost_mode': 'replace'
}
},
{
'function_score': {
'query': {
'match': { 'match': {
'phrase.default': { 'phrase.default': {
'analyzer': 'peliasPhrase', 'analyzer': 'peliasPhrase',
@ -26,98 +70,50 @@ module.exports = {
} }
} }
}, },
{ 'max_boost': 20,
'function_score': { 'functions': [
'query': { {
'match': { 'field_value_factor': {
'phrase.default': { 'modifier': 'log1p',
'analyzer': 'peliasPhrase', 'field': 'popularity',
'type': 'phrase', 'missing': 1
'boost': 1,
'slop': 2,
'query': 'test'
}
}
}, },
'functions': [ 'weight': 1
{
'weight': 2,
'linear': {
'center_point': {
'origin': {
'lat': 29.49136,
'lon': -82.50622
},
'offset': '1km',
'scale': '50km',
'decay': 0.5
}
}
}
],
'score_mode': 'avg',
'boost_mode': 'replace'
} }
}, ],
{ 'score_mode': 'first',
'function_score': { 'boost_mode': 'replace'
'query': { }
'match': { },
'phrase.default': { {
'analyzer': 'peliasPhrase', 'function_score': {
'type': 'phrase', 'query': {
'boost': 1, 'match': {
'slop': 2, 'phrase.default': {
'query': 'test' 'analyzer': 'peliasPhrase',
} 'type': 'phrase',
} 'boost': 1,
}, 'slop': 2,
'max_boost': 20, 'query': 'test'
'functions': [ }
{
'field_value_factor': {
'modifier': 'log1p',
'field': 'popularity',
'missing': 1
},
'weight': 1
}
],
'score_mode': 'first',
'boost_mode': 'replace'
} }
}, },
{ 'max_boost': 20,
'function_score': { 'functions': [
'query': { {
'match': { 'field_value_factor': {
'phrase.default': { 'modifier': 'log1p',
'analyzer': 'peliasPhrase', 'field': 'population',
'type': 'phrase', 'missing': 1
'boost': 1,
'slop': 2,
'query': 'test'
}
}
}, },
'max_boost': 20, 'weight': 2
'functions': [
{
'field_value_factor': {
'modifier': 'log1p',
'field': 'population',
'missing': 1
},
'weight': 2
}
],
'score_mode': 'first',
'boost_mode': 'replace'
} }
} ],
] 'score_mode': 'first',
'boost_mode': 'replace'
}
} }
} ]
} }
}, },
'size': 10, 'size': 10,

4
test/unit/fixture/search_linguistic_viewport_min_diagonal.js

@ -7,7 +7,7 @@ module.exports = {
{ {
'match': { 'match': {
'name.default': { 'name.default': {
'analyzer': 'peliasIndexOneEdgeGram', 'analyzer': 'peliasQueryFullToken',
'boost': 1, 'boost': 1,
'query': 'test' 'query': 'test'
} }
@ -48,7 +48,7 @@ module.exports = {
'lat': 28.49136, 'lat': 28.49136,
'lon': -87.50623 'lon': -87.50623
}, },
'offset': '1km', 'offset': '0km',
'scale': '1km', 'scale': '1km',
'decay': 0.5 'decay': 0.5
} }

160
test/unit/fixture/search_partial_address.js

@ -3,19 +3,54 @@ var vs = require('../../../query/search_defaults');
module.exports = { module.exports = {
'query': { 'query': {
'filtered': { 'bool': {
'query': { 'must': [{
'bool': { 'match': {
'must': [{ 'name.default': {
'query': 'soho grand',
'analyzer': 'peliasQueryFullToken',
'boost': 1
}
}
}],
'should': [{
'match': {
'phrase.default': {
'query': 'soho grand',
'analyzer': 'peliasPhrase',
'type': 'phrase',
'slop': 2,
'boost': 1
}
}
},{
'function_score': {
'query': {
'match': { 'match': {
'name.default': { 'phrase.default': {
'query': 'soho grand', 'query': 'soho grand',
'analyzer': 'peliasIndexOneEdgeGram', 'analyzer': 'peliasPhrase',
'type': 'phrase',
'slop': 2,
'boost': 1 'boost': 1
} }
} }
}], },
'should': [{ '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': { 'match': {
'phrase.default': { 'phrase.default': {
'query': 'soho grand', 'query': 'soho grand',
@ -25,82 +60,43 @@ module.exports = {
'boost': 1 'boost': 1
} }
} }
},{ },
'function_score': { 'max_boost': 20,
'query': { 'score_mode': 'first',
'match': { 'boost_mode': 'replace',
'phrase.default': { 'functions': [{
'query': 'soho grand', 'field_value_factor': {
'analyzer': 'peliasPhrase', 'modifier': 'log1p',
'type': 'phrase', 'field': 'population',
'slop': 2, 'missing': 1
'boost': 1 },
} 'weight': 2
}
},
'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': {
'phrase.default': {
'query': 'soho grand',
'analyzer': 'peliasPhrase',
'type': 'phrase',
'slop': 2,
'boost': 1
}
}
},
'max_boost': 20,
'score_mode': 'first',
'boost_mode': 'replace',
'functions': [{
'field_value_factor': {
'modifier': 'log1p',
'field': 'population',
'missing': 1
},
'weight': 2
}]
}
}, {
'match': {
'parent.region_a': {
'analyzer': 'peliasAdmin',
'boost': 1,
'query': 'new york'
}
}
}, {
'multi_match': {
'fields': [
'parent.country^1',
'parent.region^1',
'parent.county^1',
'parent.localadmin^1',
'parent.locality^1',
'parent.borough^1',
'parent.neighbourhood^1',
'parent.region_a^1'
],
'query': 'new york',
'analyzer': 'peliasAdmin'
}
}] }]
} }
} }, {
'match': {
'parent.region_a': {
'analyzer': 'peliasAdmin',
'boost': 1,
'query': 'new york'
}
}
}, {
'multi_match': {
'fields': [
'parent.country^1',
'parent.region^1',
'parent.county^1',
'parent.localadmin^1',
'parent.locality^1',
'parent.borough^1',
'parent.neighbourhood^1',
'parent.region_a^1'
],
'query': 'new york',
'analyzer': 'peliasAdmin'
}
}]
} }
}, },
'size': 10, 'size': 10,

192
test/unit/fixture/search_regions_address.js

@ -3,19 +3,54 @@ var vs = require('../../../query/search_defaults');
module.exports = { module.exports = {
'query': { 'query': {
'filtered': { 'bool': {
'query': { 'must': [{
'bool': { 'match': {
'must': [{ 'name.default': {
'query': '1 water st',
'analyzer': 'peliasQueryFullToken',
'boost': 1
}
}
}],
'should': [{
'match': {
'phrase.default': {
'query': '1 water st',
'analyzer': 'peliasPhrase',
'type': 'phrase',
'slop': 2,
'boost': 1
}
}
},{
'function_score': {
'query': {
'match': { 'match': {
'name.default': { 'phrase.default': {
'query': '1 water st', 'query': '1 water st',
'analyzer': 'peliasIndexOneEdgeGram', 'analyzer': 'peliasPhrase',
'type': 'phrase',
'slop': 2,
'boost': 1 'boost': 1
} }
} }
}], },
'should': [{ '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': { 'match': {
'phrase.default': { 'phrase.default': {
'query': '1 water st', 'query': '1 water st',
@ -25,98 +60,59 @@ module.exports = {
'boost': 1 'boost': 1
} }
} }
},{ },
'function_score': { 'max_boost': 20,
'query': { 'score_mode': 'first',
'match': { 'boost_mode': 'replace',
'phrase.default': { 'functions': [{
'query': '1 water st', 'field_value_factor': {
'analyzer': 'peliasPhrase', 'modifier': 'log1p',
'type': 'phrase', 'field': 'population',
'slop': 2, 'missing': 1
'boost': 1 },
} 'weight': 2
}
},
'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': {
'phrase.default': {
'query': '1 water st',
'analyzer': 'peliasPhrase',
'type': 'phrase',
'slop': 2,
'boost': 1
}
}
},
'max_boost': 20,
'score_mode': 'first',
'boost_mode': 'replace',
'functions': [{
'field_value_factor': {
'modifier': 'log1p',
'field': 'population',
'missing': 1
},
'weight': 2
}]
}
},{
'match': {
'address_parts.number': {
'query': '1',
'boost': vs['address:housenumber:boost'],
'analyzer': vs['address:housenumber:analyzer']
}
}
}, {
'match': {
'address_parts.street': {
'query': 'water st',
'boost': vs['address:street:boost'],
'analyzer': vs['address:street:analyzer']
}
}
}, {
'match': {
'parent.region_a': {
'query': 'NY',
'boost': vs['admin:region_a:boost'],
'analyzer': vs['admin:region_a:analyzer']
}
}
}, {
'multi_match': {
'fields': [
'parent.country^1',
'parent.region^1',
'parent.county^1',
'parent.localadmin^1',
'parent.locality^1',
'parent.borough^1',
'parent.neighbourhood^1',
'parent.region_a^1'
],
'query': 'manhattan',
'analyzer': 'peliasAdmin'
}
}] }]
} }
} },{
'match': {
'address_parts.number': {
'query': '1',
'boost': vs['address:housenumber:boost'],
'analyzer': vs['address:housenumber:analyzer']
}
}
}, {
'match': {
'address_parts.street': {
'query': 'water st',
'boost': vs['address:street:boost'],
'analyzer': vs['address:street:analyzer']
}
}
}, {
'match': {
'parent.region_a': {
'query': 'NY',
'boost': vs['admin:region_a:boost'],
'analyzer': vs['admin:region_a:analyzer']
}
}
}, {
'multi_match': {
'fields': [
'parent.country^1',
'parent.region^1',
'parent.county^1',
'parent.localadmin^1',
'parent.locality^1',
'parent.borough^1',
'parent.neighbourhood^1',
'parent.region_a^1'
],
'query': 'manhattan',
'analyzer': 'peliasAdmin'
}
}]
} }
}, },
'size': 10, 'size': 10,

132
test/unit/fixture/search_with_source_filtering.js

@ -1,90 +1,82 @@
module.exports = { module.exports = {
'query': { 'query': {
'filtered': { 'bool': {
'query': { 'must': [{
'bool': { 'match': {
'must': [{ 'name.default': {
'query': 'test',
'boost': 1,
'analyzer': 'peliasQueryFullToken'
}
}
}],
'should': [{
'match': {
'phrase.default': {
'query': 'test',
'analyzer': 'peliasPhrase',
'type': 'phrase',
'boost': 1,
'slop': 2
}
}
},{
'function_score': {
'query': {
'match': { 'match': {
'name.default': { 'phrase.default': {
'query': 'test', 'query': 'test',
'boost': 1, 'analyzer': 'peliasPhrase',
'analyzer': 'peliasIndexOneEdgeGram' 'type': 'phrase',
'slop': 2,
'boost': 1
} }
} }
}], },
'should': [{ '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': { 'match': {
'phrase.default': { 'phrase.default': {
'query': 'test', 'query': 'test',
'analyzer': 'peliasPhrase', 'analyzer': 'peliasPhrase',
'type': 'phrase', 'type': 'phrase',
'boost': 1, 'slop': 2,
'slop': 2 'boost': 1
} }
} }
},{ },
'function_score': { 'max_boost': 20,
'query': { 'score_mode': 'first',
'match': { 'boost_mode': 'replace',
'phrase.default': { 'functions': [{
'query': 'test', 'field_value_factor': {
'analyzer': 'peliasPhrase', 'modifier': 'log1p',
'type': 'phrase', 'field': 'population',
'slop': 2, 'missing': 1
'boost': 1 },
} 'weight': 2
}
},
'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': {
'phrase.default': {
'query': 'test',
'analyzer': 'peliasPhrase',
'type': 'phrase',
'slop': 2,
'boost': 1
}
}
},
'max_boost': 20,
'score_mode': 'first',
'boost_mode': 'replace',
'functions': [{
'field_value_factor': {
'modifier': 'log1p',
'field': 'population',
'missing': 1
},
'weight': 2
}]
}
}] }]
} }
}, }],
'filter': { 'filter': [{
'bool': { 'terms': {
'must': [{ 'source': ['test_source']
'terms': {
'source': ['test_source']
}
}]
} }
} }]
} }
}, },
'sort': [ '_score' ], 'sort': [ '_score' ],

10
test/unit/query/reverse.js

@ -22,7 +22,7 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse( JSON.stringify( query ) ); var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/reverse_standard'); var expected = require('../fixture/reverse_standard');
t.deepEqual(compiled, expected, 'valid reverse query'); t.deepEqual(compiled, expected, 'reverse_standard');
t.end(); t.end();
}); });
@ -38,7 +38,7 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse( JSON.stringify( query ) ); var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/reverse_null_island'); var expected = require('../fixture/reverse_null_island');
t.deepEqual(compiled, expected, 'valid reverse query'); t.deepEqual(compiled, expected, 'reverse_null_island');
t.end(); t.end();
}); });
@ -54,7 +54,7 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse( JSON.stringify( query ) ); var compiled = JSON.parse( JSON.stringify( query ) );
var expected = '123km'; var expected = '123km';
t.deepEqual(compiled.query.filtered.filter.bool.must[0].geo_distance.distance, expected, 'distance set to boundary circle radius'); t.deepEqual(compiled.query.bool.filter[0].geo_distance.distance, expected, 'distance set to boundary circle radius');
t.end(); t.end();
}); });
@ -71,9 +71,9 @@ module.exports.tests.query = function(test, common) {
// this should not equal `point.lat` and `point.lon` as it was explitely specified // this should not equal `point.lat` and `point.lon` as it was explitely specified
var expected = { lat: clean['boundary.circle.lat'], lon: clean['boundary.circle.lon'] }; var expected = { lat: clean['boundary.circle.lat'], lon: clean['boundary.circle.lon'] };
var centroid = compiled.query.filtered.filter.bool.must[0].geo_distance.center_point; var centroid = compiled.query.bool.filter[0].geo_distance.center_point;
t.deepEqual(centroid, expected, 'boundary.circle/lon overrides point.lat/lon'); t.deepEqual(centroid, expected, 'reverse: boundary.circle/lon overrides point.lat/lon');
t.end(); t.end();
}); });

4
test/unit/query/search.js

@ -178,7 +178,7 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse( JSON.stringify( query ) ); var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_boundary_country'); var expected = require('../fixture/search_boundary_country');
t.deepEqual(compiled, expected, 'valid boundary.country query'); t.deepEqual(compiled, expected, 'search: valid boundary.country query');
t.end(); t.end();
}); });
@ -191,7 +191,7 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse( JSON.stringify( query ) ); var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_with_source_filtering'); var expected = require('../fixture/search_with_source_filtering');
t.deepEqual(compiled, expected, 'valid search query with source filtering'); t.deepEqual(compiled, expected, 'search: valid search query with source filtering');
t.end(); t.end();
}); });

11
test/unit/sanitiser/_sources_and_layers.js

@ -51,6 +51,17 @@ module.exports.tests.no_errors = function(test, common) {
t.end(); t.end();
}); });
test('valid combination', function(t) {
var raw = {};
var clean = { sources: ['geonames'], layers: ['macroregion'] };
var messages = sanitize(raw, clean);
t.equal(messages.errors.length, 0, 'should return no errors');
t.equal(messages.warnings.length, 0, 'should return no warnings');
t.end();
});
test('valid combination because of multiple sources', function(t) { test('valid combination because of multiple sources', function(t) {
var raw = {}; var raw = {};
var clean = { sources: ['openstreetmap', 'openaddresses'], layers: ['venue'] }; var clean = { sources: ['openstreetmap', 'openaddresses'], layers: ['venue'] };

6
test/unit/sanitiser/_tokenizer.js

@ -372,8 +372,10 @@ module.exports.tests.final_token_single_gram = function(test, common) {
'grolmanstrasse', 'grolmanstrasse',
], 'tokens produced'); ], 'tokens produced');
// last token removed! // last token marked as 'incomplete'
t.deepEquals(clean.tokens_incomplete, [], 'no tokens'); t.deepEquals(clean.tokens_incomplete, [
'a'
], 'tokens produced');
// no errors/warnings produced // no errors/warnings produced
t.deepEquals(messages.errors, [], 'no errors'); t.deepEquals(messages.errors, [], 'no errors');

Loading…
Cancel
Save