No highlighting of HTML content?



Is highlighting with AsHighlighted not supported on indexed content that contains HTML tags? I am getting a search hit on the content document, but the value returned from AsHighlighted is empty. If I index the field without HTML tags, the highlighting works. (I am not using unified search, I'm using typed search.)

Update: some times I get a highlighted result back, but the marking tags interfere with the HTML tags. 

Mar 19, 2019 11:26

Hi, Johan

Have you checked that your initialization of Find returns proper highlighting syntax as specified in the documentation?

I don't think there should be an issue with having a mix of html content for the indexed entries but perhaps you have not set the custom css styles for highlighting the content in your project's stylesheets?

Mar 20, 2019 15:53


Vi sågs bestämt på en lunch bredvid Consid för inte länge sen ;)

I've setup highlighting and I'm creating my projection as follows but the problem is the resulting <mark> sections seem to not heed the structure of the HTML tags:

var highlightSpec = new HighlightSpec()
    NumberOfFragments = 1,
    FragmentSize = 200,
    PreTag = "<mark>",
    PostTag = "</mark>",
var projection = search.Select(x => new
   ContentLink = x.ContentLink,
   HighlightedTitle = x.SearchTitle().AsHighlighted(highlightSpec),
   HighlightedContent = x.MyHtmlProp.AsHighlighted(highlightSpec)

The result when the marked phrase is overlapping HTML is for example:

    <li>Lorem ipsum <mark>dolor</li>
    <li>sit amet</mark> consectetur adipiscing elit</li>
Edited, Mar 25, 2019 12:18

Det stämmer ju bra :)

Check if the Pre/PostTagForAllHighlights works out better for you:

public UnifiedSearchResults Search(string query)
            var querySearch = _client.UnifiedSearchFor(query);
            var hitSpecification = new HitSpecification
                PreTagForAllHighlights = "<em class='highlight--text'>",
                PostTagForAllHighlights = "</em>",
                HighlightTitle = true,
                HighlightExcerpt = true
            var currentCulture = ContentLanguage.PreferredCulture;
            return querySearch.OverrideCurrentLanguage(currentCulture.Name).Track().ApplyBestBets().GetResult(hitSpecification);
Edited, Mar 28, 2019 13:03

Thanks but we're using typed search and not unified search. I've since solved it by just extracting the highlight fragments and delegating the actual highlighting to the client instead.

Mar 28, 2019 14:32
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.