1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-08-07 22:33:50 +00:00

Fixed bugs in previous commit to extend search to titles and tags of binary tiddlers

This commit is contained in:
Jeremy Ruston 2013-10-18 16:09:10 +01:00
parent e11c620c27
commit 25612958d7

View File

@ -742,38 +742,40 @@ exports.search = function(text,options) {
// Function to check a given tiddler for the search term // Function to check a given tiddler for the search term
var searchTiddler = function(title) { var searchTiddler = function(title) {
if(!searchTermsRegExps) { if(!searchTermsRegExps) {
return !options.invert; return false;
} }
var tiddler = self.getTiddler(title); var tiddler = self.getTiddler(title);
if(!tiddler) { if(!tiddler) {
tiddler = new $tw.Tiddler({title: title, text: "", type: "text/vnd.tiddlywiki"}); tiddler = new $tw.Tiddler({title: title, text: "", type: "text/vnd.tiddlywiki"});
} }
var contentTypeInfo = $tw.config.contentTypeInfo[tiddler.fields.type] || $tw.config.contentTypeInfo["text/vnd.tiddlywiki"]; var contentTypeInfo = $tw.config.contentTypeInfo[tiddler.fields.type] || $tw.config.contentTypeInfo["text/vnd.tiddlywiki"],
var match = true; match;
for(var t=0; t<searchTermsRegExps.length; t++) { for(var t=0; t<searchTermsRegExps.length; t++) {
// Search title and body // Search title, tags and body
if(match) { match = false;
var tags = tiddler.fields.tags ? tiddler.fields.tags.join("\0") : ""; if(contentTypeInfo.encoding === "utf8") {
if(contentTypeInfo.encoding === "utf8") { match = match || searchTermsRegExps[t].test(tiddler.fields.text);
match = searchTermsRegExps[t].test(tiddler.fields.title); }
} var tags = tiddler.fields.tags ? tiddler.fields.tags.join("\0") : "";
match = match || searchTermsRegExps[t].test(tags) || searchTermsRegExps[t].test(tiddler.fields.text); match = match || searchTermsRegExps[t].test(tags) || searchTermsRegExps[t].test(tiddler.fields.title);
if(!match) {
return false;
} }
} }
return options.invert ? !match : match; return true;
}; };
// Loop through all the tiddlers doing the search // Loop through all the tiddlers doing the search
var results = []; var results = [];
if($tw.utils.isArray(options.titles)) { if($tw.utils.isArray(options.titles)) {
for(t=0; t<options.titles.length; t++) { for(t=0; t<options.titles.length; t++) {
if(searchTiddler(options.titles[t])) { if(!!searchTiddler(options.titles[t]) === !options.invert) {
results.push(options.titles[t]); results.push(options.titles[t]);
} }
} }
} else { } else {
var source = options.titles || this.tiddlers; var source = options.titles || this.tiddlers;
for(t in source) { for(t in source) {
if(searchTiddler(t)) { if(!!searchTiddler(t) === !options.invert) {
results.push(t); results.push(t);
} }
} }