Don't match all attachments with annotations for "not" search conditions

Fixes #2867
This commit is contained in:
Dan Stillman 2022-10-17 22:54:59 -04:00
parent aa0ef7012c
commit 2b9e9c174f
2 changed files with 44 additions and 5 deletions

View file

@ -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':
if (isNegationOperator) {
condSelectSQL += 'NOT ';
break;
}
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':

View file

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