From cda0e0cf6d2f2dac04ab9855b468f22c18495ce2 Mon Sep 17 00:00:00 2001 From: Abe Jellinek Date: Thu, 10 Nov 2022 21:55:09 -0500 Subject: [PATCH] Add "Any Field" advanced search condition (#2902) --- .../content/zotero/elements/zoteroSearch.js | 1 + chrome/content/zotero/xpcom/data/search.js | 36 ++++++++++++++++++- .../zotero/xpcom/data/searchConditions.js | 16 +++++++++ chrome/locale/en-US/zotero/zotero.properties | 1 + 4 files changed, 53 insertions(+), 1 deletion(-) diff --git a/chrome/content/zotero/elements/zoteroSearch.js b/chrome/content/zotero/elements/zoteroSearch.js index 7d1d29a49d..4ac681b999 100644 --- a/chrome/content/zotero/elements/zoteroSearch.js +++ b/chrome/content/zotero/elements/zoteroSearch.js @@ -354,6 +354,7 @@ isPrimaryCondition(condition) { switch (condition) { + case 'anyField': case 'collection': case 'creator': case 'title': diff --git a/chrome/content/zotero/xpcom/data/search.js b/chrome/content/zotero/xpcom/data/search.js index dfcd5bb297..5219f24de8 100644 --- a/chrome/content/zotero/xpcom/data/search.js +++ b/chrome/content/zotero/xpcom/data/search.js @@ -961,7 +961,8 @@ Zotero.Search.prototype._buildQuery = Zotero.Promise.coroutine(function* () { var conditions = []; let lastCondition; - for (let condition of Object.values(this._conditions)) { + let conditionsToProcess = Object.values(this._conditions); + for (let condition of conditionsToProcess) { let name = condition.condition; let conditionData = Zotero.SearchConditions.get(name); @@ -1055,6 +1056,39 @@ Zotero.Search.prototype._buildQuery = Zotero.Promise.coroutine(function* () { case 'blockEnd': conditions.push({name:'blockEnd'}); continue; + + case 'anyField': + // We expand this condition to the same underlying set of conditions as 'quicksearch-fields' + // (although we don't detect keys or split into quoted and unquoted segments). 'quicksearch-fields' + // is expanded in addCondition(), but we can't do that with this condition because we don't want + // to save the conditions it expands to in the search object + conditionsToProcess.push({ condition: 'blockStart' }); + conditionsToProcess.push({ + condition: 'field', + operator: condition.operator, + value: condition.value, + required: false + }); + conditionsToProcess.push({ + condition: 'tag', + operator: condition.operator, + value: condition.value, + required: false + }); + conditionsToProcess.push({ + condition: 'note', + operator: condition.operator, + value: condition.value, + required: false + }); + conditionsToProcess.push({ + condition: 'creator', + operator: condition.operator, + value: condition.value, + required: false + }); + conditionsToProcess.push({ condition: 'blockEnd' }); + continue; } throw new Error('Unhandled special condition ' + name); diff --git a/chrome/content/zotero/xpcom/data/searchConditions.js b/chrome/content/zotero/xpcom/data/searchConditions.js index 8ad33adcc5..b9456e2bb3 100644 --- a/chrome/content/zotero/xpcom/data/searchConditions.js +++ b/chrome/content/zotero/xpcom/data/searchConditions.js @@ -451,6 +451,18 @@ Zotero.SearchConditions = new function(){ + "'section','seriesNumber','issue')"), template: true // mark for special handling }, + + { + name: 'anyField', + operators: { + is: true, + isNot: true, + contains: true, + doesNotContain: true, + beginsWith: true + }, + special: false + }, { name: 'datefield', @@ -652,6 +664,10 @@ Zotero.SearchConditions = new function(){ var collation = Zotero.getLocaleCollation(); _standardConditions.sort(function(a, b) { + // Sort Any Field to the top + if (a.name == 'anyField') { + return -1; + } return collation.compareString(1, a.localized, b.localized); }); }); diff --git a/chrome/locale/en-US/zotero/zotero.properties b/chrome/locale/en-US/zotero/zotero.properties index 4c16acea4f..8412c86245 100644 --- a/chrome/locale/en-US/zotero/zotero.properties +++ b/chrome/locale/en-US/zotero/zotero.properties @@ -853,6 +853,7 @@ searchConditions.programmingLanguage = Programming Language searchConditions.fileTypeID = Attachment File Type searchConditions.annotationText = Annotation Text searchConditions.annotationComment = Annotation Comment +searchConditions.anyField = Any Field fulltext.indexState.indexed = Indexed fulltext.indexState.unavailable = Unknown