Browse Source

fix: Merge pull request #1162 from pelias/remove_focus_selected_layers

Remove focus_selected_layers query view
pull/1170/head
Julian Simioni 7 years ago committed by GitHub
parent
commit
8f2f55c9a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      query/autocomplete.js
  2. 38
      query/view/focus_selected_layers.js
  3. 16
      test/unit/fixture/autocomplete_linguistic_focus.js
  4. 16
      test/unit/fixture/autocomplete_linguistic_focus_null_island.js

3
query/autocomplete.js

@ -7,7 +7,6 @@ const logger = require('pelias-logger').get('api');
// additional views (these may be merged in to pelias/query at a later date) // additional views (these may be merged in to pelias/query at a later date)
var views = { var views = {
ngrams_strict: require('./view/ngrams_strict'), ngrams_strict: require('./view/ngrams_strict'),
focus_selected_layers: require('./view/focus_selected_layers'),
ngrams_last_token_only: require('./view/ngrams_last_token_only'), ngrams_last_token_only: require('./view/ngrams_last_token_only'),
phrase_first_tokens_only: require('./view/phrase_first_tokens_only'), phrase_first_tokens_only: require('./view/phrase_first_tokens_only'),
pop_subquery: require('./view/pop_subquery'), pop_subquery: require('./view/pop_subquery'),
@ -42,7 +41,7 @@ query.score( peliasQuery.view.admin('neighbourhood') );
// scoring boost // scoring boost
query.score( views.boost_exact_matches ); query.score( views.boost_exact_matches );
query.score( views.focus_selected_layers( views.ngrams_strict ) ); query.score( peliasQuery.view.focus( views.ngrams_strict ) );
query.score( peliasQuery.view.popularity( views.pop_subquery ) ); query.score( peliasQuery.view.popularity( views.pop_subquery ) );
query.score( peliasQuery.view.population( views.pop_subquery ) ); query.score( peliasQuery.view.population( views.pop_subquery ) );

38
query/view/focus_selected_layers.js

@ -1,38 +0,0 @@
var peliasQuery = require('pelias-query');
/**
This view is the same as `peliasQuery.view.focus` with one exception:
if the view is generated successfully, we add a 'filter' clause which
restricts the targeted '_type' to be in the list specified below.
documents which are not in the '_type' list below will simply score 0 for
this section of the query.
**/
module.exports = function( subview ){
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
var macroView = peliasQuery.view.focus( subview );
if( !macroView ){ return null; } // macroView validation failed
var view = macroView( vs );
if( view && view.hasOwnProperty('function_score') ){
view.function_score.filter = {
'or': [
{ 'term': { 'layer': 'venue' } },
{ 'term': { 'layer': 'address' } }
]
};
}
return view;
};
};

16
test/unit/fixture/autocomplete_linguistic_focus.js

@ -46,21 +46,7 @@ module.exports = {
'weight': 15 'weight': 15
}], }],
'score_mode': 'avg', 'score_mode': 'avg',
'boost_mode': 'replace', 'boost_mode': 'replace'
'filter': {
'or': [
{
'term': {
'layer': 'venue'
}
},
{
'term': {
'layer': 'address'
}
}
]
}
} }
},{ },{
'function_score': { 'function_score': {

16
test/unit/fixture/autocomplete_linguistic_focus_null_island.js

@ -46,21 +46,7 @@ module.exports = {
'weight': 15 'weight': 15
}], }],
'score_mode': 'avg', 'score_mode': 'avg',
'boost_mode': 'replace', 'boost_mode': 'replace'
'filter': {
'or': [
{
'term': {
'layer': 'venue'
}
},
{
'term': {
'layer': 'address'
}
}
]
}
} }
},{ },{
'function_score': { 'function_score': {

Loading…
Cancel
Save