Migration: How to Migrate Highlighting from 3.x

Highlighting functionality has been merged into RQL. Following minor and cosmetic changes have been introduced.

Namespaces

3.x
using Raven.Client;
using Raven.Client.Document;
4.0
using Raven.Client.Documents;
using Raven.Client.Documents.Queries.Highlighting;

Example I

3.x
SearchItem[] results = session
    .Query<SearchItem>("ContentSearchIndex")
    .Customize(x => x.Highlight("Text", 128, 1, out FieldHighlightings highlightings))
    .Search(x => x.Text, "raven")
    .ToArray();
4.0
List<SearchItem> results = session
    .Query<SearchItem, ContentSearchIndex>()
    .Highlight(x => x.Text, 128, 1, out Highlightings highlightings)
    .Search(x => x.Text, "raven")
    .ToList();
List<SearchItem> results = session
    .Advanced
    .DocumentQuery<SearchItem, ContentSearchIndex>()
    .Highlight(x => x.Text, 128, 1, out Highlightings highlightings)
    .Search(x => x.Text, "raven")
    .ToList();

Example II

3.x
SearchItem[] results = session
    .Query<SearchItem>("ContentSearchIndex")
    .Customize(x => x.Highlight("Text", 128, 1, out FieldHighlightings highlightings))
    .SetHighlighterTags("**", "**")
    .Search(x => x.Text, "raven")
    .ToArray();
4.0
List<SearchItem> results = session
    .Query<SearchItem, ContentSearchIndex>()
    .Highlight(x => x.Text, 128, 1, new HighlightingOptions
    {
        PreTags = new[] { "**" },
        PostTags = new[] { "**" }
    }, out Highlightings highlightings)
    .Search(x => x.Text, "raven")
    .ToList();
List<SearchItem> results = session
    .Advanced
    .DocumentQuery<SearchItem, ContentSearchIndex>()
    .Highlight(x => x.Text, 128, 1, new HighlightingOptions
    {
        PreTags = new[] { "**" },
        PostTags = new[] { "**" }
    }, out Highlightings highlightings)
    .Search(x => x.Text, "raven")
    .ToList();

Remarks

Information

You can read more about Highlighting in our dedicated Client API article or our Querying article.

Do you need any help with Migration?