Highlight Text

Most platforms provide highlighting functionality built-in, which are handled and passed through by Appkit to the front end output. If you are using the GSA, Appkit provides features to easily highlight text through the usage of a Response processor, detailed below, which you add when creating your response tag.

Highlighting on Solr

See the Solr documentation about highlighting. By default, Solr uses <em> HTML tags for highlighting.

Highlighting on Elasticsearch

See the Elasticsearch documentation about highlighting. By default, Elasticsearch uses <em> HTML tags for highlighting.

Escaping HTML emphasis tags in output

Appkit’s <search:field> tag escapes all output by default, If you want to allow <em> HTML tag highlighting through on specific fields, use the escape="false" attribute, for example, <search:field …​ escape="false">.

Do this with care and consideration, and be sure that this source data contains no user input data for Cross Site Scripting (XSS) reasons.

Highlighting on the GSA

This provides sensible defaults out of the box, and also lets you configure highlighting on whatever fields and terms you want to use.

HighlightFieldValuesProcessor

Simple usage

By default the HighlightFieldValuesProcessor uses the query term from the response to highlight all fields.

<search:response var="response" platform="${platform}" query="${query}">
    <workflow:processor name="twigkit.search.processors.response.HighlightFieldValuesProcessor" />
</search:response>

Custom Usage

By adding the {{fields}} attribute you can specify which fields to highlight, to target specific ones only.

The {{terms}} attribute lets you specify which terms should be highlighted in the target fields.

<search:response var="response" platform="${platform}" query="${query}">
    <workflow:processor name="twigkit.search.processors.response.HighlightFieldValuesProcessor" fields="foo,bar" terms="dodecahedron"  />
</search:response>

Highlighted output

Output is in this form:

<em class="twigkit-highlighted-term">dodecahedron</em>