Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
AI OnAI Off
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
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:
// Attributes ommitted for clarity public class FaqItemBlock : BlockData { public virtual string Question { get; set; } public virtual XhtmlString Answer { get; set; } public virtual ContentArea BottomContent { get; set; } }
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:
var contentQuery = _searchClient.Search<FaqItemBlock>().For(query).WithHighlight(x => x.Question); var contentResult = contentQuery.GetContentResult();
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.