Copied to clipboard

Flag this post as spam?

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


  • Bogdan 250 posts 427 karma points
    Aug 30, 2013 @ 15:40
    Bogdan
    1

    Highlight text in examine search results when matching beginning of words

    Hello,

    Based on the documentation found here http://our.umbraco.org/wiki/how-tos/how-to-highlight-text-in-examine-search-results I've implemented highlighting of the query text in the results from examine search. It all works fine, except when the query matches only the beginning of a word.

    For example if a field contains the text "Sed quis lacus mauris. Fusce auctor nunc eget neque interdum volutpat." and I search for "qui", the node will be among the results, but GetHighlight doesn't return anything. If I search for the full word "quis" it works fine.

    My implementation is a bit different from the documentation. In a Razor view:

    BaseSearchProvider externalSearcher = ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"];
        ISearchResults results = externalSearcher.Search(!String.IsNullOrEmpty(Request["query"]) ? Request["query"] : String.Empty, true);
        IndexSearcher searcher = (IndexSearcher)((SearchResults)results).LuceneSearcher;
        Query query = ((SearchResults)results).LuceneQuery;
    

    And then:

    @foreach (var result in results)
    {
        KeyValuePair<String, String> field = result.Fields.Where(f => f.Value.ToUpper().Contains(Request["query"].ToUpper()) || f.Value.ToUpper().Split(new[] { ' ' }).ContainsAny(Request["query"].ToUpper().Split(new[] { ' ' }))).FirstOrDefault();
        String searchHiglight = !String.IsNullOrEmpty(field.Key) ? LuceneHighlightHelper.Instance.GetHighlight(field.Value, field.Key, searcher, Request["query"].ToString()) : String.Empty;
    }
    

    Any ideas?

    Thanks!

  • Joel 7 posts 27 karma points
    Apr 07, 2015 @ 19:18
    Joel
    0

    Did you ever get this working correctly? I'm trying to do the same thing. What '@usings' did you need to include?

  • Bogdan 250 posts 427 karma points
    Apr 08, 2015 @ 15:12
    Bogdan
    0

    Hi Joel,

    I'm affraid this was too long ago to remember. I don't think I found a way to highlight with LuceneHighlightHelper correctly. Instead I made my own function, which just replaced all keywords with a regexp.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies