Skip to content

Commit

Permalink
moving API towards options err standard
Browse files Browse the repository at this point in the history
  • Loading branch information
fergiemcdowall committed Sep 19, 2014
1 parent b3a50e2 commit c4e3aad
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 32 deletions.
4 changes: 2 additions & 2 deletions lib/indexing/indexPeek.js
Expand Up @@ -23,8 +23,8 @@ exports.indexValue = function (key, index, callback) {
if (err) {
if (err.notFound)
return callback('[warning] key not found')
return callback(err)
return callback(true, false)
}
return callback(value);
return callback(false, value);
});
}
2 changes: 1 addition & 1 deletion lib/indexing/indexer.js
Expand Up @@ -230,7 +230,7 @@ exports.addDocToIndex = function(indexes, indexesMultiply, batch, batchName, fil
calibrater.incrementallyCalibrate(indexesMultiply, reduceTF(tf), function(msg) {
logger.info(msg);
logger.success('indexed batch: ' + batchName);
callback('[success] indexed batch: ' + batchName);
callback(false);
});
}
};
Expand Down
31 changes: 17 additions & 14 deletions lib/search-index.js
Expand Up @@ -48,12 +48,17 @@ SearchIndex.get = function(docID, callback) {
};


SearchIndex.add = function(batchString, batchName, filters, callback) {
//SearchIndex.add = function(batchString, batchName, filters, callback) {
SearchIndex.add = function(options, callback) {
if (!indexes) SearchIndex();

indexer.addDocToIndex(indexes, indexesMultiply, batchString, batchName, filters, function(msg) {
callback(msg);
});
indexer.addDocToIndex(indexes,
indexesMultiply,
options.batchString,
options.batchName,
options.filters,
function(err) {
callback(err);
});
};

SearchIndex.empty = function( callback) {
Expand All @@ -80,7 +85,6 @@ SearchIndex.search = function (q, callback) {

SearchIndex.match = function(beginsWith, callback) {
if (!indexes) SearchIndex();

matcher.matcher(indexes, beginsWith, function(msg) {
callback(msg);
});
Expand Down Expand Up @@ -116,20 +120,19 @@ SearchIndex.snapShot = function(callback) {

//utility methods for testing and devlopment
//******************************************
SearchIndex.indexRange = function(start, stop, callback) {
SearchIndex.indexRange = function(options, callback) {
if (!indexes) SearchIndex();

indexPeek.indexRange(start, stop, indexes, function(msg) {
callback(msg);
indexPeek.indexRange(options.start, options.stop, indexes, function(err) {
callback(err);
});
};
SearchIndex.indexValue = function(key, callback) {
SearchIndex.indexValue = function(options, callback) {
if (!indexes) SearchIndex();

indexPeek.indexValue(key, indexes, function(msg) {
callback(msg);
indexPeek.indexValue(options.key, indexes, function(err, value) {
callback(err, value);
});
};

//do a full recalibration of the index
SearchIndex.calibrate = function(callback) {
if (!indexes) SearchIndex();
Expand Down
32 changes: 17 additions & 15 deletions test/spec/0indexing-spec.js
Expand Up @@ -7,39 +7,41 @@ describe('indexing and search', function () {

var data = JSON.parse(fs.readFileSync('node_modules/reuters-21578-json/data/reuters-000.json'));


it('should index one file of test data', function () {
runs(function() {
this.indexingMsg = '';
this.err = undefined;
var that = this;
console.log('also in here');
si.add(data, 'reuters-000.json', ['places'], function(indexingMsg) {
console.log('in here');
that.indexingMsg = indexingMsg;
});
var options = {};
options['batchString'] = data;
options['batchName'] = 'reuters-000.json';
options['filters'] = ['places'];
si.add(options,function(err) {
that.err = err;
});
});
waitsFor(function() {
return this.indexingMsg != '';
}, 'indexingMsg not to be empty (search results returned)', 30000)
return this.err != undefined;
}, 'err not to be empty (search err returned)', 30000)
runs(function () {
expect(this.indexingMsg).toEqual('[success] indexed batch: reuters-000.json');
expect(this.err).toEqual(false);
});
});


it('verifies calibration after batch is indexed', function () {
runs(function() {
this.value = '';
this.value = undefined;
this.err = undefined;
var that = this;
si.indexValue('TF~*~1987~~', function(value) {
si.indexValue({key:'TF~*~1987~~'}, function(err, value) {
that.err = err;
that.value = value;
});
});
waitsFor(function() {
return this.value != '';
}, 'TF~*~1987~~ should have a value of 1000 in TF index ', 100000)
return this.value != undefined;
}, 'TF~*~1987~~ should have a value of 1000 in TF index ', 30000)
runs(function () {
console.log(this.value);
expect(this.value.length).toEqual(1000);
});
});
Expand Down

0 comments on commit c4e3aad

Please sign in to comment.