Browse Source

simplify pass 1

pull/378/head
missinglink 9 years ago
parent
commit
6711aa45e0
  1. 45
      query/autocomplete.js
  2. 19
      query/view/ngrams_strict.js
  3. 4
      test/unit/fixture/autocomplete_linguistic_final_token.js
  4. 4
      test/unit/fixture/autocomplete_linguistic_focus.js
  5. 4
      test/unit/fixture/autocomplete_linguistic_focus_null_island.js
  6. 4
      test/unit/fixture/autocomplete_linguistic_multiple_tokens.js
  7. 4
      test/unit/fixture/autocomplete_linguistic_only.js
  8. 4
      test/unit/fixture/autocomplete_linguistic_with_admin.js

45
query/autocomplete.js

@ -4,13 +4,9 @@ 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 ){ // additional views (these may be merged in to pelias/query at a later date)
var view = peliasQuery.view.ngrams( vs ); var views = {};
view.match['name.default'].type = 'phrase'; views.ngrams_strict = require('./view/ngrams_strict');
view.match['name.default'].operator = 'and';
// console.log( JSON.stringify( view, null, 2 ) );
return view;
};
var ngrams_last_only = function( vs ){ var ngrams_last_only = function( vs ){
@ -24,19 +20,12 @@ var ngrams_last_only = function( vs ){
var vs2 = new peliasQuery.Vars( vs.export() ); var vs2 = new peliasQuery.Vars( vs.export() );
vs2.var('input:name').set( name.substr( name.lastIndexOf(' ')+1 ) ); vs2.var('input:name').set( name.substr( name.lastIndexOf(' ')+1 ) );
var view = ngrams( vs2 ); var view = views.ngrams_strict( vs2 );
view.match['name.default'].analyzer = 'peliasPhrase'; view.match['name.default'].analyzer = 'peliasPhrase';
return view; 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;
};
var phrase_first_only = function( vs ){ var phrase_first_only = function( vs ){
// hack to disable substr when query parsing enabled // hack to disable substr when query parsing enabled
@ -52,31 +41,18 @@ var phrase_first_only = function( vs ){
var vs2 = new peliasQuery.Vars( vs.export() ); var vs2 = new peliasQuery.Vars( vs.export() );
vs2.var('input:name').set( name.substr(0, name.lastIndexOf(' ') ) ); vs2.var('input:name').set( name.substr(0, name.lastIndexOf(' ') ) );
return phrase( vs2 ); return peliasQuery.view.phrase( vs2 );
} }
return phrase( vs ); return peliasQuery.view.phrase( vs );
};
var simpleNgramsView = function( vs ){
var view = ngrams( vs );
view.match['name.default'].analyzer = 'peliasPhrase';
delete view.match['name.default'].type;
delete view.match['name.default'].boost;
// console.log( JSON.stringify( view, null, 2 ) );
return view;
}; };
var focus = peliasQuery.view.focus( ngrams ); var focus = peliasQuery.view.focus( views.ngrams_strict );
var localView = function( vs ){ var localView = function( vs ){
var view = focus( vs ); var view = focus( vs );
if( view && view.hasOwnProperty('function_score') ){ if( view && view.hasOwnProperty('function_score') ){
view.function_score.query.match['name.default'].analyzer = 'peliasPhrase';
view.function_score.filter = { view.function_score.filter = {
'or': [ 'or': [
{ 'type': { 'value': 'osmnode' } }, { 'type': { 'value': 'osmnode' } },
@ -116,13 +92,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( phrase );
// console.log( focus );
query.score( localView ); query.score( localView );
query.score( peliasQuery.view.popularity( simpleNgramsView ) ); query.score( peliasQuery.view.popularity( views.ngrams_strict ) );
query.score( peliasQuery.view.population( simpleNgramsView ) ); query.score( peliasQuery.view.population( views.ngrams_strict ) );
// -------------------------------- // --------------------------------

19
query/view/ngrams_strict.js

@ -0,0 +1,19 @@
var peliasQuery = require('pelias-query');
/**
Ngrams view with the additional properties to enable:
type:phrase -> tokens MUST appear in the same order in BOTH query and index
operator:and -> ALL tokens are mandatory, missing any single token will cause
a query failure.
**/
module.exports = function( vs ){
var view = peliasQuery.view.ngrams( vs );
view.match['name.default'].type = 'phrase';
view.match['name.default'].operator = 'and';
return view;
};

4
test/unit/fixture/autocomplete_linguistic_final_token.js

@ -21,7 +21,9 @@ module.exports = {
'match': { 'match': {
'name.default': { 'name.default': {
'analyzer': 'peliasPhrase', 'analyzer': 'peliasPhrase',
'boost': 100,
'query': 'one', 'query': 'one',
'type': 'phrase',
'operator': 'and' 'operator': 'and'
} }
} }
@ -48,7 +50,9 @@ module.exports = {
'match': { 'match': {
'name.default': { 'name.default': {
'analyzer': 'peliasPhrase', 'analyzer': 'peliasPhrase',
'boost': 100,
'query': 'one', 'query': 'one',
'type': 'phrase',
'operator': 'and' 'operator': 'and'
} }
} }

4
test/unit/fixture/autocomplete_linguistic_focus.js

@ -75,7 +75,9 @@ module.exports = {
'match': { 'match': {
'name.default': { 'name.default': {
'analyzer': 'peliasPhrase', 'analyzer': 'peliasPhrase',
'boost': 100,
'query': 'test', 'query': 'test',
'type': 'phrase',
'operator': 'and' 'operator': 'and'
} }
} }
@ -102,7 +104,9 @@ module.exports = {
'match': { 'match': {
'name.default': { 'name.default': {
'analyzer': 'peliasPhrase', 'analyzer': 'peliasPhrase',
'boost': 100,
'query': 'test', 'query': 'test',
'type': 'phrase',
'operator': 'and' 'operator': 'and'
} }
} }

4
test/unit/fixture/autocomplete_linguistic_focus_null_island.js

@ -75,7 +75,9 @@ module.exports = {
'match': { 'match': {
'name.default': { 'name.default': {
'analyzer': 'peliasPhrase', 'analyzer': 'peliasPhrase',
'boost': 100,
'query': 'test', 'query': 'test',
'type': 'phrase',
'operator': 'and' 'operator': 'and'
} }
} }
@ -102,7 +104,9 @@ module.exports = {
'match': { 'match': {
'name.default': { 'name.default': {
'analyzer': 'peliasPhrase', 'analyzer': 'peliasPhrase',
'boost': 100,
'query': 'test', 'query': 'test',
'type': 'phrase',
'operator': 'and' 'operator': 'and'
} }
} }

4
test/unit/fixture/autocomplete_linguistic_multiple_tokens.js

@ -32,7 +32,9 @@ module.exports = {
'match': { 'match': {
'name.default': { 'name.default': {
'analyzer': 'peliasPhrase', 'analyzer': 'peliasPhrase',
'boost': 100,
'query': 'one two three', 'query': 'one two three',
'type': 'phrase',
'operator': 'and' 'operator': 'and'
} }
} }
@ -59,7 +61,9 @@ module.exports = {
'match': { 'match': {
'name.default': { 'name.default': {
'analyzer': 'peliasPhrase', 'analyzer': 'peliasPhrase',
'boost': 100,
'query': 'one two three', 'query': 'one two three',
'type': 'phrase',
'operator': 'and' 'operator': 'and'
} }
} }

4
test/unit/fixture/autocomplete_linguistic_only.js

@ -21,7 +21,9 @@ module.exports = {
'match': { 'match': {
'name.default': { 'name.default': {
'analyzer': 'peliasPhrase', 'analyzer': 'peliasPhrase',
'boost': 100,
'query': 'test', 'query': 'test',
'type': 'phrase',
'operator': 'and' 'operator': 'and'
} }
} }
@ -48,7 +50,9 @@ module.exports = {
'match': { 'match': {
'name.default': { 'name.default': {
'analyzer': 'peliasPhrase', 'analyzer': 'peliasPhrase',
'boost': 100,
'query': 'test', 'query': 'test',
'type': 'phrase',
'operator': 'and' 'operator': 'and'
} }
} }

4
test/unit/fixture/autocomplete_linguistic_with_admin.js

@ -87,7 +87,9 @@ module.exports = {
'match': { 'match': {
'name.default': { 'name.default': {
'analyzer': 'peliasPhrase', 'analyzer': 'peliasPhrase',
'boost': 100,
'query': 'one two', 'query': 'one two',
'type': 'phrase',
'operator': 'and' 'operator': 'and'
} }
} }
@ -117,7 +119,9 @@ module.exports = {
'match': { 'match': {
'name.default': { 'name.default': {
'analyzer': 'peliasPhrase', 'analyzer': 'peliasPhrase',
'boost': 100,
'query': 'one two', 'query': 'one two',
'type': 'phrase',
'operator': 'and' 'operator': 'and'
} }
} }

Loading…
Cancel
Save