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 ){
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

6
query/view/ngrams_last_token_only.js

@ -28,5 +28,9 @@ module.exports = function( vs ){
vsCopy.var('input:name').set( tokens.join(' ') );
// 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': {
'bool': {
'must': [{
'match': {
'name.default': {
'analyzer': 'peliasQueryPartialToken',
'boost': 100,
'query': 'test',
'type': 'phrase',
'operator': 'and',
'slop': 3
'constant_score': {
'query': {
'match': {
'name.default': {
'analyzer': 'peliasQueryPartialToken',
'boost': 100,
'query': 'test',
'type': 'phrase',
'operator': 'and',
'slop': 3
}
}
}
}
}],

20
test/unit/fixture/autocomplete_linguistic_focus_null_island.js

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

20
test/unit/fixture/autocomplete_linguistic_multiple_tokens.js

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

20
test/unit/fixture/autocomplete_linguistic_only.js

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

20
test/unit/fixture/autocomplete_with_source_filtering.js

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

Loading…
Cancel
Save