November Happy Hour will be moved to Thursday December 5th.

How to properly define the text used in the excerpt of a unifiedSearchHit

Vote:
 

I am trying to update an episerver website so that the text shown in the excerpt comes from a specific property that is used on all page types of the site. We have a base page type called BaseRenderedPage that has a property named ListingSynopsis which is used throughout the site when rendering a list of pages (such as on a section landing page). We would like this property to be the text shown for each search result listed on the site search page. Currently we are using unified search and the text used is the Excerpt. I am aware that there is a way to ‘project’ the excerpt using the following code but it is not working as I need it to.

SearchClient.Instance.Conventions.UnifiedSearchRegistry

                    .ForInstanceOf<BaseRenderedPage>()

                    .ProjectExcerptUsing<ISearchContent>(spec =>

                        x => x.SearchTitle);

The problem I have is I can’t work out how to make the text of the excerpt the property on my base page type, the only examples I can see are to make the excerpt come from a property on the ISearchContent itself rather than from a property on the type of content that the UnifiedSearchHit points to.

Is it actually possible to do what I am trying using episerver find? The only alternative I can think of would be to try to convert each search result into an instance of BaseRenderedPage when I get the results back and then I could output the required text directly but I think this would reduce the efficiency of the code considerably.

#206453
Aug 21, 2019 15:56
Vote:
 

Hi Sam, 

If you added a property to your type similar to this:

public virtual string SearchSummary => base.ListingSynopsis;

And keeping the projection as you have it, I would expect that to work as you want. 

Explained further here, under ISearchContent:

https://world.episerver.com/documentation/developer-guides/find/NET-Client-API/searching/Unified-search/

Hope it helps. 

Paul 

#206458
Aug 21, 2019 16:52
Vote:
 

Thanks @Paul Middleton that was exactly what i was after. What's great is that if the SearchSummary property returns an empty string epi Find will fall back to the normal excerpt which is what the client wanted. perfect!

#206499
Aug 22, 2019 13:48
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.