2013-05-25 16:26:22 +00:00
|
|
|
/*\
|
2013-05-27 16:58:27 +00:00
|
|
|
title: $:/core/modules/filters/search.js
|
2013-05-25 16:26:22 +00:00
|
|
|
type: application/javascript
|
|
|
|
module-type: filteroperator
|
|
|
|
|
|
|
|
Filter operator for searching for the text in the operand tiddler
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
/*
|
|
|
|
Export our filter function
|
|
|
|
*/
|
2013-05-27 16:58:27 +00:00
|
|
|
exports.search = function(source,operator,options) {
|
|
|
|
var invert = operator.prefix === "!";
|
2018-10-30 17:39:18 +00:00
|
|
|
if(operator.suffixes) {
|
|
|
|
var hasFlag = function(flag) {
|
|
|
|
return (operator.suffixes[1] || []).indexOf(flag) !== -1;
|
|
|
|
},
|
|
|
|
excludeFields = false,
|
2018-11-01 12:56:56 +00:00
|
|
|
fieldList = operator.suffixes[0] || [],
|
|
|
|
firstField = fieldList[0] || "",
|
|
|
|
firstChar = firstField.charAt(0),
|
2018-10-30 17:39:18 +00:00
|
|
|
fields;
|
2018-11-01 12:56:56 +00:00
|
|
|
if(firstChar === "-") {
|
|
|
|
fields = [firstField.slice(1)].concat(fieldList.slice(1));
|
2018-10-30 17:39:18 +00:00
|
|
|
excludeFields = true;
|
2018-11-01 12:56:56 +00:00
|
|
|
} else if(fieldList[0] === "*"){
|
2018-10-30 17:39:18 +00:00
|
|
|
fields = [];
|
|
|
|
excludeFields = true;
|
|
|
|
} else {
|
2018-11-01 12:56:56 +00:00
|
|
|
fields = fieldList.slice(0);
|
2018-10-30 17:39:18 +00:00
|
|
|
}
|
2014-11-06 20:56:32 +00:00
|
|
|
return options.wiki.search(operator.operand,{
|
|
|
|
source: source,
|
|
|
|
invert: invert,
|
2018-10-30 17:39:18 +00:00
|
|
|
field: fields,
|
|
|
|
excludeField: excludeFields,
|
2022-02-21 15:05:34 +00:00
|
|
|
some: hasFlag("some"),
|
2018-10-30 17:39:18 +00:00
|
|
|
caseSensitive: hasFlag("casesensitive"),
|
|
|
|
literal: hasFlag("literal"),
|
|
|
|
whitespace: hasFlag("whitespace"),
|
2019-07-31 20:36:12 +00:00
|
|
|
anchored: hasFlag("anchored"),
|
2018-10-30 17:39:18 +00:00
|
|
|
regexp: hasFlag("regexp"),
|
|
|
|
words: hasFlag("words")
|
2014-11-06 20:56:32 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return options.wiki.search(operator.operand,{
|
|
|
|
source: source,
|
|
|
|
invert: invert
|
|
|
|
});
|
|
|
|
}
|
2013-05-25 16:26:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
})();
|