Browse Source

add unit test

pull/378/head
missinglink 9 years ago
parent
commit
3b4d566b11
  1. 80
      test/unit/fixture/autocomplete_linguistic_final_token.js
  2. 64
      test/unit/fixture/autocomplete_linguistic_focus.js
  3. 64
      test/unit/fixture/autocomplete_linguistic_focus_null_island.js
  4. 91
      test/unit/fixture/autocomplete_linguistic_multiple_tokens.js
  5. 32
      test/unit/fixture/autocomplete_linguistic_only.js
  6. 154
      test/unit/fixture/autocomplete_linguistic_with_admin.js
  7. 44
      test/unit/query/autocomplete.js

80
test/unit/fixture/autocomplete_linguistic_final_token.js

@ -0,0 +1,80 @@
module.exports = {
'query': {
'filtered': {
'query': {
'bool': {
'must': [{
'match': {
'name.default': {
'analyzer': 'peliasPhrase',
'boost': 1,
'query': 'one',
'type': 'phrase',
'operator': 'and'
}
}
}],
'should':[{
'function_score': {
'query': {
'match': {
'name.default': {
'analyzer': 'peliasPhrase',
'query': 'one',
'operator': 'and'
}
}
},
'max_boost': 20,
'score_mode': 'first',
'boost_mode': 'replace',
'filter': {
'exists': {
'field': 'popularity'
}
},
'functions': [{
'field_value_factor': {
'modifier': 'log1p',
'field': 'popularity'
},
'weight': 1
}]
}
},{
'function_score': {
'query': {
'match': {
'name.default': {
'analyzer': 'peliasPhrase',
'query': 'one',
'operator': 'and'
}
}
},
'max_boost': 20,
'score_mode': 'first',
'boost_mode': 'replace',
'filter': {
'exists': {
'field': 'population'
}
},
'functions': [{
'field_value_factor': {
'modifier': 'log1p',
'field': 'population'
},
'weight': 2
}]
}
}]
}
}
}
},
'sort': [ '_score' ],
'size': 10,
'track_scores': true
};

64
test/unit/fixture/autocomplete_linguistic_focus.js

