Context Plugin

search with context

...
the widget is the following:

```
<$context term="lorem"/>
```
Which will render as:
<$context term="lorem...
Lorem ipsum dolor sit amet, consectetur adipisicing elit...
...
culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit...
...
culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit...
...
culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit...
...
culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit...
...
culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit...
...
culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit...

ContextPlugin

10 years ago

This widget looks for a word inside a tiddler and shows the result with the searched word highlighted with some of its context.

Installation

The easiest way is to just grab the plugin. It contents the basic tiddlers needed. Just drag and drop the following link into your own wiki:

$:/plugins/danielo515/ContextPlugin

Usage

After installing the plugin you will have a new tab in $:/AdvancedSearch called Context Search. If you want this functionality in other places you will have to edit the desired tiddler yourself adding the context widget. For more details about using the widget see the section below.

Using the widget

The very basic usage of the widget is the following:

<$context term="lorem"/>

Which will render as:

...
the widget is the following:

```
<$context term="lorem"/>
```
Which will render as:
<$context term="lorem...

The widgets will search inside the current tiddler by default. Because that you see the same content twice here. This example is not very useful. Other more meaningful would be:

<$list filter="[search{$:/temp/advancedsearch}sort[title]limit[250]]">
{{!!title||$:/core/ui/ListItemTemplate}}
<$context term={{$:/temp/advancedsearch}}/>
</$list>

That will search for tiddlers containing the text specified in $:/temp/advancedsearch and will display a link to the matching tiddlers plus a preview of the matching content. Something very similar is used in Context Search. Below you can find a complete list of parameters and their default values.

parameter descriptiondefault
termThe term you want to search
searchTermAn alias for the previous one
tiddlerThe tiddler's name to look intocurrent tiddler
lengthNumber of context characters to show50
beforeNumber of characters before the matched term to showthe value of the length parameter
afterNumber of characters after the matched term to showthe value of the length parameter
maxMatchesmaximun number of matched elements to show. Incrementing this can cause several performance issues10
elementNode element to create. This element will contain the results of the search. If you want to style it its class is tw-context<pre>
matchClassThe css class to assign to the matched terms in the results. This is used to highlight the resultsmatched

Customizing the output

There are not many ways to customize the output of this widget. You can specify what type of node you want to create to wrap the results (div,span...). The default is <pre>. This container is created with the class tw-context so you can easily apply styles to it. Something similar happens to the highlighted words. You can specify the name of the class to assign to it and also you can apply styles to that class.

A very basic example of customization could be:

  1. Create a tiddler, for example $/plugins/danielo515/context/css
  2. Paste the following text or any css rule you want:
    .matched{background-color:yellow}
    .tw-context {
      border:1px solid blue;
      word-break: break-all; word-wrap: break-word;}
    

  3. Tag it with $:/tags/stylesheet
  4. Save the tiddler

Live example

Here is a transclusion of Context Search so you can see the plugin in action:

Search for standard tiddlers

Lore

10 years ago

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.