Add highlighting to a custom search type
Solr's highlighting feature lets you include fragments in the highlighting section of a query response.
You can add highlights to a custom search type by first enabling highlighting on a specific field, then adding the Highlights type property to the custom search type.
To add highlights:
-
In the
<SOLR_DIR>\server\solr\<SOLR_CORE_NAME>\conffolder, in themanaged-schemafile, enable highlighting for the desired fields by setting thestoredproperty of the fields totrue, as shown in the following example: -
Create a custom search type class and add public properties that return the
Highlightstype, then map each property to its appropriate index field, as shown in the following example: -
Use the custom search type in a LINQ query. For example:
The preceding LINQ query generates the following Solr query:
q=(title_t:("Sitecore") AND text:("customer experience")) ... &hl=true&hl.fl=textThe
highlightSegmentsproperty contains the following segment:
Highlight multiple fields in a LINQ query
Highlight multiple fields in a LINQ query
You can get highlighted matches for several index fields in a single LINQ query.
The following query returns highlights for both the title and text index fields:
The preceding LINQ query generates the following Solr query: q=(title_t:("Sitecore") AND text:("customer experience")) ... &hl=true&hl.fl=title_t,text
The HighlightsInText property contains the following segment:
The HighlightsInTitle property contains the following segment: