limiting search by tag

124 views
Skip to first unread message

ac0la

unread,
Sep 17, 2009, 11:59:43 PM9/17/09
to TiddlyWiki
Hi there:

I can't seem to find a plugin that lets me create a search box that
will only display results that have a specific tag. I want to put such
a search box in the a SideBarOptionsReadOnly tiddler I've created, so
that users' searches turn up only tiddlers tagged "Content" (and not
plugins and other irrelevant stuff). The SimpleSearchPlugin apparently
includes "tag matching" (v0.4.0), but I can't figure out how to employ
that, or if it's even what I'm looking for. I'm not at the point yet
where I can just read the code and figure out what it does.

Thanks for any suggestions!

Anthony Muscio

unread,
Sep 18, 2009, 1:02:43 AM9/18/09
to tiddl...@googlegroups.com
See,

http://www.TiddlyTools.com/#GotoPlugin

And use the format

<<gotoTiddler search filter:"contact">>

This searches all tiddler Titles for the text and tagged Contact. The Search option that becomes available within Goto does not restrict its results to those tagged contact. But often if you have not found a tiddler with the text in the title you do want to search all including content.

For cases like tiddlers titled "contact name" and tagged contact this is perfect and very fast.

Regards Tony

TonyM

If you have not found an easy way to do it with TiddlyWiki, you have missed something.
www.tiddlywiki.com

ac0la

unread,
Sep 18, 2009, 11:56:20 AM9/18/09
to TiddlyWiki
Cool plugin, but it's not quite what I'm looking for. I specifically
need a search box that works just like the normal search (searching
the full text of tiddlers) but returns only tiddlers tagged "Content."

Andres

On Sep 18, 1:02 am, Anthony Muscio <anthony.mus...@gmail.com> wrote:
> See,
>
> http://www.TiddlyTools.com/#GotoPlugin<http://www.tiddlytools.com/#GotoPlugin>
>
> And use the format
>
> <<gotoTiddler search filter:"contact">>
>
> This searches all tiddler Titles for the text and tagged Contact. The Search
> option that becomes available within Goto does not restrict its results to
> those tagged contact. But often if you have not found a tiddler with the
> text in the title you do want to search all including content.
>
> For cases like tiddlers titled "contact name" and tagged contact this is
> perfect and very fast.
>
> Regards Tony
>
> TonyM
>
> If you have not found an easy way to do it with TiddlyWiki, you have missed
> something.www.tiddlywiki.com
>

FND

unread,
Sep 18, 2009, 1:42:58 PM9/18/09
to tiddl...@googlegroups.com
> Cool plugin, but it's not quite what I'm looking for. I specifically
> need a search box that works just like the normal search (searching
> the full text of tiddlers) but returns only tiddlers tagged "Content."

This might be of interest:
http://tiddlywiki.org/wiki/Enhanced_Search


-- F.

ac0la

unread,
Sep 18, 2009, 4:18:47 PM9/18/09
to TiddlyWiki
I did already look there, but didn't see anything that addressed my
problem.

I did find something indicating that the code was changed two years
ago to allow what I'm trying to do, but I'm not at the point where I
can make it useful (or tell if it could be made useful):

Here's the discussion:
http://trac.tiddlywiki.org/ticket/387

It addresses a change that was made to the bit of code below (addition
of the "match" argument). I just don't understand what this stuff has
to do with the search macro.

// Return an array of tiddlers matching a search regular expression
TiddlyWiki.prototype.search = function
(searchRegExp,sortField,excludeTag,match)
{
var candidates = this.reverseLookup("tags",excludeTag,!!match);
var results = [];
for(var t=0; t<candidates.length; t++) {
if((candidates[t].title.search(searchRegExp) != -1) || (candidates
[t].text.search(searchRegExp) != -1))
results.push(candidates[t]);
}
if(!sortField)
sortField = "title";
results.sort(function(a,b) {return a[sortField] < b[sortField] ? -1 :
(a[sortField] == b[sortField] ? 0 : +1);});
return results;
};





