How to create a filter using variables set using set widet

Here, I am trying to create a filter builder to open those tiddlers in the storyriver (similar to this implementation by @jonnie45 )

<$vars tid-limit={{{ [[$:/state/limit]is[tiddler]then{$:/state/limit}else[10]] }}} stype={{{ [[$:/state/stype]is[tiddler]then{$:/state/stype}else['created']] }}}>
<$set name=filter-step-1 filter="[<currentTiddler>{!!filter-step-value-1}]">
<$set name=filter-step-2 filter="[<currentTiddler>{!!filter-step-value-2}]">
<$set name=filter-step-3 filter="[<currentTiddler>{!!filter-step-value-3}]">
<$set name=filter-steps-combined filter="[all[tiddlers]note<filter-step-1>sub-rad<filter-step-2>limit<tid-limit>]">

This code is working. But I want to modify it for more general usage.
Currently in the filter for filter-steps-combined set widget, sub-rad is hard-coded. I want sub-rad to be replaced by something like sub-<filter-step-1> because it depends on the value of <filter-step-1>
When value of <filter-step-1> is rad, my code works. But if value of <filter-step-1> is tw, I have to change it to sub-tw.
How to to this ?

Can someone give some suggestions …I don’t want a complete solution, just some suggestions will do…so that I can try them out. I am running out of ideas now

@arunnbabu81 I think your question is hard to follow and dependant on contenty outside the code

First lets make this more readable

<$vars tid-limit={{{ [[$:/state/limit]is[tiddler]then{$:/state/limit}else[10]] }}}
            stype={{{ [[$:/state/stype]is[tiddler]then{$:/state/stype}else['created']] }}}>
   <$set name=filter-step-1 filter="[<currentTiddler>{!!filter-step-value-1}]">
   <$set name=filter-step-2 filter="[<currentTiddler>{!!filter-step-value-2}]">
   <$set name=filter-step-3 filter="[<currentTiddler>{!!filter-step-value-3}]">
   <$set name=filter-steps-combined 
         filter="[all[tiddlers]note<filter-step-1>sub-rad<filter-step-2>limit<tid-limit>]">


</$set></$set></$set></$set>
</$vars>

Notes;

  • what do you intend here else['created']?
  • These seem redundant [<currentTiddler>{!!filter-step-value-1}] as [{!!filter-step-value-1}] should be sufficient.

I think you should present a minimal question with working example, on tiddlywiki.com for your example;

My point is you are making it hard work to help you, if you put in the effort to build a minimal example you will;

  • Possibly find the answer yourself
  • Make it easier for us to help you without all your specific use case flotsam.

example tiddler is already given in the OP

You may be familiar with the wiki, the problem, but when I look there is a large cognitive overhead just to workout what the question is, let alone consider the answer. So don’t expect many answers.

  • Your short reply indicates you have not read my reply, because you reply telling me something I already know, and ignore all my suggestions.
  • You can ignore my advice but don’t be surprised if people ignore your questions.
  • We are all volunteers here and fixing your wiki is harder and less useful to others than it would be to provide a clear answer based on a clear question, that a general audience can make use of.
    • and solves your problem.

Because it was 4 am here when i replied …i replied when I woke up in between my sleep…

I guess it’s better I delete this question. Sorry for trouble.

If anyone has the power to delete this question, please do.

Ask it when you are ready

I think your question is clear enough - just.

Perhaps you could use value= instead of filter= in your $set widgets (or use $let). That way, you’re just building strings which are not evaluated until you use them as filters. Then you can build the subfilters as strings. And then you can pass the correct combined string to wherever you need to use it as a filter.

Just my thoughs…

2 Likes

Here is a simple wiki showing only the filter builder which is used to populate the storyriver.
This is the demo wiki and this is the tiddler involved

I want to populate the storyriver with tiddlers based on a filter created using multiple select widgets and set widgets. Select widget is used to assign certain field values…these field values are used to assign variables using set widget…I want to combine these variable into a final filter run filter-steps-combined

I guess the issue is at the <<filter-step-2>> which is not giving the correct results.

Actually {{{ [sub-tw[filter-operators]] }}} returns addprefix-operator and addsuffix-operator. But the <<filter-step-2>> is returning filter-operators

If that variable corrected, the final filter <<filter-steps-combined>> will also work I guess.

What do you expect this to do?, I can’t find sub-tw any where else?

To me this [sub-tw[filter-operators]] reads as if the field sub-tw has the value “filter-operators” and is a logical test. so will not change the the input, which is implied as all[]

sub-tw comes from filter-step-2-operator

