diff --git a/query/autocomplete.js b/query/autocomplete.js index acaecd0c..4cf9f15c 100644 --- a/query/autocomplete.js +++ b/query/autocomplete.js @@ -48,32 +48,17 @@ var phrase_first_only = function( vs ){ return phrase( vs2 ); }; -//------------------------------ -// autocomplete query -//------------------------------ -var query = new peliasQuery.layout.FilteredBooleanQuery(); - -// mandatory matches -query.score( phrase_first_only, 'must' ); -query.score( ngrams_last_only, 'must' ); +var simpleNgramsView = function( vs ){ -// address components -query.score( peliasQuery.view.address('housenumber') ); -query.score( peliasQuery.view.address('street') ); -query.score( peliasQuery.view.address('postcode') ); + var view = ngrams( vs ); -// admin components -query.score( peliasQuery.view.admin('alpha3') ); -query.score( peliasQuery.view.admin('admin0') ); -query.score( peliasQuery.view.admin('admin1') ); -query.score( peliasQuery.view.admin('admin1_abbr') ); -query.score( peliasQuery.view.admin('admin2') ); -query.score( peliasQuery.view.admin('local_admin') ); -query.score( peliasQuery.view.admin('locality') ); -query.score( peliasQuery.view.admin('neighborhood') ); + view.match['name.default'].analyzer = 'peliasPhrase'; + delete view.match['name.default'].type; + delete view.match['name.default'].boost; -// scoring boost -// query.score( phrase ); + // console.log( JSON.stringify( view, null, 2 ) ); + return view; +}; var focus = peliasQuery.view.focus( ngrams ); var localView = function( vs ){ @@ -81,6 +66,7 @@ var localView = function( vs ){ var view = focus( vs ); if( view && view.hasOwnProperty('function_score') ){ + view.function_score.query.match['name.default'].analyzer = 'peliasPhrase'; view.function_score.filter = { 'or': [ { 'type': { 'value': 'osmnode' } }, @@ -95,20 +81,35 @@ var localView = function( vs ){ return view; }; -// console.log( focus ); +//------------------------------ +// autocomplete query +//------------------------------ +var query = new peliasQuery.layout.FilteredBooleanQuery(); -query.score( localView ); +// mandatory matches +query.score( phrase_first_only, 'must' ); +query.score( ngrams_last_only, 'must' ); -var simpleNgramsView = function( vs ){ +// address components +query.score( peliasQuery.view.address('housenumber') ); +query.score( peliasQuery.view.address('street') ); +query.score( peliasQuery.view.address('postcode') ); - var view = ngrams( vs ); +// admin components +query.score( peliasQuery.view.admin('alpha3') ); +query.score( peliasQuery.view.admin('admin0') ); +query.score( peliasQuery.view.admin('admin1') ); +query.score( peliasQuery.view.admin('admin1_abbr') ); +query.score( peliasQuery.view.admin('admin2') ); +query.score( peliasQuery.view.admin('local_admin') ); +query.score( peliasQuery.view.admin('locality') ); +query.score( peliasQuery.view.admin('neighborhood') ); - delete view.match['name.default'].type; - delete view.match['name.default'].boost; +// scoring boost +// query.score( phrase ); - // console.log( JSON.stringify( view, null, 2 ) ); - return view; -}; +// console.log( focus ); +query.score( localView ); query.score( peliasQuery.view.popularity( simpleNgramsView ) ); query.score( peliasQuery.view.population( simpleNgramsView ) ); diff --git a/query/autocomplete_defaults.js b/query/autocomplete_defaults.js index f30acc7a..c19c932a 100644 --- a/query/autocomplete_defaults.js +++ b/query/autocomplete_defaults.js @@ -30,7 +30,7 @@ module.exports = extend( false, peliasQuery.defaults, { 'phrase:slop': 2, 'focus:function': 'linear', - 'focus:offset': '100km', + 'focus:offset': '10km', 'focus:scale': '250km', 'focus:decay': 0.5, 'focus:weight': 4,