Configure highlighting in a custom search type
You can configure the highlighting in a custom search type to meet your specific requirements.
You can configure highlighting in two ways:
-
Use
presetOverrideto pass parameters in a LINQ query -
Define a preset and reference it in a LINQ query
Use presetOverride to pass parameters in a LINQ query
Use presetOverride to pass parameters in a LINQ query
To configure highlighting by passing parameters in a LINQ query:
-
Use
presetOverrideto pass parameters in the LINQ query.The preceding example changes the HTML tags that wrap the highlighted terms and generates the following Solr query:
q=(title_t:("Sitecore") AND text:("customer experience")) ... &hl=true&hl.fl=text&hl.simple.pre=<br>&hl.simple.post=</br>The
HighlightsInTextproperty contains the following segment:
Define a preset and reference it in a LINQ query
Define a preset and reference it in a LINQ query
You can also configure highlighting using configuration presets.
A preset is a set of defined highlight parameters with an associated unique name. You can define a preset with multiple highlight parameters and reuse it across your solution.
To define and reference a preset in a LINQ query:
-
Define a preset in the
sitecore>contentSearch>indexConfigurations>defaultSolrIndexConfiguration>highlightOptions>presetStore>presetsnode of your custom Sitecore configuration file.The preceding example defined a preset named
sampleand added Solr-specific parameters. -
Reference the preset in the LINQ query:
The preceding LINQ query generates the following Solr query:
q=(title_t:("Sitecore") AND text:("customer experience")) ... &hl=true&hl.fl=text&hl.snippets=1&hl.fragsize=50&hl.requireFieldMatch=true&hl.simple.pre=<span>&hl.simple.post=</span>The
HighlightsInTextproperty contains the segment: