Add "Any Field" advanced search condition (#2902)

This commit is contained in:
Abe Jellinek 2022-11-10 21:55:09 -05:00
parent 0aae101196
commit c2941738e6
4 changed files with 53 additions and 1 deletions

View file

@ -407,6 +407,7 @@
<parameter name="condition"/> <parameter name="condition"/>
<body><![CDATA[ <body><![CDATA[
switch (condition) { switch (condition) {
case 'anyField':
case 'collection': case 'collection':
case 'creator': case 'creator':
case 'title': case 'title':

View file

@ -961,7 +961,8 @@ Zotero.Search.prototype._buildQuery = Zotero.Promise.coroutine(function* () {
var conditions = []; var conditions = [];
let lastCondition; 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 name = condition.condition;
let conditionData = Zotero.SearchConditions.get(name); let conditionData = Zotero.SearchConditions.get(name);
@ -1055,6 +1056,39 @@ Zotero.Search.prototype._buildQuery = Zotero.Promise.coroutine(function* () {
case 'blockEnd': case 'blockEnd':
conditions.push({name:'blockEnd'}); conditions.push({name:'blockEnd'});
continue; 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); throw new Error('Unhandled special condition ' + name);

View file

@ -452,6 +452,18 @@ Zotero.SearchConditions = new function(){
template: true // mark for special handling template: true // mark for special handling
}, },
{
name: 'anyField',
operators: {
is: true,
isNot: true,
contains: true,
doesNotContain: true,
beginsWith: true
},
special: false
},
{ {
name: 'datefield', name: 'datefield',
operators: { operators: {
@ -652,6 +664,10 @@ Zotero.SearchConditions = new function(){
var collation = Zotero.getLocaleCollation(); var collation = Zotero.getLocaleCollation();
_standardConditions.sort(function(a, b) { _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); return collation.compareString(1, a.localized, b.localized);
}); });
}); });

View file

@ -857,6 +857,7 @@ searchConditions.programmingLanguage = Programming Language
searchConditions.fileTypeID = Attachment File Type searchConditions.fileTypeID = Attachment File Type
searchConditions.annotationText = Annotation Text searchConditions.annotationText = Annotation Text
searchConditions.annotationComment = Annotation Comment searchConditions.annotationComment = Annotation Comment
searchConditions.anyField = Any Field
fulltext.indexState.indexed = Indexed fulltext.indexState.indexed = Indexed
fulltext.indexState.unavailable = Unknown fulltext.indexState.unavailable = Unknown