Highlighted excerpt is only returned if excerpt contains search phrase

Vote:
 

Highlighted excerpt is only returned if excerpt contains search phrase. If excerpt text does not contain the search phrase, nothing gets highlighted and no excerpt is returned att all.

What I need is highlighted excerpt text if excerpt text contains the search phrase, AND except text if it does not contain the search phrase. Is this a bug or am I missing something in the HitSpecification or in the find initializer?

In controller:

var hetSpec = new HitSpecification
                {
                    HighlightExcerpt = true
                };

                model.Hits = query.GetResult(hetSpec);

In EpiserverFindInitializer.cs:

SearchClient.Instance.Conventions.UnifiedSearchRegistry
                .ForInstanceOf<BasePage>()
                .ProjectExcerptUsing<BasePage>(spec => x => x.ExcerptText.AsCropped(spec.ExcerptLength));

            SearchClient.Instance.Conventions.UnifiedSearchRegistry
                           .ForInstanceOf<BasePage>()
                           .ProjectHighlightedExcerptUsing<BasePage>(spec => x => x.ExcerptText
                           .AsHighlighted(new HighlightSpec { 
                               FragmentSize = spec.ExcerptLength,
                               NumberOfFragments = 1,
                               PreTag = "<strong>",
                               PostTag = "</strong>"
                           }));

In BasePage:

public virtual string ExcerptText
        {
            get
            {
                if (MetaDescription.IsNotNullOrEmpty())
                {
                    var meta = HttpUtility.HtmlDecode(MetaDescription);
                    return meta;
                }
                    

                if(HeroArea != null && HeroArea.Items.Any() && UseNewHero)
                {
                    IContentRepository ContentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();
                    if (ContentRepository.TryGet(HeroArea.Items.First().ContentLink, this.Language, out HeroBlockBase heroBlockBase))
                    {
                        if (heroBlockBase.IntroText != null && !heroBlockBase.IntroText.IsEmpty)
                        {
                            var intro = StringHelpers.RemovePTag(heroBlockBase.IntroText).ToString();
                            return intro;
                        }
                    }
                }
                return string.Empty;
            }
        }
#280048
May 09, 2022 11:06
Vote:
 

Try reducing the boosting weight of the excerpt text. Do it in the admin section before doing it in code to test out the results.

#280214
May 12, 2022 3:00
Vote:
 

Hi and thank you for your answer.

I lowered the boosting weight for search summary to 0 and there was no change.

The hits (the UnifiedSearchHit objects) themselves are returned, but it is the Excerpt property that is not returned if Excerpt does not contain the search phrase.

Isn't boosting for determining which hits should be showing first depending on certain configurations, but how can boosting be used to show or not show excerpt text?

#280226
Edited, May 12, 2022 12:01
Vote:
 

You need to inform the UnifiedSearchRegistry which content types fields in your solution you want to map to the fields that Unified Search understands.

Take a look at ISearchContent. You'll see a list of fields that UnifiedSearch uses.

You can project a custom field to the Title..exactly like you've done with the Excerpt; or you can implement ISearchContent.SummaryTitle against your content types definitions.

Once you've done that, you'll find when the search hits in the ISearchContent.SummaryTitle field...the Excerpt will also get returned in the results whether it has the search term or not.

#280273
Edited, May 13, 2022 0:27
* 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.