Can index null values

pull/2/head
Louis Chatriot 12 years ago
parent b90e1d84a2
commit 2acace4227
  1. 2
      package.json
  2. 34
      test/indexes.test.js

@ -22,7 +22,7 @@
"dependencies": { "dependencies": {
"async": "~0.2.8", "async": "~0.2.8",
"underscore": "~1.4.4", "underscore": "~1.4.4",
"binary-search-tree": "0.2.1" "binary-search-tree": "0.2.2"
}, },
"devDependencies": { "devDependencies": {
"chai": "1.0.x", "chai": "1.0.x",

@ -463,6 +463,13 @@ describe('Indexes', function () {
idx.insert(doc1); idx.insert(doc1);
idx.insert(doc2); idx.insert(doc2);
idx.insert(doc3); 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); idx.insert(doc4);
assert.deepEqual(idx.getMatching('bloup'), []); assert.deepEqual(idx.getMatching('bloup'), []);
@ -472,6 +479,33 @@ describe('Indexes', function () {
assert.deepEqual(idx.getMatching(undefined), [doc2, doc4]); 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 () { 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 }) var idx = new Index({ fieldName: 'tf', sparse: true })
, doc1 = { a: 5, tf: 'hello' } , doc1 = { a: 5, tf: 'hello' }

Loading…
Cancel
Save