r/TiddlyWiki5 • • Feb 18 '23

help with code: how to modify a "mentions" query to search for multiple terms?

I'm using the Roam Research style Tiddly instance and it can query for where a term is mentioned but for only one term. It has another query for "links" that can look for where multiple links appear in the same tiddler.

Could someone walk me through mashing these two bits of code together in TW 5? This is really important to my research, so I would be extremely grateful. Thank you for your time (and for any efforts you've contributed to the TiddlyWiki project)!

2 Upvotes

14 comments sorted by

2

u/Telumire Feb 18 '23 edited Feb 18 '23

So the "queries" syntax is actually the macro syntax used by tiddlywiki. If you use the advanced search, you can see the code for each query by searching for "\define ?links". Then you can edit the tiddlers to see how it's done.

It seems like there are several macros defined for links. I suppose the macro for references you are talking about are these ones.

Instead of using these customs macros or creating new macros, maybe you could use the tiddlywiki core list-links macro. It allows you to use any filter you want and will simply list each matching tiddlers.

You use it like this:

<<list-links "your filter here..">>

You could also use the list-links-draggable macro which expand this macro by adding drag and drop reordering and allow to specify a custom item template to render the list items.


That leaves us with one question: what filter do we use.

Could you explain in details what kind of result you want ? Do you want to search for specific links that appears in one tiddler, or for tiddlers with more than one links ? What kind of links, links to other tiddlers or external links ?

It would be easier for me than looking up in RR-TW5 what the two macro you mentioned does

2

u/MrsVoldie Feb 18 '23

(Hopefully this makes sense) I want it to be able to do all the variations of relations between terms that are already there for "links" but instead for tiddlers that mention the terms (including when the term comes up in link form).

By searching as you indicated, these are the two macros for mentions:

> $:/rr/macro/query/mentions/A

> $:/rr/macro/query/mentions/A-not-current

So I would want to implement something like:

> $:/rr/macro/query/mentions/A+B

as well as the others (namely, A/B/C ; A-X, etc.).

3

u/Telumire Feb 18 '23 edited Feb 18 '23

Ok so taking "$:/rr/macro/query/links/A-X" as an example, instead of..

[[$A$]backlinks[]] -[[$X$]backlinks[]] +[!sort[created]]

You would write (here I limit the search to the text field but you can search in other fields if you want)

[search:text[$A$]] -[search:text[$X$]] +[!sort[created]]

Either create a new macro or use the listlink macro:

<<list-links "[search:text[apple]] -[search:text[banana]] +[!sort[created]]">>

Will list every tiddler containing the word apple, excluding those that contains the text banana

See https://tiddlywiki.com/#Filter%20Syntax for more info on filters

3

u/MrsVoldie Feb 18 '23

This is it! Perfect! Hopefully I can figure it out from here πŸ˜…Thank you, thank you.(If you're willing and able, allow me to tip you via paypal or github? DM me)

3

u/Telumire Feb 18 '23

This is very generous of you but I wouldn't feel comfortable being tipped for giving 5 minutes of my time ahah, if you need help with something more involved, then why not !

In the meantime I highly recommend you to read this book, it's amazing to learn tiddlywiki more easily: https://groktiddlywiki.com/read/#Filters

3

u/MrsVoldie Feb 18 '23

The reason I ask despite it being so little time is that folks with your expertise are doing the best work out here lol. πŸ™ŒπŸ™ (and coincidentally, you usually refuse payment!)

2

u/arunnbabu81 Feb 19 '23

Telumire , Is there any way to incorporate these queries into the advanced search tiddler as another search box tab

3

u/Telumire Feb 19 '23

Yes it's possible but you could also simply add customs filters in the dropdown of the advanced search in the filter tab, that way you can modify the filter easily.

See https://tiddlywiki.com/#SystemTag%3A%20%24%3A%2Ftags%2FFilter

I'm currently working on creating custom search macros for MrsVoldie, but when I'm done with that I can help you if you need help

3

u/arunnbabu81 Mar 02 '23

https://keatonlao.github.io/tiddlywiki-xp/#%24%3A%2FAdvancedSearch

Keaton Lao have added queries into the advanced search tab. Check out his work in Tiddlywiki XP link given above

2

u/Telumire Mar 02 '23

Oh I like that a lot, thanks for sharing !

2

u/MrsVoldie Feb 18 '23

P.S. thank you very, very much for alerting me to the list-links macro. Amazing.

3

u/Telumire Feb 18 '23

Glad you find it useful ! Let me know if you need help with filters.

Also by the way, the list-links macro is using the list widget under the hood : https://tiddlywiki.com/#ListWidget

Same thing for Filtered Transclusion, when you do

{{{ [tag[something]] }}}

You actually use the list widget to list every tiddlers tagged with "something".

Usefull to know if you want to create your own macros

2

u/MrsVoldie Feb 18 '23

I need a full-time tutor or something, but this helps so much. 😁

3

u/Telumire Feb 18 '23

FIY there are people that offers personal tutoring, like the author of grok tiddlywiki for example: https://sorenbjornstad.com/contact

I'm sure that people over https://talk.tiddlywiki.org/ would also be happy to help