<$set name=filter-step-2-operator filter="[<currentTiddler>get[filter-step-1-parameter-value]addprefix[sub-]]">

In my example, <<filter-step-2-operator>> returns sub-tw

image

image

I want to create [sub-tw[filter-operators]] using the variables - <<filter-step-2-operator>> and <<filter-step-2-parameter>>

That’s what I tried here using filter-step-2

<$set name=filter-step-2 filter="[<filter-step-2-operator><filter-step-2-parameter>]">

But it’s returning the wrong result of filter-operators

image

image

Where as it is supposed to return addprefix-operator and addsuffix-operator.

image

That’s why I am assuming that if filter-step-2 is fixed, the final-filter may also be fixed. Just my assumptions.

all[] was actually not there, I tried may combinations to get some result. In that process all[] came. I forgot to remove it before saving the tiddlyhost wiki.

All is implied if it’s there or not in a default filter.

If I look at the Topic;

How to create a filter using variables set using set widet

Is it fair for me to say you want to combine filters stored in some variables/fields? My error. Now variables provided

If so you should be able to do this in the last step;

filter="[subfilter<var1>subfilter<var1>subfilter<var1>]"
  • This assumes those filters are validly constructed.
  • You can also do things like
    • [subfilter<var1>] -[subfilter<var2>]
filter="[subfilter{!!field1}subfilter{!!field2}subfilter{!!field3}]"
  • This assumes those filters are validly constructed.
  • You can also do things like
    • [subfilter{!!field1}] -[subfilter{!!field2}]

However I now use functions and custom operators a lot.

Otherwise, I still don’t follow but I will revisit later.

ya, this is almost correct.

but the issue here lies in this part which I mentioned in the previous post I guess

OK I think I am starting to get it;

You have an operator in var1 and a parameter for that operator in var2 so that when combined you end up with a “string”, to be later used as a filter that look like this [var1[var2]] where the var(s) are replaced with their value?

Is this correct? If so I think I have a solution.

Here is a simplified example;

<$let op=tag param=TableOfContents filter=`[$(op)$[$(param)$]]`>

<$text text=<<filter>>/>

<$list filter=<<filter>> >

</$list>

</$let>

I use the backtick attributes to substitute the operator name and parameter. op and param rather than var1 and var2.

1 Like

Yes, thats correct. But I will have 2 or 3 strings like this to be used in the final filter.

I will study this code and try to implement it. I will return back after testing. Thank you @TW_Tones

Good.

If you dont want to build the whole combined filter in a single back tick attribute you can use a few and put them together with the subfilter operator.

There are other ways to join filters using functions so if you give some simple examples we may be able to explore these.

Thank you @TW_Tones It works now. I need to modify it a little more. But the basic framework is working now.

Here is the demo - My TiddlyWiki — a non-linear personal web notebook

<div class="" style="margin-top:0px;background:<<color code-background>>;">
<$vars tid-limit={{{ [[$:/state/limit]is[tiddler]then{$:/state/limit}else[10]] }}} stype={{{ [[$:/state/stype]is[tiddler]then{$:/state/stype}else['created']] }}}>
<$let op1=note  param1={{!!filter-step-1-parameter-value}} op2={{{ [<currentTiddler>get[filter-step-1-parameter-value]addprefix[sub-]] }}} param2={{!!filter-step-2-parameter-value}}  filter-steps-combined=`[$(op1)$[$(param1)$]$(op2)$[$(param2)$]]`>
<table class="styled-table-flex" style="border: none;"><tr>
<td>
<$select field='filter-step-1-parameter-value' default='rad'>
<$list filter=[all[tiddlers]tag[note]get[title]]>
<option value=<<currentTiddler>>><$view field='caption'/></option>
</$list> 
</$select>   &nbsp; 
</td>
<td>
<$select field='filter-step-2-parameter-value' default='gu-rad'>
<$list filter="[all[tiddlers]tag<param1>get[title]]">
<option value=<<currentTiddler>>><$view field='caption'/></option>
</$list> 
</$select>  &nbsp;
</td>
<td>
<$range tiddler="$:/state/limit" min="10" max="400" default="10" increment="5"/>
</td>
<td>
<$macrocall $name="tag-pill" tag=<<param2>> element-tag="$button" actions="""<$wikify name="filteredList" text="<$list filter=<<filter-steps-combined>> ><$text text='[['/><$text text={{!!title}}/><$text text=']] '/></$list>"><$action-setfield $tiddler="$:/StoryList" list=<<filteredList>>/></$wikify>"""/>
</td>
</tr>
</table>
<div>


1 Like