Fix quicksearch not finding annotations of standalone attachments (#5756)

Fix search not finding annotations of standalone attachments
when searching within a scope.

Fixes: #5751
This commit is contained in:
abaevbog 2026-01-28 10:30:36 -08:00 committed by GitHub
parent 1969bde82c
commit 22f62138a3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 65 additions and 2 deletions

View file

@ -611,9 +611,13 @@ Zotero.Search.prototype.search = async function (asTempTable) {
+ " WHERE parentItemID IN (SELECT itemID FROM " + tmpTable + ")) OR "
+ "itemID IN (SELECT itemID FROM itemNotes"
+ " WHERE parentItemID IN (SELECT itemID FROM " + tmpTable + "))"
// Match annotations of attachments of top-level items in scope
+ " OR itemID IN ( SELECT itemID FROM itemAnnotations WHERE "
+ " parentItemID IN ( SELECT itemID FROM itemAttachments WHERE "
+ " parentItemID IN ( SELECT itemID FROM " + tmpTable + ")))";
+ " parentItemID IN ( SELECT itemID FROM " + tmpTable + ")))"
// Match annotations of top-level attachments in scope
+ " OR itemID IN (SELECT itemID FROM itemAnnotations"
+ " WHERE parentItemID IN (SELECT itemID FROM " + tmpTable + "))";
}
sql += ")";

View file

@ -612,7 +612,7 @@ describe("Zotero.Search", function () {
describe("Quick search", function () {
describe("All Fields & Tags", function () {
it("should match parent attachment for annotation tag", async function () {
it("should match annotation for tag search", async function () {
var attachment = await importPDFAttachment();
var annotation = await createAnnotation('highlight', attachment);
var tag = Zotero.Utilities.randomString();
@ -625,6 +625,65 @@ describe("Zotero.Search", function () {
var matches = await s.search();
assert.sameMembers(matches, [annotation.id]);
});
it("should match annotation of top-level attachment within scope", async function () {
// Create collection with an attachment
var collection = await createDataObject('collection');
var attachment = await importPDFAttachment();
attachment.addToCollection(collection.id);
await attachment.saveTx();
// Add annotation with a tag to that attachment
var annotation = await createAnnotation('highlight', attachment);
var tag = Zotero.Utilities.randomString();
annotation.addTag(tag);
await annotation.saveTx();
// Search within the scope of that collection by tag
var scope = new Zotero.Search();
scope.libraryID = userLibraryID;
scope.addCondition('noChildren', 'true');
scope.addCondition('collectionID', 'is', collection.id);
var s = new Zotero.Search();
s.libraryID = userLibraryID;
s.addCondition('quicksearch-fields', 'contains', tag);
s.setScope(scope, true);
// Expect child annotation to be found
var matches = await s.search();
assert.sameMembers(matches, [annotation.id]);
});
it("should match annotation of a child attachment of an item within scope", async function () {
// Create collection with a top-level item and an attachment
var collection = await createDataObject('collection');
var item = await createDataObject('item');
var attachment = await importPDFAttachment(item);
item.addToCollection(collection.id);
await item.saveTx();
// Add annotation with a tag to the attachment
var annotation = await createAnnotation('highlight', attachment);
var tag = Zotero.Utilities.randomString();
annotation.addTag(tag);
await annotation.saveTx();
// Search within the scope of that collection by tag
var scope = new Zotero.Search();
scope.libraryID = userLibraryID;
scope.addCondition('noChildren', 'true');
scope.addCondition('collectionID', 'is', collection.id);
var s = new Zotero.Search();
s.libraryID = userLibraryID;
s.addCondition('quicksearch-fields', 'contains', tag);
s.setScope(scope, true);
// Expect child annotation to be found
var matches = await s.search();
assert.sameMembers(matches, [annotation.id]);
});
})
describe("Everything", function () {