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"/>
<body><![CDATA[
switch (condition) {
case 'anyField':
case 'collection':
case 'creator':
case 'title':

View file

@ -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);

View file

@ -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);
});
});

View file

@ -857,6 +857,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