Need a single filter: where list field contains any one title in a list of titles

I need a TiddlyWiki filter to replace the one below, where place1 place2 and place3 are housed in a variable as a list of place tiddler titles.

Thanks in advance.

[tag[event]contains:place[place1]] [tag[event]contains:place[place2]][tag[event]contains:place[place3]] +[unique[]sort[date]]

What does the variable look like ?

Say your variable has three places, can you give some sample code with a “let” statement?

Can any of the places have spaces in them ? If so, please include that in your sample code.

No need to show where the places are coming from. Just need to see what the content in the variable looks like when displaying the content in the variable.

The place field in an event tiddler is a title list. A variable that I would suggest is a title list as well. Eg

[[Upper Canada]] Ontario [[Canada West]]

Does this answer your question?

If you don’t setup a common/standard starting point, then everybody might base a solution from different starting points, none of which might match exactly the starting point.

So a good idea for you to provide a “let” statement that can be copy/pasted into any TiddlyWiki, and that let statement sets the stage for solutions that are compatible with what you are doing.

So a <$let v="[[Upper Canada]] Ontario [[Canada West]]"> ... </$let> is the starting point?

Ignore. Bad code. Working code in other post further below.

My question is focused on a filter solution where the “contains” operator or an alternative is used to obtain event tiddlers where the title list contains any one of the titles i have in a list. That list may or may not be in a variable. I’m not bothered at this point if someone has a solution that does not use a variable.

But, yes, I’m okay with that being a starting point. Thanks

Ignore. Working code in post further below.

Something along these lines should work:


[enlist<var-with-places>] :map:flat[tag[event]contains:place<currentTiddler>] :and[unique[]sort[date]]
1 Like

Apologies, my eyesight is brutal today, and I had to go to my personal TW instance to see what the heck I’m coding.

\define fs() [tag[event]contains:place[
\define fe() ]]

<$let v="[[Upper Canada]] Ontario [[Canada West]]"
          s={{{ [enlist:<v>] +[addprefix<fs>] +[addsuffix<fe>]  +[join[]] }}}>

the solution filter: <<s>>

<$list filter="[subfilter<s>]">
<<currentTiddler>>
</$list>

</$let>

Thank you @saqimtiaz

You have provided these :map solutions before, and you’d think I would wrap my head around them. However, based on my limited experience I think you mean:

[enlist<placeList>] :map:flat[all[tiddlers]tag[event]contains:place<currentTiddler>] :and[unique[]sort[date]]

This worked.

2 Likes

thanks @Charlie_Veniot I will add this to my snippets for dyanmically generating filters. In this use case, @saqimtiaz has provide a working solution without the dynamic filter. However, which solution will perform faster in long list of places?

The solutions I come up with are rarely, if ever, popular.

I usually build things in a way that allows incremental/iterative testing of the “bits”, and I do like to make the bits very visible.

There are a lot of handy-dandy operators that obfuscate things too much for me to see all of the bits.

I think the great majority of folk don’t want to see all of the bits. So, if you depend on help from the community, you are much better off sticking with what the majority of folk use.

Try this:

<$let places="[[Upper Canada]] Ontario [[Canada West]]"
      events={{{ [enlist<places>] :map:flat[all[tiddlers]tag[event]contains:place<currentTiddler>]
      +[unique[]sort[date]format:titlelist[]join[ ]] }}}>

Notes:

  • The first line defines the list of places to be found
  • The second line finds all tiddlers tagged event that contain at least one of those places in their place field
  • The third line removes duplicates, sorts by date, and formats the output as a space-separated list with brackets around titles that contain spaces

-e

2 Likes