From 91cdc5610b9c68c798acd747425aa92d0a3674b7 Mon Sep 17 00:00:00 2001 From: Abe Jellinek Date: Wed, 16 Feb 2022 22:06:14 -0800 Subject: [PATCH] Search by specific creator type (#2353) Author, editor, or book author. --- chrome/content/zotero/xpcom/data/search.js | 9 +++++ .../zotero/xpcom/data/searchConditions.js | 39 +++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/chrome/content/zotero/xpcom/data/search.js b/chrome/content/zotero/xpcom/data/search.js index 73d139af8f..b060a26df9 100644 --- a/chrome/content/zotero/xpcom/data/search.js +++ b/chrome/content/zotero/xpcom/data/search.js @@ -1331,6 +1331,15 @@ Zotero.Search.prototype._buildQuery = Zotero.Promise.coroutine(function* () { condSQL += "creatorID IN (SELECT creatorID FROM creators WHERE "; openParens++; break; + + case 'author': + case 'editor': + case 'bookAuthor': { + let creatorTypeID = Zotero.CreatorTypes.getID(condition.name); + condSQL += `creatorTypeID = ${creatorTypeID} AND creatorID IN (SELECT creatorID FROM creators WHERE `; + openParens++; + break; + } case 'childNote': condSQL += "itemID IN (SELECT parentItemID FROM " diff --git a/chrome/content/zotero/xpcom/data/searchConditions.js b/chrome/content/zotero/xpcom/data/searchConditions.js index 0586e0fd8b..19117329e8 100644 --- a/chrome/content/zotero/xpcom/data/searchConditions.js +++ b/chrome/content/zotero/xpcom/data/searchConditions.js @@ -399,6 +399,42 @@ Zotero.SearchConditions = new function(){ special: true }, + { + name: 'author', + operators: { + is: true, + isNot: true, + contains: true, + doesNotContain: true + }, + table: 'itemCreators', + field: "TRIM(firstName || ' ' || lastName)" + }, + + { + name: 'editor', + operators: { + is: true, + isNot: true, + contains: true, + doesNotContain: true + }, + table: 'itemCreators', + field: "TRIM(firstName || ' ' || lastName)" + }, + + { + name: 'bookAuthor', + operators: { + is: true, + isNot: true, + contains: true, + doesNotContain: true + }, + table: 'itemCreators', + field: "TRIM(firstName || ' ' || lastName)" + }, + { name: 'field', operators: { @@ -669,6 +705,9 @@ Zotero.SearchConditions = new function(){ if (str == 'itemType') { str = 'itemTypeID'; } + else if (['author', 'editor', 'bookAuthor'].includes(str)) { + return Zotero.CreatorTypes.getLocalizedString(str); + } try { return Zotero.getString('searchConditions.' + str)