diff --git a/chrome/content/zotero/xpcom/data/search.js b/chrome/content/zotero/xpcom/data/search.js index d38db463ea..dfcd5bb297 100644 --- a/chrome/content/zotero/xpcom/data/search.js +++ b/chrome/content/zotero/xpcom/data/search.js @@ -1126,16 +1126,23 @@ Zotero.Search.prototype._buildQuery = Zotero.Promise.coroutine(function* () { // Special table handling // if (condition.table) { + let negationOperators = ['isNot', 'doesNotContain']; + let isNegationOperator = negationOperators.includes(condition.operator); + condSelectSQL += 'itemID ' - switch (condition.operator) { - case 'isNot': - case 'doesNotContain': - condSelectSQL += 'NOT '; - break; + if (isNegationOperator) { + condSelectSQL += 'NOT '; } condSelectSQL += 'IN ('; selectOpenParens = 1; + // TEMP: Don't match annotations for negation operators, since it would result in + // all parent attachments being returned + if (isNegationOperator) { + condSelectSQL += "SELECT itemID FROM items WHERE itemTypeID=" + + Zotero.ItemTypes.getID('annotation') + " UNION "; + } + switch (condition.name) { // TEMP: Match parent attachments of matching annotations case 'tag': diff --git a/test/tests/searchTest.js b/test/tests/searchTest.js index dcb69b414d..74c37b5f13 100644 --- a/test/tests/searchTest.js +++ b/test/tests/searchTest.js @@ -158,6 +158,23 @@ describe("Zotero.Search", function() { }); describe("Conditions", function () { + describe("title", function () { + // TEMP + it("shouldn't match parent attachments with annotations for 'title' 'does not contain' condition", async function () { + var attachment = await importPDFAttachment(); + var title = "Attachment Title"; + attachment.setField('title', title); + await attachment.saveTx(); + await createAnnotation('highlight', attachment); + + var s = new Zotero.Search(); + s.libraryID = userLibraryID; + s.addCondition('title', 'doesNotContain', title); + var matches = await s.search(); + assert.notInclude(matches, attachment.id); + }); + }); + describe("collection", function () { it("should find item in collection", function* () { var col = yield createDataObject('collection'); @@ -233,6 +250,21 @@ describe("Zotero.Search", function() { var matches = await s.search(); assert.sameMembers(matches, [attachment.id]); }); + + // TEMP + it("shouldn't match parent attachments with annotations for 'tag' 'is not' condition", async function () { + var attachment = await importPDFAttachment(); + await createAnnotation('highlight', attachment); + var tag = Zotero.Utilities.randomString(); + attachment.addTag(tag); + await attachment.saveTx(); + + var s = new Zotero.Search(); + s.libraryID = userLibraryID; + s.addCondition('tag', 'isNot', tag); + var matches = await s.search(); + assert.notInclude(matches, attachment.id); + }); }); describe("dateAdded", function () {