Browse Source

using ngrams (experiment)

using-pelias-ngram
Harish Krishna 10 years ago
parent
commit
5d6d22ff92
  1. 2
      controller/search.js
  2. 2
      controller/suggest.js
  3. 12
      query/suggest.js
  4. 4
      test/unit/controller/search.js
  5. 10
      test/unit/controller/suggest.js
  6. 24
      test/unit/query/suggest.js

2
controller/search.js

@ -12,7 +12,7 @@ function setup( backend, query ){
// backend command // backend command
var cmd = { var cmd = {
index: 'pelias', index: 'pelias_ngram',
searchType: 'dfs_query_then_fetch', searchType: 'dfs_query_then_fetch',
body: query( req.clean ) body: query( req.clean )
}; };

2
controller/suggest.js

@ -17,7 +17,7 @@ function setup( backend, query, query_mixer ){
// backend command // backend command
var cmd = { var cmd = {
index: 'pelias', index: 'pelias_ngram',
body: query( req.clean, query_mixer ) body: query( req.clean, query_mixer )
}; };

12
query/suggest.js

@ -34,20 +34,16 @@ function generate( params, query_mixer, fuzziness ){
'size' : this.params.size, 'size' : this.params.size,
'field' : 'suggest', 'field' : 'suggest',
'context': { 'context': {
'dataset': layers || this.params.layers, 'dataset': layers || this.params.layers
'location': {
'value': null,
'precision': precision || this.get_precision()
}
}, },
'fuzzy': { 'fuzzy': {
'fuzziness': fuzzy || fuzziness || 0 'fuzziness': fuzzy || fuzziness || 0
} }
} }
}; };
if (!isNaN(this.params.lon) && !isNaN(this.params.lat)) { // if (!isNaN(this.params.lon) && !isNaN(this.params.lat)) {
this.cmd[name].completion.context.location.value = [ this.params.lon, this.params.lat ]; // this.cmd[name].completion.context.location.value = [ this.params.lon, this.params.lat ];
} // }
}; };
var cmd = new CmdGenerator(params); var cmd = new CmdGenerator(params);

4
test/unit/controller/search.js

@ -53,7 +53,7 @@ module.exports.tests.functional_success = function(test, common) {
test('functional success', function(t) { test('functional success', function(t) {
var backend = mockBackend( 'client/search/ok/1', function( cmd ){ var backend = mockBackend( 'client/search/ok/1', function( cmd ){
t.deepEqual(cmd, { body: { a: 'b' }, index: 'pelias', searchType: 'dfs_query_then_fetch' }, 'correct backend command'); t.deepEqual(cmd, { body: { a: 'b' }, index: 'pelias_ngram', searchType: 'dfs_query_then_fetch' }, 'correct backend command');
}); });
var controller = setup( backend, mockQuery() ); var controller = setup( backend, mockQuery() );
var res = { var res = {
@ -78,7 +78,7 @@ module.exports.tests.functional_success = function(test, common) {
module.exports.tests.functional_failure = function(test, common) { module.exports.tests.functional_failure = function(test, common) {
test('functional failure', function(t) { test('functional failure', function(t) {
var backend = mockBackend( 'client/search/fail/1', function( cmd ){ var backend = mockBackend( 'client/search/fail/1', function( cmd ){
t.deepEqual(cmd, { body: { a: 'b' }, index: 'pelias', searchType: 'dfs_query_then_fetch' }, 'correct backend command'); t.deepEqual(cmd, { body: { a: 'b' }, index: 'pelias_ngram', searchType: 'dfs_query_then_fetch' }, 'correct backend command');
}); });
var controller = setup( backend, mockQuery() ); var controller = setup( backend, mockQuery() );
var next = function( message ){ var next = function( message ){

10
test/unit/controller/suggest.js

@ -62,7 +62,7 @@ module.exports.tests.functional_success = function(test, common) {
]} ]}
}, 'correct mget command'); }, 'correct mget command');
} else { } else {
t.deepEqual(cmd, { body: { input: 'b' }, index: 'pelias' }, 'correct suggest command'); t.deepEqual(cmd, { body: { input: 'b' }, index: 'pelias_ngram' }, 'correct suggest command');
} }
}); });
var controller = setup( backend, mockQuery() ); var controller = setup( backend, mockQuery() );
@ -91,16 +91,16 @@ module.exports.tests.functional_failure = function(test, common) {
if( cmd.body.docs ){ if( cmd.body.docs ){
t.deepEqual(cmd, { t.deepEqual(cmd, {
body: { docs: [ body: { docs: [
{ _id: 'mockid1', _index: 'pelias', _type: 'mocktype' }, { _id: 'mockid1', _index: 'pelias_ngram', _type: 'mocktype' },
{ _id: 'mockid2', _index: 'pelias', _type: 'mocktype' }] { _id: 'mockid2', _index: 'pelias_ngram', _type: 'mocktype' }]
} }
}, 'correct mget command'); }, 'correct mget command');
} else if (cmd.body.layers) { } else if (cmd.body.layers) {
// layers are set exclusively for admin: test for admin-only layers // layers are set exclusively for admin: test for admin-only layers
t.deepEqual(cmd, { body: { a: 'b', layers: [ 'admin0', 'admin1', 'admin2' ] }, index: 'pelias' }, t.deepEqual(cmd, { body: { a: 'b', layers: [ 'admin0', 'admin1', 'admin2' ] }, index: 'pelias_ngram' },
'correct suggest/admin command'); 'correct suggest/admin command');
} else { } else {
t.deepEqual(cmd, { body: { a: 'b' }, index: 'pelias' }, 'correct suggest command'); t.deepEqual(cmd, { body: { a: 'b' }, index: 'pelias_ngram' }, 'correct suggest command');
} }
}); });
var controller = setup( backend, mockQuery() ); var controller = setup( backend, mockQuery() );

24
test/unit/query/suggest.js

@ -24,11 +24,7 @@ module.exports.tests.query = function(test, common) {
field: 'suggest', field: 'suggest',
size: 10, size: 10,
context: { context: {
dataset: [ 'test' ], dataset: [ 'test' ]
location: {
precision: 1,
value: [ 0, 0 ]
}
}, },
fuzzy: { fuzziness: 0 }, fuzzy: { fuzziness: 0 },
} }
@ -50,11 +46,7 @@ module.exports.tests.query = function(test, common) {
field: 'suggest', field: 'suggest',
size: 10, size: 10,
context: { context: {
dataset: [ 'test' ], dataset: [ 'test' ]
location: {
precision: 1,
value: null
}
}, },
fuzzy: { fuzziness: 0 }, fuzzy: { fuzziness: 0 },
} }
@ -104,11 +96,7 @@ module.exports.tests.precision = function(test, common) {
field: 'suggest', field: 'suggest',
size: 10, size: 10,
context: { context: {
dataset: [ 'test' ], dataset: [ 'test' ]
location: {
precision: test_case.precision,
value: [ 0, 0 ]
}
}, },
fuzzy: { fuzziness: 0 }, fuzzy: { fuzziness: 0 },
} }
@ -136,11 +124,7 @@ module.exports.tests.fuzziness = function(test, common) {
field: 'suggest', field: 'suggest',
size: 10, size: 10,
context: { context: {
dataset: [ 'test' ], dataset: [ 'test' ]
location: {
precision: 1,
value: [ 0, 0 ]
}
}, },
fuzzy: { fuzziness: test_case || 0 }, fuzzy: { fuzziness: test_case || 0 },
} }

Loading…
Cancel
Save