Filter Assistance

Hey all,

Looking for some assistance in relation to a filter I’m trying to write.

Here are the steps I need the filter to take:

  • Find tiddlers whose primary-topic field contains the current tiddler
  • Extract all links ( [[ ]] ) from those tiddlers’ text fields
  • Deduplicate and sort those links alphabetically, then show each link to user in list.
  • For each link, find tiddlers that both reference the current tiddler in primary-topic AND contain that specific link in their text field
  • Display those tiddlers under each link

The above would be option 1. Option 2 would be the following:

  • Find tiddlers whose primary-topic field contains the current tiddler
  • Extract all links ( [[ ]] ) from those tiddlers’ text fields
  • Deduplicate and sort those links alphabetically, then show each link to user in list.
  • Allow user to select (check) one or more links. Each selection “runs” a filter that finds all tiddlers that both reference the current tiddler in primary-topic AND contains the selected links in their text field.
  • Display those tiddlers on the right side of the screen (or even on another tiddler…not picky here).

I would suggest not trying to jam this into one filter but use a filter in a list widget for points 1-3, then with in that list widget address items 4-5.

Maybe even break it apart further. Once you have a working solution you may be able to simplify further.

As Tony pointed out, in no way can you do this with 1 filter. Your options 1 and 2 are 2 relatively complex constructions.

Here is a text-case for the first option how I did understand it.

Create a tiddler named eg: link-backlink-primary-topic
tag: $:/tags/wiki-test-spec
caption: Link, Backlinks and primary-topic

With the following content:

title: Narrative

* Find tiddlers whose primary-topic field contains the current tiddler
* Extract all links ( [[ ]] ) from those tiddlers’ text fields
* Deduplicate and sort those links alphabetically, then show each link to user in list.
* For each link, find tiddlers that both reference the current tiddler in primary-topic AND contain that specific link in their text field
* Display those tiddlers under each link

+
title: Output

\procedure list-linksX(filter) <$text text=<<filter>>/>

\procedure list-primary(currentTiddler)
currentTiddler: <<currentTiddler>>
<ul>
<$list filter="[primary-topic<currentTiddler>]" variable="primaryItem">
  <li><<currentTiddler>> is a primary-topic in: <$link to=<<primaryItem>>/></li>
    <ul>
      <$list filter="[<primaryItem>links[]]" variable="listItem">
        <li>contains a link to: <$link to=<<listItem>>/></li>
        <ul>
          <<listItem>> is a primary-topic in: <$transclude $variable="list-links" filter="[primary-topic<listItem>]"/>
          tiddlers that link to <<listItem>>: <$list filter="[<listItem>backlinks[]]" join=", "/><br>
          tiddlers that link to <<listItem>>: <$transclude $variable="list-links" filter=`[[$(listItem)$]backlinks[]]`/>
        </ul>
      </$list>
    </ul>
</$list>
</ul>
\end

<<list-primary "topic-1">>

---

<<list-primary "topic-2">>
+
title: topic-1

topic-1 links to [[link-1]] and [[link-2]] 
+
title: topic-2

topic-1 links to [[link-3]] and [[link-4]] 
+
title: link-1
primary-topic: topic-1

[[link-1-1]]

+
title: link-2
primary-topic: topic-2

[[link-2-2]]

+
title: test
primary-topic: link-1-1

+
title: test-2

[[link-1-1]]

+
title: link-1-1

link-1-1 is a primary-topic in tiddler: [[test]]

It creates a testcase widget with which you can play with.

  • The procedure list-linksX(filter) is for testing only.
  • The procedure \procedure list-primary(currentTiddler) is for easier testing and it can be converted to a template if needed.

I did try to add some text, that should explain what’s going on.

Option 2 can be created using the knowledge from option 1, but I did not have time to play with it.

There is the testcase tiddler, that can be downloaded and imported to tiddlywiki.com

Also see: Reference Documentation for used widgets and macros

Have fun!
Mario

link-backlink-primary-topic.json (2.0 KB)

Ultimatly you could generate a lists of titles, if necessary wikifying the output of a nested list structure (Not recommended) then feed this into a new listing mechanisium that then performs a break on each source tiddler.

But the additional filter run prefixes can be used to recursive lists, but calling functions (filters)