diff --git a/package.json b/package.json index 21a08b5..0c656e8 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "dependencies": { "async": "~0.2.8", "underscore": "~1.4.4", - "binary-search-tree": "0.2.1" + "binary-search-tree": "0.2.2" }, "devDependencies": { "chai": "1.0.x", diff --git a/test/indexes.test.js b/test/indexes.test.js index 3710e90..5ce89de 100644 --- a/test/indexes.test.js +++ b/test/indexes.test.js @@ -463,6 +463,13 @@ describe('Indexes', function () { idx.insert(doc1); idx.insert(doc2); idx.insert(doc3); + + assert.deepEqual(idx.getMatching('bloup'), []); + assert.deepEqual(idx.getMatching('hello'), [doc1]); + assert.deepEqual(idx.getMatching('world'), [doc3]); + assert.deepEqual(idx.getMatching('yes'), []); + assert.deepEqual(idx.getMatching(undefined), [doc2]); + idx.insert(doc4); assert.deepEqual(idx.getMatching('bloup'), []); @@ -472,6 +479,33 @@ describe('Indexes', function () { assert.deepEqual(idx.getMatching(undefined), [doc2, doc4]); }); + it('Can get all documents for which a field is null', function () { + var idx = new Index({ fieldName: 'tf' }) + , doc1 = { a: 5, tf: 'hello' } + , doc2 = { a: 2, tf: null } + , doc3 = { a: 8, tf: 'world' } + , doc4 = { a: 7, tf: null } + ; + + idx.insert(doc1); + idx.insert(doc2); + idx.insert(doc3); + + assert.deepEqual(idx.getMatching('bloup'), []); + assert.deepEqual(idx.getMatching('hello'), [doc1]); + assert.deepEqual(idx.getMatching('world'), [doc3]); + assert.deepEqual(idx.getMatching('yes'), []); + assert.deepEqual(idx.getMatching(null), [doc2]); + + idx.insert(doc4); + + assert.deepEqual(idx.getMatching('bloup'), []); + assert.deepEqual(idx.getMatching('hello'), [doc1]); + assert.deepEqual(idx.getMatching('world'), [doc3]); + assert.deepEqual(idx.getMatching('yes'), []); + assert.deepEqual(idx.getMatching(null), [doc2, doc4]); + }); + it('Can get all documents for a given key in a sparse index, but not unindexed docs (= field undefined)', function () { var idx = new Index({ fieldName: 'tf', sparse: true }) , doc1 = { a: 5, tf: 'hello' }