Don't match all attachments with annotations for "not" search conditions
Fixes #2867
This commit is contained in:
parent
aa0ef7012c
commit
2b9e9c174f
2 changed files with 44 additions and 5 deletions
|
@ -1126,16 +1126,23 @@ Zotero.Search.prototype._buildQuery = Zotero.Promise.coroutine(function* () {
|
||||||
// Special table handling
|
// Special table handling
|
||||||
//
|
//
|
||||||
if (condition.table) {
|
if (condition.table) {
|
||||||
|
let negationOperators = ['isNot', 'doesNotContain'];
|
||||||
|
let isNegationOperator = negationOperators.includes(condition.operator);
|
||||||
|
|
||||||
condSelectSQL += 'itemID '
|
condSelectSQL += 'itemID '
|
||||||
switch (condition.operator) {
|
if (isNegationOperator) {
|
||||||
case 'isNot':
|
condSelectSQL += 'NOT ';
|
||||||
case 'doesNotContain':
|
|
||||||
condSelectSQL += 'NOT ';
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
condSelectSQL += 'IN (';
|
condSelectSQL += 'IN (';
|
||||||
selectOpenParens = 1;
|
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) {
|
switch (condition.name) {
|
||||||
// TEMP: Match parent attachments of matching annotations
|
// TEMP: Match parent attachments of matching annotations
|
||||||
case 'tag':
|
case 'tag':
|
||||||
|
|
|
@ -158,6 +158,23 @@ describe("Zotero.Search", function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Conditions", 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 () {
|
describe("collection", function () {
|
||||||
it("should find item in collection", function* () {
|
it("should find item in collection", function* () {
|
||||||
var col = yield createDataObject('collection');
|
var col = yield createDataObject('collection');
|
||||||
|
@ -233,6 +250,21 @@ describe("Zotero.Search", function() {
|
||||||
var matches = await s.search();
|
var matches = await s.search();
|
||||||
assert.sameMembers(matches, [attachment.id]);
|
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 () {
|
describe("dateAdded", function () {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue