Seems that when the MainIntro field is populated with html tags, both these tags and MainBody is retrieved. Why is MainBody retrieved at all? Is it a default "fallback property"?
Hi,
By "default" all properties marked as Searchable in the page definition is included in SearchText that in turn is a "fallback" property. If you only want SearchSummary in the Excerpt you can override the defult Excerpt projection by:
client.Conventions.UnifiedSearchRegistry.ForInstanceOf<MyBasePageType>()
.ProjectExcerptUsing<ISearchContent>(spec =>
x => x.SearchText.AsCropped(spec.ExcerptLength));
If you are using Highlighting you have to override the HighlightExcerpt by:
client.Conventions.UnifiedSearchRegistry.ForInstanceOf<MyBasePageType>()
.ProjectHighlightedExcerptUsing<ISearchContent>(spec =>
x => x.SearchSummary.AsHighlighted(
new HighlightSpec { FragmentSize = spec.ExcerptLength, NumberOfFragments = 1 }));
Regards,
Henrik
How would this work with the singleton?
I don't get intelliSense for the .ProjectExcerptUsing method in my indexing convention class.
Swap client to SearchClient.Instance and add EPiServer.Find.UnifiedSearch to your usings.
I first tried this without any luck:
SearchClient.Instance.Conventions.UnifiedSearchRegistry.ForInstanceOf<PageType_BasePage>()
.ProjectHighlightedExcerptUsing<ISearchContent>(spec => x => x.SearchSummary.AsHighlighted(new HighlightSpec { FragmentSize = spec.ExcerptLength, NumberOfFragments = 1 }));
Here is the result from the search on a specifici test article, using the code above. Properties in order are title, heading, intro, body. As you can see the intro is just an empty <strong> tag. As soon as I populate the tag with something, the intro alone is returned in the result.
Since I haven't actually implement ISearchContent but rather declared the properties with the same name and type I tried the following, also without any luck:
SearchClient.Instance.Conventions.UnifiedSearchRegistry.ForInstanceOf<PageType_BasePage>()
.ProjectHighlightedExcerptUsing<PageType_BasePage>(spec => x => x.SearchSummary.AsHighlighted(new HighlightSpec { FragmentSize = spec.ExcerptLength, NumberOfFragments = 1 }));
This is not really a big showstopper though, as I can just filter out the html tags before displaying the result.
As you have edited Highlighting excerpts are you passing the HitsSpecification to GetResult?
.GetResult(new HitSpecification { HighlightExcerpt = true })
and that you are using the .For(querystring) so that it has something to highlight on?
No, I hadn't passed the HitsSpec, but I've done so now and it looks like it works.
Thanks :)
I'm using CMS 6 r2 with UnifiedSearch. I've declared the property SearchSummary in my basepage (PageType Builder 2.0).
public string SearchSummary
{
get
{
var propertyMainIntro = this.Property.ExistsLocally("MainIntro") && this["MainIntro"] != null ? this["MainIntro"].ToString() : String.Empty;
if (!String.IsNullOrWhiteSpace(propertyMainIntro))
{
return propertyMainIntro;
}
return String.Empty;
}
}
In some cases the Excerpt field on the UnifiedSearchHit object only gives me the MainIntro field, which is correct. For some of the other pages I get both the MainIntro and MainBody field. Both pagetypes inherit the basepage. There are no differences for the two page types in my indexing convention.
Any tips?