On Sep 18, 1:42 pm, FND <F...@gmx.net> wrote:
> > Cool plugin, but it's not quite what I'm looking for. I specifically
> > need asearchbox that works just like the normalsearch(searching

FND

unread,
Sep 21, 2009, 9:59:26 AM9/21/09
to tiddl...@googlegroups.com
> http://trac.tiddlywiki.org/ticket/387
> It addresses a change that was made to the bit of code below (addition
> of the "match" argument). I just don't understand what this stuff has
> to do with the search macro.

It doesn't - it's just extending the API for programmers rather than the
macro for end users.
If none of the existing plugins provide the functionality you're looking
for, I'm afraid you're gonna need to write some custom code.


-- F.

Anthony Muscio

unread,
Sep 21, 2009, 8:57:22 PM9/21/09
to tiddl...@googlegroups.com
A Quick Idea,

What about developing a front end to a search macro using the Alias Plugin
Sourcehttp://www.TiddlyTools.com/#AliasPlugin
Documentationhttp://www.TiddlyTools.com/#AliasPluginInfo

This may be a way to avoid coding and at the same time reuse existing code.


Tony


TonyM

If you have not found an easy way to do it with TiddlyWiki, you have missed something.
www.tiddlywiki.com



ac0la

unread,
Sep 22, 2009, 12:24:49 PM9/22/09
to TiddlyWiki

>
> It doesn't - it's just extending the API for programmers rather than the
> macro for end users.
> If none of the existing plugins provide the functionality you're looking
> for, I'm afraid you're gonna need to write some custom code.
>
> -- F.

I'm afraid you're right. Thanks for the clarification.

A

ac0la

unread,
Sep 22, 2009, 12:25:46 PM9/22/09
to TiddlyWiki
I don't initially see how I can get this to work for me, but I'll give
it a closer look. Thank you for the suggestion!

A

> What about developing a front end to a search macro using the Alias Plugin
> Sourcehttp://www.TiddlyTools.com/#AliasPlugin<http://www.tiddlytools.com/#AliasPlugin>
> Documentationhttp://www.TiddlyTools.com/#AliasPluginInfo<http://www.tiddlytools.com/#AliasPluginInfo>

Eric Shulman

unread,
Sep 22, 2009, 1:14:24 PM9/22/09
to TiddlyWiki
> > I'm afraid you're gonna need to write some custom code.
> I'm afraid you're right. Thanks for the clarification.

Don't be afraid... :-)

Here's some custom code:

----------------------
<<tiddler {{config.options['txtMySearch']='';'';}}>><<option
txtMySearch>>/%
%/<html><nowiki><form style='display:inline'>
<select name='tags'><option value=''>Filter by tag:</option></select>
<input type='button' value='search' onclick="
var text=config.options['txtMySearch'];
var useRE=config.options['chkRegExpSearch'];
var useCase=config.options['chkCaseSensitiveSearch'];
highlightHack=new RegExp(useRE?text:text.escapeRegExp
(),useCase?'mg':'img');
var matches=store.search
(highlightHack,'tags',this.form.tags.value,true);
highlightHack=null;
var q=useRE?'/':'\x27';
if(matches.length>0) {
story.closeAllTiddlers();
story.displayTiddlers(null,matches);
displayMessage(config.macros.search.successMsg.format
([matches.length.toString(),q+text+q]));
} else
displayMessage(config.macros.search.failureMsg.format([q+text+q]));
return false;
"></form></html><<tiddler {{
var list=place.lastChild.getElementsByTagName('form')[0].tags;
var tags=store.getTags()
for (var t=0;t<tags.length;t++)
list.options[list.length]=new Option(tags[t][0],tags[t][0]);
'';}}>>
------------------------

enjoy,
-e
Eric Shulman
TiddlyTools / ELS Design Studios

P.S. GoogleGroups adds word-wrapping, so the formatting of the code
may be a bit messy. You may even have to remove some extra newlines
in order to get this to work. If you get stuck, let me know.

ac0la

unread,
Sep 22, 2009, 2:27:14 PM9/22/09
to TiddlyWiki
This is amazing, thank you! It's actually much more functionality than
I want to give users; I just want their search to spit back only
tiddlers with the "Content" tag, without giving them the option to
change this. But I'll see what I can tweak to get it that way. It will
give me chance to learn what's going on under the hatch. I won't be
afraid. :-)

Andres

Eric Shulman

