Browse Source

more tweaks

pull/378/head
Peter Johnson 9 years ago
parent
commit
a022e62acb
  1. 52
      query/autocomplete.js
  2. 22
      query/autocomplete_defaults.js

52
query/autocomplete.js

@ -4,6 +4,20 @@ var peliasQuery = require('pelias-query'),
textParser = require('./text_parser'), textParser = require('./text_parser'),
check = require('check-types'); check = require('check-types');
var ngrams = function( vs ){
var view = peliasQuery.view.ngrams( vs );
view.match['name.default'].type = 'phrase';
view.match['name.default'].operator = 'and';
// console.log( JSON.stringify( view, null, 2 ) );
return view;
};
var phrase = function( vs ){
var view = peliasQuery.view.phrase( vs );
view.match['phrase.default'].type = 'phrase';
// console.log( JSON.stringify( view, null, 2 ) );
return view;
};
//------------------------------ //------------------------------
// autocomplete query // autocomplete query
@ -11,7 +25,12 @@ var peliasQuery = require('pelias-query'),
var query = new peliasQuery.layout.FilteredBooleanQuery(); var query = new peliasQuery.layout.FilteredBooleanQuery();
// mandatory matches // mandatory matches
query.score( peliasQuery.view.ngrams, 'must' ); query.score( ngrams, 'must' );
// address components
query.score( peliasQuery.view.address('housenumber') );
query.score( peliasQuery.view.address('street') );
query.score( peliasQuery.view.address('postcode') );
// admin components // admin components
query.score( peliasQuery.view.admin('alpha3') ); query.score( peliasQuery.view.admin('alpha3') );
@ -24,11 +43,10 @@ query.score( peliasQuery.view.admin('locality') );
query.score( peliasQuery.view.admin('neighborhood') ); query.score( peliasQuery.view.admin('neighborhood') );
// scoring boost // scoring boost
query.score( peliasQuery.view.phrase ); query.score( phrase );
var focus = peliasQuery.view.focus( peliasQuery.view.phrase );
var _tmpview = function( vs ){ var focus = peliasQuery.view.focus( ngrams );
var localView = function( vs ){
var view = focus( vs ); var view = focus( vs );
@ -38,8 +56,7 @@ var _tmpview = function( vs ){
{ 'type': { 'value': 'osmnode' } }, { 'type': { 'value': 'osmnode' } },
{ 'type': { 'value': 'osmway' } }, { 'type': { 'value': 'osmway' } },
{ 'type': { 'value': 'osmaddress' } }, { 'type': { 'value': 'osmaddress' } },
{ 'type': { 'value': 'openaddresses' } }, { 'type': { 'value': 'openaddresses' } }
{ 'type': { 'value': 'geoname' } },
] ]
}; };
} }
@ -50,9 +67,21 @@ var _tmpview = function( vs ){
// console.log( focus ); // console.log( focus );
query.score( _tmpview ); query.score( localView );
query.score( peliasQuery.view.popularity( peliasQuery.view.phrase ) );
query.score( peliasQuery.view.population( peliasQuery.view.phrase ) ); var simpleNgramsView = function( vs ){
var view = ngrams( vs );
delete view.match['name.default'].type;
delete view.match['name.default'].boost;
// console.log( JSON.stringify( view, null, 2 ) );
return view;
};
query.score( peliasQuery.view.popularity( simpleNgramsView ) );
query.score( peliasQuery.view.population( simpleNgramsView ) );
// -------------------------------- // --------------------------------
@ -64,6 +93,9 @@ function generateQuery( clean ){
var vs = new peliasQuery.Vars( defaults ); var vs = new peliasQuery.Vars( defaults );
// remove single grams at end
clean.text = clean.text.replace(/( .$)/g,'');
// input text // input text
vs.var( 'input:name', clean.text ); vs.var( 'input:name', clean.text );

22
query/autocomplete_defaults.js

@ -20,9 +20,9 @@ module.exports = extend( false, peliasQuery.defaults, {
'boundary:rect:type': 'indexed', 'boundary:rect:type': 'indexed',
'boundary:rect:_cache': true, 'boundary:rect:_cache': true,
'ngram:analyzer': 'peliasOneEdgeGram', 'ngram:analyzer': 'standard',
'ngram:field': 'name.default', 'ngram:field': 'name.default',
'ngram:boost': 1, 'ngram:boost': 100,
'phrase:analyzer': 'peliasPhrase', 'phrase:analyzer': 'peliasPhrase',
'phrase:field': 'phrase.default', 'phrase:field': 'phrase.default',
@ -33,7 +33,7 @@ module.exports = extend( false, peliasQuery.defaults, {
'focus:offset': '100km', 'focus:offset': '100km',
'focus:scale': '250km', 'focus:scale': '250km',
'focus:decay': 0.5, 'focus:decay': 0.5,
'focus:weight': 10, 'focus:weight': 2,
'function_score:score_mode': 'avg', 'function_score:score_mode': 'avg',
'function_score:boost_mode': 'multiply', 'function_score:boost_mode': 'multiply',
@ -52,35 +52,35 @@ module.exports = extend( false, peliasQuery.defaults, {
'admin:alpha3:analyzer': 'standard', 'admin:alpha3:analyzer': 'standard',
'admin:alpha3:field': 'alpha3', 'admin:alpha3:field': 'alpha3',
'admin:alpha3:boost': 5, 'admin:alpha3:boost': 50,
'admin:admin0:analyzer': 'peliasAdmin', 'admin:admin0:analyzer': 'peliasAdmin',
'admin:admin0:field': 'admin0', 'admin:admin0:field': 'admin0',
'admin:admin0:boost': 4, 'admin:admin0:boost': 40,
'admin:admin1:analyzer': 'peliasAdmin', 'admin:admin1:analyzer': 'peliasAdmin',
'admin:admin1:field': 'admin1', 'admin:admin1:field': 'admin1',
'admin:admin1:boost': 3, 'admin:admin1:boost': 30,
'admin:admin1_abbr:analyzer': 'peliasAdmin', 'admin:admin1_abbr:analyzer': 'peliasAdmin',
'admin:admin1_abbr:field': 'admin1_abbr', 'admin:admin1_abbr:field': 'admin1_abbr',
'admin:admin1_abbr:boost': 3, 'admin:admin1_abbr:boost': 30,
'admin:admin2:analyzer': 'peliasAdmin', 'admin:admin2:analyzer': 'peliasAdmin',
'admin:admin2:field': 'admin2', 'admin:admin2:field': 'admin2',
'admin:admin2:boost': 2, 'admin:admin2:boost': 20,
'admin:local_admin:analyzer': 'peliasAdmin', 'admin:local_admin:analyzer': 'peliasAdmin',
'admin:local_admin:field': 'local_admin', 'admin:local_admin:field': 'local_admin',
'admin:local_admin:boost': 1, 'admin:local_admin:boost': 10,
'admin:locality:analyzer': 'peliasAdmin', 'admin:locality:analyzer': 'peliasAdmin',
'admin:locality:field': 'locality', 'admin:locality:field': 'locality',
'admin:locality:boost': 1, 'admin:locality:boost': 10,
'admin:neighborhood:analyzer': 'peliasAdmin', 'admin:neighborhood:analyzer': 'peliasAdmin',
'admin:neighborhood:field': 'neighborhood', 'admin:neighborhood:field': 'neighborhood',
'admin:neighborhood:boost': 1, 'admin:neighborhood:boost': 10,
'popularity:field': 'popularity', 'popularity:field': 'popularity',
'popularity:modifier': 'log1p', 'popularity:modifier': 'log1p',

Loading…
Cancel
Save