Hi PMario, thanks a lot, indeed my code is inconsistent because in an attempt to give a generic example, not tied tho the specific issue, I tried to simplify it (and I ended up to over-simplify it). Lots of stuff to reply to, let's go through it point by point:
1. indeed widgets are no programming language, that's why I used the word 'environment', not 'language'; 2. regardless of the (poor) consistency of my pseudo-code (I should have better stressed out that it was such) the point at the core of my post is this: it is frustratingly difficult to output a number of text entries (filtered out from a db made of data tiddlers) excluding duplicates, and this because in TW you cannot assign to a 'variable' other than at declaration time, so you cannot incrementally append your entries to a 'list' variable for post-processing. Acknowledging that TW is not a full-featured programming language, I'm pretty much sure that it was conceived to enable users to do such kind of stuff: filter out and manipulate chunks of text; 3. filters have if-then-else logic but only to a limited scope. Filters' if-then-else statements can only output text strings; 4. filters indeed create and deal with lists, so the only place where hopefully I can do my processing is within a filter, but it is quite difficult to write a one-liner that does what I want, let me paste my true code below (I'm sure that a better developer could write a more elegant, more synthetic one merging some of the <$list> widgets together into a single one)... <$list filter=[enlist{!!keywords}] variable='keyword'> <!-- for EVERY keyword in a keywords list... --> <$list filter="[tag[dict-AR]]" variable='entry'> <!-- entries are nothing but data tiddlers ... --> <$list filter="[<entry>indexes[]]" variable='indx'> <$set name="hit" filter="[<entry>getindex<indx>split[,]trim[ ]match<keyword>]" <!-- entries' indexes store a collection (a string) of words like word1, word2, ... --> value="<$macrocall $name='astr' entry=<<entry>> />" <!-- prepare the data tiddler as a table row on a match test hit --> emptyValue="" > <<hit>> <!-- what the code actually do is output the data tiddler immediately upon a match test hit, this DOESN'T prevent outputting duplicates --> </$set> </$list> </$list> </$list> As you can see, there is no simple way to prevent outputting duplicates with the code above. It should be completely re-arranged to append 'uniquely' (greedily? I miss the exact word to say 'without duplicates') to the list of hits before outputting it. My dictionary is made up of data tiddler entries structured as below: Entry1 indx11: word1a, word1b, ... indx12: word1c, word1d, ... Entry2 indx21: word2a, word2b, ... indx22: word2c, word2d, ... ... Thanks and regards, CG On Friday, November 19, 2021 at 11:29:55 PM UTC+2 PMario wrote: > Hi, > Widgets are no programming language. ... The ` <$list ` widget is no loop. > ... It's more like a template to create text output ... > > *Filters produce lists* so `[tag[dict_entry]] ` will return a list of > tiddler titles, that are tagged ` dict_entry ` ... Tiddler titles are > unique. > > So `[tag[dict_entry]match[keyword]]` will only return 1 tiddler name: > keyword, since there can't be a second tiddler with the same name. ... So > this part of your "code" doesn't make too much sense. > > ` [tag[dict_entry]get[db_hit]match[keyword] ` would make sense, if db_hit > is a field of a tiddler. ... BUT that's probably not what you want. > > That's why I use the tiddler text as the field that contains the keyword. > Let's say we have 3 tiddlers > > ``` > title: a > text: keyword > db_hit: aa > > title: b > text: keyword > db_hit: bb > > title: c > text: no keyword > db_hit: cc > ``` > > So `[tag[dict-entry]] :filter[get[text]match[keyword]]` will return a > list: ` a b ` . So we have a list of tiddlers that match the keyword. > Now we need to read the db_hit value > > The following wikitext is probably all you need, as far as I can interpret > your "code". > > ``` > <$set name="myList" filter="[tag[dict-entry]] > :filter[get[text]match[keyword]] "> > <$set name=hitList filter="[enlist<myList>get[db_hit]addsuffix[, ]]"> > Entries matching keyword: <<hitList>> > </$set></$set> > ``` > > In TW filters are the powerful features. ... Widgets are there to create > text output with templates. Filters have match, then, else and other fancy > stuff. > > I'm not sure, if that's what you really want. .. > *You should describe your data structure first similar to what I did with > my 3 example tiddlers. * > *From your code we don't see where the `*db_hit*` value comes from.* > *We don't see, where the *`keyword ` *is defined* > > Whith that info missing it's hard to know what you really need. > > See the docs: > https://tiddlywiki.com/#tag%20Operator:%5B%5Btag%20Operator%5D%5D%20%5B%5Benlist%20Operator%5D%5D%20%5B%5Bget%20Operator%5D%5D%20%5B%5BFilter%20Expression%5D%5D%20%5B%5Bfilter%20Operator%5D%5D%20%5B%5BFilter%20Operators%5D%5D > > I hope that helps. > Mario > > -- 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 tiddlywiki+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/85f830f6-7111-42a3-a900-272096151b83n%40googlegroups.com.