unread,
Sep 22, 2009, 2:40:26 PM9/22/09
to TiddlyWiki
> This is amazing, thank you! It's actually much more functionality than
> I want to give users; I just want their search to spit back only
> tiddlers with the "Content" tag, without giving them the option to
> change this. But I'll see what I can tweak to get it that way. It will
> give me chance to learn what's going on under the hatch. I won't be
> afraid. :-)

That's just a few easy changes, and makes the code even simpler!

REMOVE
<select name='tags'><option value=''>Filter by tag:</option></
select>

CHANGE:
var matches=store.search
(highlightHack,'tags',this.form.tags.value,true);
to:
var matches=store.search(highlightHack,'tags','Content',true);

REMOVE
<<tiddler {{
        var list=place.lastChild.getElementsByTagName('form')[0].tags;
        var tags=store.getTags()
        for (var t=0;t<tags.length;t++)
                list.options[list.length]=new Option(tags[t][0],tags[t]
[0]);
'';}}>>

ac0la

unread,
Sep 23, 2009, 3:34:01 AM9/23/09
to TiddlyWiki
It works beautifully!

A million thanks. But with people like you around, I'll never learn to
do this myself....

Andres

axelm

unread,
Jul 1, 2012, 11:31:55 AM7/1/12
to tiddl...@googlegroups.com
Hello all,
this works very well.
Is there a way to just get a list of links to the matched tiddlers and not open them all?
This can sometimes be rather slow.

thanks,

axelm

Scott Simmons

unread,
Jul 1, 2012, 4:05:00 PM7/1/12
to tiddl...@googlegroups.com
I'm surprised no one mentioned Udo Borkowski's YourSearchPlugin:

http://tiddlywiki.abego-software.de/#YourSearchPlugin

In addition to having a pretty preview window, it offers extended syntax in search. where, for example, !string matches a title and #string matches a tag.

For example:

dogs -poodles -"toy dogs" !pets #tips

... would find all tiddlers that contained the string "dogs" but not the strings "poodles" or "toy dogs," but only in tiddlers whose title contained the string "pets" and that were tagged "tips."

axelm

unread,
Jul 2, 2012, 7:10:18 PM7/2/12
to tiddl...@googlegroups.com
That works great.
Is there a wild character one can use?

axel

Cyrill

unread,
Jul 3, 2012, 4:50:19 AM7/3/12
to tiddl...@googlegroups.com
Hallo Eric,

how to insert the actual tiddlername as one of the indicated filter criteria ? With this option i will use the code inserted in the ViewTemplate of the TW and it will present in every tiddler of a different way. This can be used as little visual mindmap, perhaps also to show parents, silblings and childs.

Ex:
Tiddler
Tiddlername
Table of List of filtered "Tags" and "placeholder = Tiddlername"

Kind Regards

Scott Simmons

unread,
Jul 3, 2012, 5:15:48 AM7/3/12
to tiddl...@googlegroups.com

On Monday, July 2, 2012 7:10:18 PM UTC-4, axelm wrote:
That works great.
Is there a wild character one can use?
 
It's an awesome plugin.
 
There are a couple of different ways to go about wildcard matching. For the sake of example, Let's say you have seven daily tiddlers named "MyMondayTiddler," "MyTuesdayTiddler," etc. and that you have individual tiddlers that used those names as tags.  You want to use YourSearchPlugin to find "My*dayTiddler" (where * is a wildcard).
 
Because the plugin matches individual strings by default, the easiest way might be to search what's on either side of the wildcard:
 
     !My !dayTiddler
 
would find tiddlers whose title contained both the strings "My" and "dayTiddler" -- which would give you all seven tiddlers as results.  By the same token,
 
     #My #dayTiddler
 
would do the same with tags
 
Even better, YourSearchPlugin supports regular expresssions, as long as you enclose your regexp in slashes -- so you could use a regexp wildcard pattern:
 
     !/My.*?dayTiddler/
 
With regexp, your searches can get wildly specific.
 
(For those unfamiliar with regexp, ".*?" is the equivalent of a wildcard.  The "." matches any single character, the "*" tells it to match it as many times as possible (zero or more times), and the "?" says to stop when you reach whatever comes next.)
 
In case you didn't get the YourSearchHelp tiddler when you installed the plugin, be sure to check it out here:
 
 
One of my favorite plugins -- SO versatile.  :)
Reply all
Reply to author
Forward
0 new messages