Calling all developers! We invite you to provide your input on Feature Experimentation by completing this brief survey.
Calling all developers! We invite you to provide your input on Feature Experimentation by completing this brief survey.
Hi Lasse,
Here a some examples exaplained to use highlited with multiple properties.
I think following code example should work for you.
searchResult = client.Search<BlogPost>()
.For("Bacon")
.Select(x => new { Title = x.Title.AsHighlighted(),
Content = x.Content.AsHighlighted()
})
.GetResult();
Hi Praful,
The problem with that code is that I need XhtmlString content back, but Xhtml properties are saved as html-stripped strings in the index by default.
So if I do:
searchResult = client.Search<FaqItemBlock>()
.For(query)
.Select(x => new {
Answer = x.Answer,
AnswerHighlighted = x.Answer.AsHighlighted()
})
.GetResult();
"Answer" in my result is an empty XhtmlString, and "AnswerHighlighted" has a value with highlights, but no html tags. That's why I am using GetContentResult in my original post.
I have the following block in my solution and my Find index:
I want to search for it (by free text), and get back all content, including highlights in the Question and Answer properties. I use GetContentResult for that purpose:
Now I run into problems.
1. There is a hit, but no highlight. Am I using WithHighlight wrong?
2. How do I get highlights for both Question and Answer? Can I chain WithHighlight() to include highlights for multiple properties?
By the way, I have tried to achieve the same thing using a projection query and GetResult, but I need the content to display on the result page, e.g. content area, xhtml strings, etc... So GetContentResult seemed like a better fit.