Fixed filed items with annotations appearing in Unfiled Items

Fixes #2771

Regression from 20c6fe67
This commit is contained in:
Dan Stillman 2022-08-19 00:12:42 -04:00
parent 3391f3bc99
commit b373291c02
2 changed files with 19 additions and 6 deletions

View file

@ -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) {

View file

@ -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] });