|
|
@ -449,6 +449,84 @@ describe('Database', function () { |
|
|
|
}); // ==== End of 'Insert' ==== //
|
|
|
|
}); // ==== End of 'Insert' ==== //
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe('#getCandidates', function () { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('Can use an index to get docs with a basic match', function (done) { |
|
|
|
|
|
|
|
d.ensureIndex({ fieldName: 'tf' }, function (err) { |
|
|
|
|
|
|
|
d.insert({ tf: 4 }, function (err, _doc1) { |
|
|
|
|
|
|
|
d.insert({ tf: 6 }, function () { |
|
|
|
|
|
|
|
d.insert({ tf: 4, an: 'other' }, function (err, _doc2) { |
|
|
|
|
|
|
|
d.insert({ tf: 9 }, function () { |
|
|
|
|
|
|
|
var data = d.getCandidates({ r: 6, tf: 4 }) |
|
|
|
|
|
|
|
, doc1 = _.find(data, function (d) { return d._id === _doc1._id; }) |
|
|
|
|
|
|
|
, doc2 = _.find(data, function (d) { return d._id === _doc2._id; }) |
|
|
|
|
|
|
|
; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data.length.should.equal(2); |
|
|
|
|
|
|
|
assert.deepEqual(doc1, { _id: doc1._id, tf: 4 }); |
|
|
|
|
|
|
|
assert.deepEqual(doc2, { _id: doc2._id, tf: 4, an: 'other' }); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
done(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('Can use an index to get docs with a $in match', function (done) { |
|
|
|
|
|
|
|
d.ensureIndex({ fieldName: 'tf' }, function (err) { |
|
|
|
|
|
|
|
d.insert({ tf: 4 }, function (err) { |
|
|
|
|
|
|
|
d.insert({ tf: 6 }, function (err, _doc1) { |
|
|
|
|
|
|
|
d.insert({ tf: 4, an: 'other' }, function (err) { |
|
|
|
|
|
|
|
d.insert({ tf: 9 }, function (err, _doc2) { |
|
|
|
|
|
|
|
var data = d.getCandidates({ r: 6, tf: { $in: [6, 9, 5] } }) |
|
|
|
|
|
|
|
, doc1 = _.find(data, function (d) { return d._id === _doc1._id; }) |
|
|
|
|
|
|
|
, doc2 = _.find(data, function (d) { return d._id === _doc2._id; }) |
|
|
|
|
|
|
|
; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data.length.should.equal(2); |
|
|
|
|
|
|
|
assert.deepEqual(doc1, { _id: doc1._id, tf: 6 }); |
|
|
|
|
|
|
|
assert.deepEqual(doc2, { _id: doc2._id, tf: 9 }); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
done(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('If no index can be used, return the whole database', function (done) { |
|
|
|
|
|
|
|
d.ensureIndex({ fieldName: 'tf' }, function (err) { |
|
|
|
|
|
|
|
d.insert({ tf: 4 }, function (err, _doc1) { |
|
|
|
|
|
|
|
d.insert({ tf: 6 }, function (err, _doc2) { |
|
|
|
|
|
|
|
d.insert({ tf: 4, an: 'other' }, function (err, _doc3) { |
|
|
|
|
|
|
|
d.insert({ tf: 9 }, function (err, _doc4) { |
|
|
|
|
|
|
|
var data = d.getCandidates({ r: 6, notf: { $in: [6, 9, 5] } }) |
|
|
|
|
|
|
|
, doc1 = _.find(data, function (d) { return d._id === _doc1._id; }) |
|
|
|
|
|
|
|
, doc2 = _.find(data, function (d) { return d._id === _doc2._id; }) |
|
|
|
|
|
|
|
, doc3 = _.find(data, function (d) { return d._id === _doc3._id; }) |
|
|
|
|
|
|
|
, doc4 = _.find(data, function (d) { return d._id === _doc4._id; }) |
|
|
|
|
|
|
|
; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data.length.should.equal(4); |
|
|
|
|
|
|
|
assert.deepEqual(doc1, { _id: doc1._id, tf: 4 }); |
|
|
|
|
|
|
|
assert.deepEqual(doc2, { _id: doc2._id, tf: 6 }); |
|
|
|
|
|
|
|
assert.deepEqual(doc3, { _id: doc3._id, tf: 4, an: 'other' }); |
|
|
|
|
|
|
|
assert.deepEqual(doc4, { _id: doc4._id, tf: 9 }); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
done(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}); // ==== End of '#getCandidates' ==== //
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe('Find', function () { |
|
|
|
describe('Find', function () { |
|
|
|
|
|
|
|
|
|
|
|
it('Can find all documents if an empty query is used', function (done) { |
|
|
|
it('Can find all documents if an empty query is used', function (done) { |
|
|
|