Do you need any help with Migration?

Not Now Yes, Contact Support

You are currently browsing legacy 4.1 version of documentation. Click here to switch to the newest 4.2 version.

We can help you with migration to the latest RavenDB

Contact Us Now
see on GitHub

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.