From 0982bcbf4517f425f164779b7bf44050f2e21854 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Wed, 17 Oct 2012 14:34:59 +0100 Subject: [PATCH] Added function to search a wiki Crude at the moment --- core/modules/wiki.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/core/modules/wiki.js b/core/modules/wiki.js index e1be97c5c..9d3aba298 100644 --- a/core/modules/wiki.js +++ b/core/modules/wiki.js @@ -593,4 +593,36 @@ exports.saveWiki = function(options) { this.callSaver("save",text); }; +/* +Return an array of tiddler titles that match a search string + text: The text string to search for + titles: Optional hashmap or array of tiddler titles to limit search + exclude: Optional; if true returns tiddlers that do not contain the specified string +*/ +exports.search = function(text,titles,exclude) { + var me = this; + // Function to check a given tiddler for the search term + var searchTiddler = function(title) { + var tiddler = me.getTiddler(title); + return tiddler ? tiddler.fields.text.indexOf(text) !== -1 : false; + } + // Loop through all the tiddlers doing the search + var results = [],t; + if($tw.utils.isArray(titles)) { + for(t=0; t