All

The listViaContains macro shown in an previous post does not identify exact 
matches.
The xMatchTags macro listed below does return exact matches.  It uses the 
"contain and 
"count" macros from Tobias Beer.

My thanks to Tobias and the folks that kindly responded to my question.

Steve Wharton



```
\define xMatchTags(inputTiddler)
<!-- Create a comma separated list of tiddlers whose tags
       are an EXACT match of the the tags for the inputTiddler.

        Features:
        * list all of the tag combinations and the list of tidders per 
          combination without having to enumerate each combination 
          in advance;
        * tag matches are exact.

       A tidder is an exact match if:
       1.  it has all of the tags that the refTiddler has; and 
       2.  it has the same number of tags that the refTiddler 
  
       Note: the second check is necessary to eliminate tiddlers that
       have a SUPERSET of the reference tags. For example refTags
       (music, genre) would match Blues (tagged: music, genre) and 
       aboutBlues (tagged: music, genre, description).

       Example:
        * <<xMatchTags "blues">>   
        * list all of the tiddlers that have the same tags (e.g., music, 
genre) as "blues" 
        * Returns: afroPop, altCountry, alternative, bluegrass, blues, ... 
singerSongwriter,

       
------------------------------------------------------------------------------------
       Many thanks to Tobias Beer who developed  the "contains" and 
       "count" macros used below. See http://tobibeer.github.io/tw5-plugins/
       
------------------------------------------------------------------------------------
-->

<!-- Make a "copy" of the input tiddler, its tags and its number of tags.
-->
<$set name="refTiddler" value="""$inputTiddler$""">
<$set name="refTagList" filter="[<refTiddler>tags[]sort[]]">
<$set name="refTagCount" filter="[<refTiddler>tags[]count[]]">

<!-- First Filter: Find tiddlers that contain ALL of the tags in refTagList.
       Second Filter: Find tiddlers that have the refTagCount number of 
tags.
-->
<$list filter="[contains:tags $all<refTagList>] +[sort[title]]" 
variable="nextMatchingTiddler">
<$list filter="[<nextMatchingTiddler>tags[]count<refTagCount>]">
    <$link to=<<nextMatchingTiddler>> ><<nextMatchingTiddler>></$link>, 
    </$list>
</$list>
</$set></$set></$set>
\end
```

On Friday, December 9, 2016 at 8:10:33 AM UTC-5, steve wrote:
>
> Cmari
>
> Yes there is and I somehow managed to not include it. Here it is ...
>
> Steve Wharton
>
> ```
> \define listViaContains()
>
> <!--
>        List all tiddlers that match the tags in the variable "currentTags".
>
>        The "contain" plugin from Tobias Beer makes this very easy to do.
>        (His plugin can be found at 
> http://tobibeer.github.io/tw5-plugins/#contains)
> -->
>
> <$list filter="[contains:tags $all<currentTags>]">
> <$link><$view field="title"/></$link>, </$list>
>
> \end
>
> <!-- Show an example to find all tiddlers that have the same tags as the
>        "macroDef: listViaContains" tiddler.
> -->
> <$set name=currentTags filter='[<currentTiddler>tags[]sort[]]'>
> <<listViaContains>>
> </$set>
> ```
>
>
>
>
> On Thursday, December 8, 2016 at 4:18:50 PM UTC-5, cmari wrote:
>>
>> Hi Steve,
>> Is there another tiddler that contains the macro <<listViaContains>>? 
>> Sorry if I overlooked something in your post.
>> The table is really useful - thanks!
>> cmari
>>
>> On Monday, December 5, 2016 at 5:45:28 AM UTC-8, steve wrote:
>>>
>>> An Update:
>>>
>>> Thanks to everything that has responded. Alas, thus far, I have been 
>>> unable to find or develop an exact match function.
>>>
>>> Here is the macro I promised that generates a table which lists tiddlers 
>>> in order of their respective tags field.
>>> Each unique set of tags is listed on a separate line of the table, 
>>> followed by the list of tiddlers that possess those tags.
>>>
>>> Writing the plugin was made much easier thanks to Tobias Beer's 
>>> ''contains'' plugin, which can be found at 
>>> http://tobibeer.github.io/tw5-plugins/#contains.
>>> I am having difficulties in setting up an example on tiddyspot. As an 
>>> alternative a listing of the macro is given below.
>>>
>>> Steve Wharton
>>>
>>> ```
>>> \define listAsTableSortedByTagField(filter:"[!is[system]]" titleText 
>>> captionText)
>>>
>>> <!-- By Stephen Wharton (last revised Dec 3, 2016)
>>>
>>>       Generate a table of tiddlers listed in order of their unique sets 
>>> of tags. 
>>>       * first column is the unique set of tags formatted as pills
>>>       * second column is the list of tiddlers that match the tags from 
>>> the first column
>>> -->
>>>
>>> <!-- Optionally sort the tags in place for each tiddler
>>> -->
>>> <$button>Sort Tags In Place (Ascending Order)
>>> <$list filter="[!is[system]!has[draft.of]] +$filter$">
>>> <$set name=TagsString filter='[<currentTiddler>tags[]sort[]]'>
>>> <$action-setfield tags=<<TagsString>>/>
>>> </$set>
>>> </$list>
>>> </$button>
>>>
>>>
>>> <!-- Sort the tiddlers according to their (sorted) tags.
>>>        Generate the table by listing the tiddler title, followed by tag 
>>> pills.
>>> -->
>>> <table>
>>> <tr>
>>> <th>Unique Sets of Tags</th>
>>> <th>Matching Tiddlers per Tag Set</th>
>>> </tr>
>>> <$list filter="$filter$ +[each[tags]] +[sort[tags]]">
>>> <$set name=currentTags filter='[<currentTiddler>tags[]sort[]]'>
>>> <tr><td class="cellWidth4Pills"><$list filter="[all[current]tags[]]" 
>>> template="$:/core/ui/TagTemplate" storyview="pop"/></td>
>>> <td class="cellWidth4Titles"><<listViaContains>></td>
>>> </tr>
>>> </$set>
>>> </$list>
>>> </table>
>>>
>>> \end
>>>
>>> <!-- Example Application
>>> -->
>>> <<listAsTableSortedByTagField filter:"[tag[music]]" 
>>> titleText:"listSortedByTagField - example application">>
>>> ```
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/95530fd8-286b-4373-aa2f-a3650c737f2c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to