Browse Source

disable focus for single token queries, use constant_score for ngrams matching

pull/538/head
Peter Johnson 9 years ago
parent
commit
d3cd14e304
  1. 6
      query/view/focus_selected_layers.js
  2. 6
      query/view/ngrams_last_token_only.js
  3. 4
      test/unit/fixture/autocomplete_linguistic_focus.js
  4. 4
      test/unit/fixture/autocomplete_linguistic_focus_null_island.js
  5. 4
      test/unit/fixture/autocomplete_linguistic_multiple_tokens.js
  6. 4
      test/unit/fixture/autocomplete_linguistic_only.js
  7. 4
      test/unit/fixture/autocomplete_with_source_filtering.js

6
query/view/focus_selected_layers.js

@ -14,6 +14,12 @@ var peliasQuery = require('pelias-query');
module.exports = function( subview ){ module.exports = function( subview ){
return function( vs ){ 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 if( !subview ){ return null; } // subview validation failed
var macroView = peliasQuery.view.focus( subview ); var macroView = peliasQuery.view.focus( subview );
if( !macroView ){ return null; } // macroView validation failed if( !macroView ){ return null; } // macroView validation failed

6
query/view/ngrams_last_token_only.js

@ -28,5 +28,9 @@ module.exports = function( vs ){
vsCopy.var('input:name').set( tokens.join(' ') ); vsCopy.var('input:name').set( tokens.join(' ') );
// return the view rendered using the copy // return the view rendered using the copy
return ngrams_strict( vsCopy ); return {
'constant_score': {
'query': ngrams_strict( vsCopy )
}
};
}; };

4
test/unit/fixture/autocomplete_linguistic_focus.js

@ -3,6 +3,8 @@ module.exports = {
'query': { 'query': {
'bool': { 'bool': {
'must': [{ 'must': [{
'constant_score': {
'query': {
'match': { 'match': {
'name.default': { 'name.default': {
'analyzer': 'peliasQueryPartialToken', 'analyzer': 'peliasQueryPartialToken',
@ -13,6 +15,8 @@ module.exports = {
'slop': 3 'slop': 3
} }
} }
}
}
}], }],
'should': [{ 'should': [{
'function_score': { 'function_score': {

4
test/unit/fixture/autocomplete_linguistic_focus_null_island.js

@ -3,6 +3,8 @@ module.exports = {
'query': { 'query': {
'bool': { 'bool': {
'must': [{ 'must': [{
'constant_score': {
'query': {
'match': { 'match': {
'name.default': { 'name.default': {
'analyzer': 'peliasQueryPartialToken', 'analyzer': 'peliasQueryPartialToken',
@ -13,6 +15,8 @@ module.exports = {
'slop': 3 'slop': 3
} }
} }
}
}
}], }],
'should': [{ 'should': [{
'function_score': { 'function_score': {

4
test/unit/fixture/autocomplete_linguistic_multiple_tokens.js

@ -14,6 +14,8 @@ module.exports = {
} }
}, },
{ {
'constant_score': {
'query': {
'match': { 'match': {
'name.default': { 'name.default': {
'analyzer': 'peliasQueryPartialToken', 'analyzer': 'peliasQueryPartialToken',
@ -24,6 +26,8 @@ module.exports = {
'slop': 3 'slop': 3
} }
} }
}
}
}], }],
'should':[ 'should':[
{ {

4
test/unit/fixture/autocomplete_linguistic_only.js

@ -3,6 +3,8 @@ module.exports = {
'query': { 'query': {
'bool': { 'bool': {
'must': [{ 'must': [{
'constant_score': {
'query': {
'match': { 'match': {
'name.default': { 'name.default': {
'analyzer': 'peliasQueryPartialToken', 'analyzer': 'peliasQueryPartialToken',
@ -13,6 +15,8 @@ module.exports = {
'slop': 3 'slop': 3
} }
} }
}
}
}], }],
'should':[{ 'should':[{
'function_score': { 'function_score': {

4
test/unit/fixture/autocomplete_with_source_filtering.js

@ -3,6 +3,8 @@ module.exports = {
'query': { 'query': {
'bool': { 'bool': {
'must': [{ 'must': [{
'constant_score': {
'query': {
'match': { 'match': {
'name.default': { 'name.default': {
'analyzer': 'peliasQueryPartialToken', 'analyzer': 'peliasQueryPartialToken',
@ -13,6 +15,8 @@ module.exports = {
'slop': 3 'slop': 3
} }
} }
}
}
}], }],
'should':[{ 'should':[{
'function_score': { 'function_score': {

Loading…
Cancel
Save