---
title: "Configure highlighting in a custom search type"
slug: "configure-highlighting-in-a-custom-search-type"
abstract: "Describes how to configure highlighting in a custom search type."
---
# Configure highlighting in a custom search type

You can configure the [highlighting in a custom search type](https://doc.sitecore.com/xp/en/developers/103/platform-administration-and-architecture/add-highlighting-to-a-custom-search-type.html "Add highlighting to a custom search type") to meet your specific requirements.

You can configure highlighting in two ways:

- Use `presetOverride` to pass parameters in a LINQ query
- Define a preset and reference it in a LINQ query

<details>
<summary><h2>Use presetOverride to pass parameters in a LINQ query</h2></summary>

To configure highlighting by passing parameters in a LINQ query:

- Use `presetOverride` to pass parameters in the LINQ query.

    ```csharp
    var result = context.GetQueryable<SimpleHighlightResultItem>()
            .Where(it => it.Title == "Sitecore" && it.Text == "customer experience")
            .WithHighlights(hl => hl.HighlightOn(i => i.HighlightsInText),
                presetOverride: p =>
                {
                    p.PreTag = "<br>";
                    p.PostTag = "</br>";
                })
            .ToArray();
    ```

    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 `HighlightsInText` property contains the following segment:

    ```text
    " complexity that has previously held marketers back, the latest version of <br>Sitecore</br> makes <br>customer</br> <br>experience</br>"
    ```

</details>

<details>
<summary><h2>Define a preset and reference it in a LINQ query</h2></summary>

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:

1. Define a preset in the `sitecore` > `contentSearch` > `indexConfigurations` > `defaultSolrIndexConfiguration` > `highlightOptions` > `presetStore` > `presets` node of your custom Sitecore configuration file.

    ```xml
    <defaultSolrIndexConfiguration>
          <highlightOptions>
            <presetStore>
              <presets>
                <preset id="sample" type="Sitecore.ContentSearch.Linq.Highlighting.ConfigurationBasedHighlightsPresetStore+HighlightPreset, Sitecore.ContentSearch.Linq">
                  <param desc="name">$(id)</param>
                  <param desc="parameters" type="Sitecore.ContentSearch.Linq.Solr.Highlighting.SolrHighlightParameters, Sitecore.ContentSearch.Linq.Solr">
                    <fragSize>50</fragSize>
                    <maxSnippetsNumber>1</maxSnippetsNumber>
                    <requireFieldMatch>true</requireFieldMatch>
                    <preTag>&lt;span&gt;</preTag>
                    <postTag>&lt;/span&gt;</postTag>
                  </param>
                </preset>
              </presets>
            </presetStore>
          </highlightOptions>
    </defaultSolrIndexConfiguration>
    ```

    The preceding example defined a preset named `sample` and added Solr-specific parameters.

2. Reference the preset in the LINQ query:

    ```

    var result = context.GetQueryable<SimpleHighlightResultItem>()
            .Where(it => it.Title == "Sitecore" && it.Text == "customer experience")
            .WithHighlights(hl => hl.HighlightOn(i => i.HighlightsInText),
                preset: "sample"
            )
            .ToArray();
    ```

    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 `HighlightsInText` property contains the segment:

    ```text
    " latest version of Sitecore makes <span>customer</span> <span>experience</span>"
    ```

</details>