diff --git a/chrome/content/zotero/xpcom/search.js b/chrome/content/zotero/xpcom/search.js index c5a92eaeb8..88598f7afb 100644 --- a/chrome/content/zotero/xpcom/search.js +++ b/chrome/content/zotero/xpcom/search.js @@ -1152,7 +1152,7 @@ Zotero.Search.prototype._buildQuery = Zotero.Promise.coroutine(function* () { } } else { - col = yield objectTypeClass.getByLibraryAndKeyAsync( + obj = yield objectTypeClass.getByLibraryAndKeyAsync( objLibraryID, objKey ); } @@ -1175,12 +1175,10 @@ Zotero.Search.prototype._buildQuery = Zotero.Promise.coroutine(function* () { // Search descendent collections if recursive search if (recursive){ - var descendents = col.getDescendents(false, 'collection'); - if (descendents){ - for (var k in descendents){ - q.push('?'); - p.push({int:descendents[k]['id']}); - } + var descendents = obj.getDescendents(false, 'collection'); + for (let d of descendents) { + q.push('?'); + p.push(d.id); } } diff --git a/test/tests/searchTest.js b/test/tests/searchTest.js index 6d639ab936..41d6a42052 100644 --- a/test/tests/searchTest.js +++ b/test/tests/searchTest.js @@ -101,10 +101,45 @@ describe("Zotero.Search", function() { if (win) { win.close(); } - yield fooItem.erase(); - yield foobarItem.erase(); + yield fooItem.eraseTx(); + yield foobarItem.eraseTx(); }); - + + it("should find item in collection", function* () { + var col = yield createDataObject('collection'); + var item = yield createDataObject('item', { collections: [col.id] }); + + var s = new Zotero.Search(); + s.libraryID = item.libraryID; + s.addCondition('collection', 'is', col.key); + var matches = yield s.search(); + assert.sameMembers(matches, [item.id]); + }); + + it("shouldn't find item in collection with no items", function* () { + var col = yield createDataObject('collection'); + var item = yield createDataObject('item'); + + var s = new Zotero.Search(); + s.libraryID = item.libraryID; + s.addCondition('collection', 'is', col.key); + var matches = yield s.search(); + assert.lengthOf(matches, 0); + }); + + it("should find item in subcollection in recursive mode", function* () { + var col1 = yield createDataObject('collection'); + var col2 = yield createDataObject('collection', { parentID: col1.id }); + var item = yield createDataObject('item', { collections: [col2.id] }); + + var s = new Zotero.Search(); + s.libraryID = item.libraryID; + s.addCondition('collection', 'is', col1.key); + s.addCondition('recursive', 'true'); + var matches = yield s.search(); + assert.sameMembers(matches, [item.id]); + }); + it("should return matches with full-text conditions", function* () { let s = new Zotero.Search(); s.addCondition('fulltextWord', 'contains', 'foo');