From b373291c02219ba7f2eda7c5bd413e328126b0a5 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 19 Aug 2022 00:12:42 -0400 Subject: [PATCH] Fixed filed items with annotations appearing in Unfiled Items Fixes #2771 Regression from 20c6fe67 --- chrome/content/zotero/xpcom/data/search.js | 13 +++++++------ test/tests/searchTest.js | 12 ++++++++++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/chrome/content/zotero/xpcom/data/search.js b/chrome/content/zotero/xpcom/data/search.js index 4d68ff98e9..d38db463ea 100644 --- a/chrome/content/zotero/xpcom/data/search.js +++ b/chrome/content/zotero/xpcom/data/search.js @@ -1082,14 +1082,15 @@ Zotero.Search.prototype._buildQuery = Zotero.Promise.coroutine(function* () { } if (unfiled) { - sql += " AND (itemID NOT IN (SELECT itemID FROM collectionItems) " + sql += " AND (itemID NOT IN (" + + "SELECT itemID FROM collectionItems " // Exclude children - + "AND itemID NOT IN " - + "(SELECT itemID FROM itemAttachments WHERE parentItemID IS NOT NULL " - + "UNION SELECT itemID FROM itemNotes WHERE parentItemID IS NOT NULL)" - + ") " + + "UNION SELECT itemID FROM itemAttachments WHERE parentItemID IS NOT NULL " + + "UNION SELECT itemID FROM itemNotes WHERE parentItemID IS NOT NULL " + + "UNION SELECT itemID FROM itemAnnotations " // Exclude My Publications - + "AND itemID NOT IN (SELECT itemID FROM publicationsItems)"; + + "UNION SELECT itemID FROM publicationsItems " + + "))"; } if (retracted) { diff --git a/test/tests/searchTest.js b/test/tests/searchTest.js index dcb69b414d..23c2efc4c3 100644 --- a/test/tests/searchTest.js +++ b/test/tests/searchTest.js @@ -170,6 +170,18 @@ describe("Zotero.Search", function() { assert.sameMembers(matches, [item.id]); }); + it("should match child attachment", async function () { + var col = await createDataObject('collection'); + var item = await createDataObject('item', { collections: [col.id] }); + var attachment = await importPDFAttachment(item); + + var s = new Zotero.Search(); + s.libraryID = item.libraryID; + s.addCondition('collection', 'is', col.key); + var matches = await s.search(); + assert.sameMembers(matches, [item.id, attachment.id]); + }); + it("should find items not in collection", function* () { var col = yield createDataObject('collection'); var item = yield createDataObject('item', { collections: [col.id] });