Displaying within search results not just tiddlers titles, but snippets of relevant text

Is there any plugin that enables such functionality?

If not, how could I implement it?

This one does for search results -
https://contextplugin.tiddlyspot.com/ and can be used for back links as well as seen in stroll edition of Tiddlywiki Stroll — A Roam-like experience in a free, downloadable file

2 Likes

Here’s a method that doesn’t use any plugins:

  • Start by cloning the $:/core/ui/DefaultSearchResultList tiddler.
  • Give it a new title (e.g., MySearchResults)
  • Change the caption field to something like Excerpts
  • Completely replace the text field contents with:
\define searchResultsExcerpt()
<$let before={{{ [{!!text}split{$:/temp/search}nth[1]split[]last[100]join[]] }}}
       after={{{ [{!!text}split{$:/temp/search}nth[2]split[]first[100]join[]] }}}>
<pre style="margin:0 1em;font-size:80%;line-height:1em;color:initial;white-space:normal;width:250px;">
<<before>>__{{$:/temp/search}}__<<after>>
</pre>
\end
{{$:/core/ui/DefaultSearchResultList}}
  • Then, edit the shadow tiddler $:/core/ui/ListItemTemplate
  • Change the text field contents from:
<div class="tc-menu-list-item"><$link /></div>

to

<div class="tc-menu-list-item"><$link /><<searchResultsExcerpt>></div>

You will now have an additional tab displayed in the sidebar search results. The second tab (called “Excerpts”) will show the same lists as the $:/core/ui/DefaultSearchResultList, but with the addition of an excerpt of the tiddler’s contents that shows the 100 characters immediately preceding/following the search text (which will be underlined).

enjoy,
-e

3 Likes

The Dynannotate plugin in the official plugin library provides the functionality of extracting and highlighting snippets of search results.

It can be installed via the plugin library. It is preinstalled in the prerelease and can also be explored there.

5 Likes