Sitecore SOLR results with highlights

724 Views Asked by At

(my ultimate goal is to have my search results page much like Google - facets, categories, synonyms, spelling corrections, and highlighting - but I'm working on highlighting first)

I followed the instructions on How to Highlight Search Terms Using ContentSearch in Sitecore With Solr to get results, but I'm not sure what to do with the results. The code example looks like:

using (var context = index.CreateSearchContext(SearchSecurityOptions.DisableSecurityCheck))
{
    var result = context.GetExtendedQueryable<SearchResultItem>().Where(it => it["content_t"] == "panda").GetResultsWithHighlights("content_t", "title_t");
    var highlights = result.Highlights;
}

When I run the commands in SOLR, I see the response contains a <result> element, having a number of <doc> elements, but the highlighted texts are separate and in a <lst name="highlighting"> element. This also seems to be true on on the C# side - result has both result.Results and result.Highlights.

The result.Highlights only contains highlighted fragments, and does not contain fields that are not matched. The search results page should list the title_t (highlighting the search string if it exists), and below the title, the content_t fragment (highlighting the search string if it exists). If content_t doesn't have a relevant fragment, then I want to pull the Description field from the Sitecore item. How do I "tie" the result.Results with the result.Highlights with the Sitecore item to achieve the display?

0

There are 0 best solutions below