@ -7,30 +7,24 @@ module.exports = {
'must': [{
'match': {
'name.default': {
'query': 'test',
'analyzer': 'peliasPhrase',
'boost': 1,
'analyzer': 'peliasOneEdgeGram'
}
}
}],
'should': [{
'match': {
'phrase.default': {
'query': 'test',
'analyzer': 'peliasPhrase',
'type': 'phrase',
'boost': 1,
'slop': 2
'operator': 'and'
}
}
}, {
}],
'should': [{
'function_score': {
'query': {
'match': {
'name.default': {
'analyzer': 'peliasOneEdgeGram',
'analyzer': 'peliasPhrase',
'boost': 1,
'query': 'test'
'query': 'test',
'type': 'phrase',
'operator': 'and'
}
}
},
@ -49,18 +43,40 @@ module.exports = {
'weight': 2
}],
'score_mode': 'avg',
'boost_mode': 'replace'
'boost_mode': 'replace',
'filter': {
'or': [
{
'type': {
'value': 'osmnode'
}
},
{
'type': {
'value': 'osmway'
}
},
{
'type': {
'value': 'osmaddress'
}
},
{
'type': {
'value': 'openaddresses'
}
}
]
}
}
},{
'function_score': {
'query': {
'match': {
'phrase.default': {
'query': 'test',
'name.default': {
'analyzer': 'peliasPhrase',
'type': 'phrase',
'slop': 2,
'boost': 1
'query': 'test',
'operator': 'and'
}
}
},
@ -84,12 +100,10 @@ module.exports = {
'function_score': {
'query': {
'match': {
'phrase.default': {
'query': 'test',
'name.default': {
'analyzer': 'peliasPhrase',
'type': 'phrase',
'slop': 2,
'boost': 1
'query': 'test',
'operator': 'and'
}
}
},

64
test/unit/fixture/autocomplete_linguistic_focus_null_island.js

@ -7,30 +7,24 @@ module.exports = {
'must': [{
'match': {
'name.default': {
'query': 'test',
'analyzer': 'peliasPhrase',
'boost': 1,
'analyzer': 'peliasOneEdgeGram'
}
}
}],
'should': [{
'match': {
'phrase.default': {
'query': 'test',
'analyzer': 'peliasPhrase',
'type': 'phrase',
'boost': 1,
'slop': 2
'operator': 'and'
}
}
}, {
}],
'should': [{
'function_score': {
'query': {
'match': {
'name.default': {
'analyzer': 'peliasOneEdgeGram',
'analyzer': 'peliasPhrase',
'boost': 1,
'query': 'test'
'query': 'test',
'type': 'phrase',
'operator': 'and'
}
}
},
@ -49,18 +43,40 @@ module.exports = {
'weight': 2
}],
'score_mode': 'avg',
'boost_mode': 'replace'
'boost_mode': 'replace',
'filter': {
'or': [
{
'type': {
'value': 'osmnode'
}
},
{
'type': {
'value': 'osmway'
}
},
{
'type': {
'value': 'osmaddress'
}
},
{
'type': {
'value': 'openaddresses'
}
}
]
}
}
},{
'function_score': {
'query': {
'match': {
'phrase.default': {
'query': 'test',
'name.default': {
'analyzer': 'peliasPhrase',
'type': 'phrase',
'slop': 2,
'boost': 1
'query': 'test',
'operator': 'and'
}
}
},
@ -84,12 +100,10 @@ module.exports = {
'function_score': {
'query': {
'match': {
'phrase.default': {
'query': 'test',
'name.default': {
'analyzer': 'peliasPhrase',
'type': 'phrase',
'slop': 2,
'boost': 1
'query': 'test',
'operator': 'and'
}
}
},

91
test/unit/fixture/autocomplete_linguistic_multiple_tokens.js

@ -0,0 +1,91 @@
module.exports = {
'query': {
'filtered': {
'query': {
'bool': {
'must': [{
'match': {
'phrase.default': {
'analyzer': 'peliasPhrase',
'type': 'phrase',
'boost': 1,
'slop': 2,
'query': 'one two'
}
}
},
{
'match': {
'name.default': {
'analyzer': 'peliasPhrase',
'boost': 1,
'query': 'three',
'type': 'phrase',
'operator': 'and'
}
}
}],
'should':[{
'function_score': {
'query': {
'match': {
'name.default': {
'analyzer': 'peliasPhrase',
'query': 'one two three',
'operator': 'and'
}
}
},
'max_boost': 20,
'score_mode': 'first',
'boost_mode': 'replace',
'filter': {
'exists': {
'field': 'popularity'
}
},
'functions': [{
'field_value_factor': {
'modifier': 'log1p',
'field': 'popularity'
},
'weight': 1
}]
}
},{
'function_score': {
'query': {
'match': {
'name.default': {
'analyzer': 'peliasPhrase',
'query': 'one two three',
'operator': 'and'
}
}
},
'max_boost': 20,
'score_mode': 'first',
'boost_mode': 'replace',
'filter': {
'exists': {
'field': 'population'
}
},
'functions': [{
'field_value_factor': {
'modifier': 'log1p',
'field': 'population'
},
'weight': 2
}]
}
}]
}
}
}
},
'sort': [ '_score' ],
'size': 10,
'track_scores': true
};

32
test/unit/fixture/autocomplete_linguistic_only.js

@ -7,32 +7,22 @@ module.exports = {
'must': [{
'match': {
'name.default': {
'query': 'test',
'analyzer': 'peliasPhrase',
'boost': 1,
'analyzer': 'peliasOneEdgeGram'
}
}
}],
'should': [{
'match': {
'phrase.default': {
'query': 'test',
'analyzer': 'peliasPhrase',
'type': 'phrase',
'boost': 1,
'slop': 2
'operator': 'and'
}
}
},{
}],
'should':[{
'function_score': {
'query': {
'match': {
'phrase.default': {
'query': 'test',
'name.default': {
'analyzer': 'peliasPhrase',
'type': 'phrase',
'slop': 2,
'boost': 1
'query': 'test',
'operator': 'and'
}
}
},
@ -56,12 +46,10 @@ module.exports = {
'function_score': {
'query': {
'match': {
'phrase.default': {
'query': 'test',
'name.default': {
'analyzer': 'peliasPhrase',
'type': 'phrase',
'slop': 2,
'boost': 1
'query': 'test',
'operator': 'and'
}
}
},

154
test/unit/fixture/autocomplete_linguistic_with_admin.js

@ -0,0 +1,154 @@
module.exports = {
'query': {
'filtered': {
'query': {
'bool': {
'must': [
{
'match': {
'phrase.default': {
'analyzer': 'peliasPhrase',
'type': 'phrase',
'boost': 1,
'slop': 2,
'query': 'one two'
}
}
}
],
'should': [
{
'match': {
'admin0': {
'analyzer': 'peliasAdmin',
'boost': 4,
'query': 'three'
}
}
},
{
'match': {
'admin1': {
'analyzer': 'peliasAdmin',
'boost': 3,
'query': 'three'
}
}
},
{
'match': {
'admin1_abbr': {
'analyzer': 'peliasAdmin',
'boost': 3,
'query': 'three'
}
}
},
{
'match': {
'admin2': {
'analyzer': 'peliasAdmin',
'boost': 2,
'query': 'three'
}
}
},
{
'match': {
'local_admin': {
'analyzer': 'peliasAdmin',
'boost': 1,
'query': 'three'
}
}
},
{
'match': {
'locality': {
'analyzer': 'peliasAdmin',
'boost': 1,
'query': 'three'
}
}
},
{
'match': {
'neighborhood': {
'analyzer': 'peliasAdmin',
'boost': 1,
'query': 'three'
}
}
},
{
'function_score': {
'query': {
'match': {
'name.default': {
'analyzer': 'peliasPhrase',
'query': 'one two',
'operator': 'and'
}
}
},
'max_boost': 20,
'functions': [
{
'field_value_factor': {
'modifier': 'log1p',
'field': 'popularity'
},
'weight': 1
}
],
'score_mode': 'first',
'boost_mode': 'replace',
'filter': {
'exists': {
'field': 'popularity'
}
}
}
},
{
'function_score': {
'query': {
'match': {
'name.default': {
'analyzer': 'peliasPhrase',
'query': 'one two',
'operator': 'and'
}
}
},
'max_boost': 20,
'functions': [
{
'field_value_factor': {
'modifier': 'log1p',
'field': 'population'
},
'weight': 2
}
],
'score_mode': 'first',
'boost_mode': 'replace',
'filter': {
'exists': {
'field': 'population'
}
}
}
}
]
}
}
}
},
'size': 10,
'track_scores': true,
'sort': [
'_score'
]
};

44
test/unit/query/autocomplete.js

@ -24,6 +24,50 @@ module.exports.tests.query = function(test, common) {
t.end();
});
test('valid lingustic autocomplete with 3 tokens', function(t) {
var query = generate({
text: 'one two three'
});
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/autocomplete_linguistic_multiple_tokens.js');
t.deepEqual(compiled, expected, 'valid autocomplete query');
t.end();
});
test('valid lingustic autocomplete with comma delimited admin section', function(t) {
var query = generate({
text: 'one two, three',
parsed_text: {
name: 'one two',
regions: [ 'one two', 'three' ],
admin_parts: 'three'
}
});
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/autocomplete_linguistic_with_admin.js');
t.deepEqual(compiled, expected, 'valid autocomplete query');
t.end();
});
// if the final token is less than 2 chars we need to remove it from the string.
// note: this behaviour is tied to having a min_gram size of 2.
// note: if 1 grams are enabled at a later date, remove this behaviour.
test('valid lingustic autocomplete final token', function(t) {
var query = generate({
text: 'one t'
});
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/autocomplete_linguistic_final_token.js');
t.deepEqual(compiled, expected, 'valid autocomplete query');
t.end();
});
test('autocomplete + focus', function(t) {
var query = generate({
text: 'test',

Loading…
Cancel
Save