|
|
@ -12,6 +12,19 @@ var ngrams = function( vs ){ |
|
|
|
return view; |
|
|
|
return view; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var ngrams_last_only = function( vs ){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var name = vs.var('input:name').get(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var vs2 = new peliasQuery.Vars( vs.export() ); |
|
|
|
|
|
|
|
vs2.var('input:name').set( name.substr( name.lastIndexOf(' ')+1 ) ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var view = ngrams( vs2 ); |
|
|
|
|
|
|
|
view.match['name.default'].analyzer = 'peliasOneEdgeGram'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return view; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
var phrase = function( vs ){ |
|
|
|
var phrase = function( vs ){ |
|
|
|
var view = peliasQuery.view.phrase( vs ); |
|
|
|
var view = peliasQuery.view.phrase( vs ); |
|
|
|
view.match['phrase.default'].type = 'phrase'; |
|
|
|
view.match['phrase.default'].type = 'phrase'; |
|
|
@ -19,13 +32,30 @@ var phrase = function( vs ){ |
|
|
|
return view; |
|
|
|
return view; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var phrase_first_only = function( vs ){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var name = vs.var('input:name').get(); |
|
|
|
|
|
|
|
var s = name.split(' '); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// single token only, abort
|
|
|
|
|
|
|
|
if( s.length < 2 ){ |
|
|
|
|
|
|
|
return function(){ return null; }; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var vs2 = new peliasQuery.Vars( vs.export() ); |
|
|
|
|
|
|
|
vs2.var('input:name').set( name.substr(0, name.lastIndexOf(' ') ) ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return phrase( vs2 ); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
//------------------------------
|
|
|
|
//------------------------------
|
|
|
|
// autocomplete query
|
|
|
|
// autocomplete query
|
|
|
|
//------------------------------
|
|
|
|
//------------------------------
|
|
|
|
var query = new peliasQuery.layout.FilteredBooleanQuery(); |
|
|
|
var query = new peliasQuery.layout.FilteredBooleanQuery(); |
|
|
|
|
|
|
|
|
|
|
|
// mandatory matches
|
|
|
|
// mandatory matches
|
|
|
|
query.score( ngrams, 'must' ); |
|
|
|
query.score( phrase_first_only, 'must' ); |
|
|
|
|
|
|
|
query.score( ngrams_last_only, 'must' ); |
|
|
|
|
|
|
|
|
|
|
|
// address components
|
|
|
|
// address components
|
|
|
|
query.score( peliasQuery.view.address('housenumber') ); |
|
|
|
query.score( peliasQuery.view.address('housenumber') ); |
|
|
@ -43,7 +73,7 @@ query.score( peliasQuery.view.admin('locality') ); |
|
|
|
query.score( peliasQuery.view.admin('neighborhood') ); |
|
|
|
query.score( peliasQuery.view.admin('neighborhood') ); |
|
|
|
|
|
|
|
|
|
|
|
// scoring boost
|
|
|
|
// scoring boost
|
|
|
|
query.score( phrase ); |
|
|
|
// query.score( phrase );
|
|
|
|
|
|
|
|
|
|
|
|
var focus = peliasQuery.view.focus( ngrams ); |
|
|
|
var focus = peliasQuery.view.focus( ngrams ); |
|
|
|
var localView = function( vs ){ |
|
|
|
var localView = function( vs ){ |
|
|
|