diff --git a/core/modules/wiki.js b/core/modules/wiki.js index 03cd70b88..821a30a85 100644 --- a/core/modules/wiki.js +++ b/core/modules/wiki.js @@ -601,18 +601,50 @@ Options available: titles: Hashmap or array of tiddler titles to limit search exclude: An array of tiddler titles to exclude from the search invert: If true returns tiddlers that do not contain the specified string + caseSensitive: If true forces a case sensitive search + literal: If true, searches for literal string, rather than separate search terms */ exports.search = function(text,options) { options = options || {}; - var me = this; + var me = this,t; + // Convert the search string into a regexp for each term + var terms, searchTermsRegExps, + flags = options.caseSensitive ? "" : "i"; + if(options.literal) { + if(text.length === 0) { + return []; + } + searchTermsRegExps = [new RegExp("(" + $tw.utils.escapeRegExp(text) + ")",flags)]; + } else { + terms = text.replace(/( +)/g," ").split(" "); + searchTermsRegExps = []; + if(terms.length === 0) { + return []; + } + for(t=0; t