forked from pelias/schema
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin_matching.js
More file actions
96 lines (83 loc) · 2.84 KB
/
Copy pathadmin_matching.js
File metadata and controls
96 lines (83 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// validate analyzer is behaving as expected
const Suite = require('../test/elastictest/Suite');
const config = require('pelias-config').generate();
const getTotalHits = require('./_hits_total_helper');
module.exports.tests = {};
module.exports.tests.functional = function(test, common){
test( 'functional', function(t){
var suite = new Suite( common.clientOpts, common.create );
suite.action( function( done ){ setTimeout( done, 500 ); }); // wait for es to bring some shards up
// index a document with all admin values
suite.action( function( done ){
suite.client.index({
index: suite.props.index,
id: '1', body: {
parent: {
country: 'Test Country',
country_a: 'TestCountry',
country_id: '100',
region: 'Test Region',
region_a: 'TestRegion',
region_id: '200',
county: 'Test County',
county_a: 'TestCounty',
county_id: '300',
locality: 'Test Locality',
locality_a: 'TestLocality',
locality_id: '400',
localadmin: 'Test LocalAdmin',
localadmin_a: 'TestLocalAdmin',
localadmin_id: '500',
neighbourhood: 'Test Neighbourhood',
neighbourhood_a: 'TestNeighbourhood',
neighbourhood_id: '600',
}
}
}, done );
});
// search by country
suite.assert( function( done ){
suite.client.search({
index: suite.props.index,
body: { query: { match: { 'parent.country': 'Test Country' } } }
}, function( err, res ){
t.equal( err, undefined );
t.equal( getTotalHits(res.hits), 1, 'document found' );
done();
});
});
// search by country_a
suite.assert( function( done ){
suite.client.search({
index: suite.props.index,
body: { query: { match: { 'parent.country_a': 'TestCountry' } } }
}, function( err, res ){
t.equal( err, undefined );
t.equal( getTotalHits(res.hits), 1, 'document found' );
done();
});
});
// search by country_id
suite.assert( function( done ){
suite.client.search({
index: suite.props.index,
body: { query: { match: { 'parent.country_id': '100' } } }
}, function( err, res ){
t.equal( err, undefined );
t.equal( getTotalHits(res.hits), 1, 'document found' );
done();
});
});
// ... the remaining admin fields are identical and so their assertions
// have been omitted for the sake of brevity.
suite.run( t.end );
});
};
module.exports.all = function (tape, common) {
function test(name, testFunction) {
return tape('admin matching: ' + name, testFunction);
}
for( var testCase in module.exports.tests ){
module.exports.tests[testCase](test, common);
}
};