Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Dev 8 posts 79 karma points
    Jun 07, 2022 @ 13:58
    Dev
    1

    Umbraco Examine - Search result highlighting

    Hi

    How we can highlight search term if we are using IBooleanOperation.

    I tried with the below code but it won't accept IBooleanOperation only accepting Query.

    var highlightCssClassName="highlight";
            var Separator = "...";
            var MaxNumHighlights = 5;
            var _luceneVersion=Version.LUCENE_30;
            var HighlightAnalyzer = new StandardAnalyzer(_luceneVersion);
            var HighlightFormatter = new SimpleHTMLFormatter("<span class=\"" + highlightCssClassName + "\">", "</span> ");
            var scorer = new QueryScorer(luceneQuery);
            var highlighter = new Highlighter(HighlightFormatter, scorer);
    
            var tokenStream = HighlightAnalyzer.TokenStream(highlightField, new StringReader(value));
            return highlighter.GetBestFragments(tokenStream, value, MaxNumHighlights, Separator);
    

    Is there any way to achieve this?

Please Sign in or register to post replies

Write your reply to:

Draft