Ahh, that makes it much clearer, and easier to find a solution.
> I want to figure out how to make the script
> that produces that "Related Terms" list ignore the addition of the
> "review" tag.
Try this:
---------------
<<forEachTiddler
where 'tiddler != context.viewerTiddler &&
tiddler.tags.sort().join().replace("review", "").replace(",,",
",") == context.viewerTiddler.tags.sort().join().replace("review",
"").replace(",,", ",")'
>>
---------------
Mirrored here without the mangled line breaks:
http://tiddlywiki.pastebin.com/f74ea229a
It's a bit hacky, but should work fine.
Also note that I'm replacing the "review" tag on both ends there - not
sure whether that's what you want.
HTH.
-- F.
I'll break it down for you (including the obvious parts, for posterity):
0. x = tiddler; OR x = context.viewerTiddler;
select the respective tiddler
1. x = x.tags;
retrieve the respective tiddler's tags (array)
2. x.sort();
sort the tags array
3. x = x.join();
convert the array to a string, joining individual items with a separator
(default is a comma)
4. x = x.replace("review", "");
replace occurrences of "review" with an empty string (essentially
removing "review")
5. x = x.replace(",,", ",");
replace double commas (potential remnants from removing the "review"
bit) with a single comma
Alternatively, we could remove ",review" (or "review,") in step #4, but
that's not entirely safe because the review tag might occur at the
beginning or the end of the tag string (e.g. "review,ztag" vs.
"atag,review").
> Also, are the comma replacements because join() by default comma
> delimits? Can you join by "nothing"?
Yes, you could do array.join("") - but that's not a good idea here.
> I did manage to fix the problem by writing a new script from
> scratch last night.
I'll take a look later.
-- F.
Exactly - imagine you have the following tags "foo", "bar", "view", "re"
and "zab". After sorting and joining with an empty string, that would
turn into "foobarreviewzab", with tags #3 and #4 disappearing in the
next step.
> It also occurred to me that using commas (or any character) to
> separate might end up yielding unequal strings.
Indeed - good catch!
Let's try a regular expression then:
---------------
<<forEachTiddler
where 'tiddler != context.viewerTiddler &&
tiddler.tags.sort().join().replace(/^review,|,review/, "")) ==
context.viewerTiddler.tags.sort().join().replace(/^review,|,review/, ""));'
>>
---------------
This also combines steps 4 and 5.
> I am also curious whether you think it would be worthwhile to create a
> macro for this function so that users could specify which tag(s) to
> ignore in this kind of match? I hunted around for this pretty
> extensively and did not find it, so I might be only one who needs it.
I currently don't see a lot of demand for this - but I could look into
it if there's real interest (would require a slightly different
approach, i.e. some more time/effort).
-- F.
I'm not sure, but I think Matthew needs exact matches. For example:
tags1 = ["foo", "bar"];
tags2 = ["foo", "bar", "baz"];
var match = tags2.containsAll(tags1);
Here "match" will return TRUE - but I think it's meant to be FALSE in
that case.
-- F.