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. 20
      test/unit/fixture/autocomplete_linguistic_focus.js
  4. 20
      test/unit/fixture/autocomplete_linguistic_focus_null_island.js
  5. 20
      test/unit/fixture/autocomplete_linguistic_multiple_tokens.js
  6. 20
      test/unit/fixture/autocomplete_linguistic_only.js
  7. 20
      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 )
}
};
}; };

20
test/unit/fixture/autocomplete_linguistic_focus.js

@ -3,14 +3,18 @@ module.exports = {
'query': { 'query': {
'bool': { 'bool': {
'must': [{ 'must': [{
'match': { 'constant_score': {
'name.default': { 'query': {
'analyzer': 'peliasQueryPartialToken', 'match': {
'boost': 100, 'name.default': {
'query': 'test', 'analyzer': 'peliasQueryPartialToken',
'type': 'phrase', 'boost': 100,
'operator': 'and', 'query': 'test',
'slop': 3 'type': 'phrase',
'operator': 'and',
'slop': 3
}
}
} }
} }
}], }],

20
test/unit/fixture/autocomplete_linguistic_focus_null_island.js

@ -3,14 +3,18 @@ module.exports = {
'query': { 'query': {
'bool': { 'bool': {
'must': [{ 'must': [{
'match': { 'constant_score': {
'name.default': { 'query': {
'analyzer': 'peliasQueryPartialToken', 'match': {
'boost': 100, 'name.default': {
'query': 'test', 'analyzer': 'peliasQueryPartialToken',
'type': 'phrase', 'boost': 100,
'operator': 'and', 'query': 'test',
'slop': 3 'type': 'phrase',
'operator': 'and',
'slop': 3
}
}
} }
} }
}], }],

20
test/unit/fixture/autocomplete_linguistic_multiple_tokens.js

@ -14,14 +14,18 @@ module.exports = {
} }
}, },
{ {
'match': { 'constant_score': {
'name.default': { 'query': {
'analyzer': 'peliasQueryPartialToken', 'match': {
'boost': 100, 'name.default': {
'query': 'three', 'analyzer': 'peliasQueryPartialToken',
'type': 'phrase', 'boost': 100,
'operator': 'and', 'query': 'three',
'slop': 3 'type': 'phrase',
'operator': 'and',
'slop': 3
}
}
} }
} }
}], }],

20
test/unit/fixture/autocomplete_linguistic_only.js

@ -3,14 +3,18 @@ module.exports = {
'query': { 'query': {
'bool': { 'bool': {
'must': [{ 'must': [{
'match': { 'constant_score': {
'name.default': { 'query': {
'analyzer': 'peliasQueryPartialToken', 'match': {
'boost': 100, 'name.default': {
'query': 'test', 'analyzer': 'peliasQueryPartialToken',
'type': 'phrase', 'boost': 100,
'operator': 'and', 'query': 'test',
'slop': 3 'type': 'phrase',
'operator': 'and',
'slop': 3
}
}
} }
} }
}], }],

20
test/unit/fixture/autocomplete_with_source_filtering.js

@ -3,14 +3,18 @@ module.exports = {
'query': { 'query': {
'bool': { 'bool': {
'must': [{ 'must': [{
'match': { 'constant_score': {
'name.default': { 'query': {
'analyzer': 'peliasQueryPartialToken', 'match': {
'boost': 100, 'name.default': {
'query': 'test', 'analyzer': 'peliasQueryPartialToken',
'type': 'phrase', 'boost': 100,
'operator': 'and', 'query': 'test',
'slop': 3 'type': 'phrase',
'operator': 'and',
'slop': 3
}
}
} }
} }
}], }],

Loading…
Cancel
Save