Search is hard. Thankfully the extreme brains working for me have donated their gray matter to develop an incredibly smart solution that will solve all your problems¹. How?
With extra filter operators of course! Coming to your house now!
¹ - No promise of actual problem solving is being made here .
As part of working on an unannounced project I wanted a search mechanism that has more functionality than you can squeeze from vanilla TW. I didn’t like the idea of shipping those with the plugin and so the idea was born to share them.
As it usually happens with my ideas, what was one simple filter turned into 4 complex filters that should cover all your searching needs together with new and exceptional documentation, unit tests guaranteeing no regressions and powerful live example.
There are four filter operators available as of now:
susearch – search that’s slightly more powerful than the good-old search; among others it can strip away wikitext to avoid false positives caused by the structure.
susearch-sort – sort the results in an intelligent way that for the most part should feel just right and natural.
susearch-mark – for highlighting the matches.
focus-on – for extracting a part of the input, specifically designed for partial previews of the matched text.
I am aware of this one but I wanted a low-cost solution that can seamlessly integrate and be multi-functional. Simple filters seemed like the best bet for me :).
I’ve seen that thread though I haven’t responded myself. I think my solution is kind of similar to what @pmario had in mind, in that most of the heavy lifting is done in the dedicated sort operator (susearch-sort) and in general it prefers fuller and earlier matches.
I’ve been playing around with your extra operators and I have some questions. I feel like I’m not using them quite correctly.
In my Kansas Railroads TW, all of my railroads are tagged with Railroads. In trying to use the focus-on operator, I entered in the filter search tab of advanced search [tag[Railroads]focus-on[Pratt]]. This should have yielded a handful of tiddlers. Instead the results list was 1836 matches which is the number of tiddlers tagged with Railroads, but the links are all showing as missing because the last character of the title is missing. (see screenshot below)
Oh dear, I’d hope the descriptions, documentation and examples would be enough to explain how to use those but I never ran them by anyone else so it appears they might not be doing their job.
Essentially the way to use those oeprators is as follows:
Start the with a list of titles you want to search through.
susearch will search through the tiddlers, removing any that don’t match the search.
Then susearch-sort will sort the results such that the more relevant the result is, the higher it appears in the list.
With this list of results you can now display them:
Use susearch-mark to add highlights – you shouldn’t do that in the original filter, because then you won’t be able to extract the original title. So you can link to <<currentTiddler>> and then use <$transclude filter={{{ [<currentTiddler>susearch-mark<query>] }}} field="title"/> to display the highlighted result.
Use focus-on if you do search in the text of the tiddler and you want to display a short preview of the relevant passage in the tiddler.
Go to the live demo, mark all three options, select “All Tiddlers” + “Search in text” and you can see all the operators in use:
susearch and susearch-sort are used to filter and sort the results
susearch-mark is used to add highlights both in the title and the preview
focus-on is used to generate the preview of the body, extracting the part of the tiddler’s text that contains the first mark + its context.
As a side note I see I broke something last minute, will fix it today!
Thanks for the tips. Got it figured out I think. One question. Does the focus-on operator only find the first occurrence in the text or will it find all?
susearch, susearch-sort and susearch-mark no longer ignore spaces when matching words (ie. sand no longer matches s and).
Fixed in 1.0.2 now!
It only finds the first occurrence. Do you have a use case for displaying more? I guess it could return each match as a separate title in the output, if you’d actually use this functionality I’ll add it to my roadmap as an optional flag.
You have hallo in the first screenshot and hello in the second, that explains the discrepancy between the results . I added the tag and it appears to be working fine, can you explain what you mean by “will not sync it”? I’ve opened both tiddlers at once and any change to either makes the same change to the other (It stores its data in the temp tiddler $:/temp/SusearchLiveExample without any qualify, so it should appear the same in both)
But that’s what susearch-mark accomplishes, it highlights all results already. I don’t recall ever seeing a tool with search that offers mini-preview of a search result also showing multiple matches for it – it’s always the first one (or any one, I am not sure). Not that there is anything wrong with upsetting the status quo, I just don’t want to do work for the sake of doing work (I say that but I am already working on one other change I need to susearch so who knows if I won’t do this one too in one go).
Just a suggestion - Is it possible to make complex queries as shown in the image using the plug in, may be in the future ? (Image is taken from an app called Remnote - selections were made just for demo purpose)
It depends. If you’re asking for “Can you make complex queries like that?” then you can do them even without this plugin, since it mostly just expands on text-search.
If you’re asking “Can you make a query builder with this plugin?” then the answer is no, it’s just a collection of filter operators. Search query builder like the one you linked sounds like an interesting challenge but it’s one that’s too far from my needs to work on it.
This way you’ll wrap the output in the link. The way you wrote it Tiddlywiki most likely interpreted it like this:
<$transclude tiddler=<$link/>
\__________/ -- The widget name
\______/ -- Set the attribute `tiddler`
\____/ -- to `<$link`
\/ -- Self-closed transclude widget