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

HitSpecification - Logic used for constructing the excerpt text

Vote:
 

Im a little confused about how the HitSpecification chooses which properties to use for building the excerpt text for a result.

I have created a custom projection for the excerpt text from for the pages on my site:

            SearchClient.Instance.Conventions.UnifiedSearchRegistry
                .ForInstanceOf<SitePageBase>()
                .ProjectExcerptUsing<SitePageBase>(spec =>
                            x => x.TeaserText);

This correctly displays teaser text when available on the page, however it seems when the teaser text is not long enough to fill the ExcerptLength defined on the HitSpecification, it will get text from other properties on the page to makeup the length.

I would like to either:

  1. Insutrct the HitSpecification to not use any other properties other than the one defined in the projection (even if it falls short in length)
  2. or.. Define the fallback properties to use in the event the teaser text falls short? (i.e MainBody)

 

 

 

#72445
Jun 17, 2013 16:27
Vote:
 

Your snippet looks correct and should work as expected (your excerpt should only contain TeserText). I've not been able to recreate the issue. Can you post the exact query you are performing? 

#72522
Jun 19, 2013 14:17
Vote:
 

Hi, 

If you check the EPiServer.Find.UnifiedSearch.HitProjection.GetProjection method, you will  see the logic used when getting Excerpt text like below:

 Expression expression2 = hitSpecification.HighlightExcerpt ? HitProjection.ReplaceParameter(this.HighlightedExcerptProjection(hitSpecification), newParameter).Body : HitProjection.ReplaceParameter(this.ExcerptProjection(hitSpecification), newParameter).Body;
 MemberAssignment memberAssignment2 = Expression.Bind((MemberInfo) typeof (UnifiedSearchHit).GetProperty("Excerpt"), expression2);

So you can choose one of below ways to make your customization works:

  1. Override HitSpecification with HighlightExcerpt as true (see more here https://world.optimizely.com/documentation/developer-guides/search-navigation/NET-Client-API/searching/Unified-search/customizing-default-projections/)
  2. Add the customization for ProjectHighlightedExcerptUsing  as below
  SearchClient.Instance.Conventions.UnifiedSearchRegistry
                .ForInstanceOf<CorporateContentPage>()
                .ProjectExcerptUsing<CorporateContentPage>(spec => x => x.TeaserText);
 SearchClient.Instance.Conventions.UnifiedSearchRegistry
                .ForInstanceOf<CorporateContentPage>()
                .ProjectHighlightedExcerptUsing<CorporateContentPage>(spec => x => x.TeaserText);

Hope it helps :)

#274670
Edited, Feb 28, 2022 4:51
* 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.