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,
|
|
|
|
firstChar = operator.suffixes[0][0].charAt(0),
|
|
|
|
fields;
|
|
|
|
if(operator.suffixes[0][0].charAt(0) === "-") {
|
|
|
|
fields = [operator.suffixes[0][0].slice(1)].concat(operator.suffixes[0].slice(1));
|
|
|
|
excludeFields = true;
|
|
|
|
} else if(operator.suffixes[0][0] === "*"){
|
|
|
|
fields = [];
|
|
|
|
excludeFields = true;
|
|
|
|
} else {
|
|
|
|
fields = operator.suffixes[0].slice(0);
|
|
|
|
}
|
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,
|
|
|
|
caseSensitive: hasFlag("casesensitive"),
|
|
|
|
literal: hasFlag("literal"),
|
|
|
|
whitespace: hasFlag("whitespace"),
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
})();
|