SaaS CMS has officially launched! Learn more now.

Typed Search and Best Bets - Example?



I have code somewhat similar to the following:

var result = _searchClient.Search(Language.Swedish)
    .Filter(x => x.Ancestors().In(searchNodeIds))
    .Select(x => searchResultFactory.Create(x))

As you can see I've added ApplyBestBets. However, after reading the documentation ( I'm somewhat confused as to how I can get typed search to play well with Best Bets.

Can someone provide an example on how to work with Best Bets for typed search? Is it even possible or do I have use UnifiedSearch?

Any help would be appreciated!

Searching CMS-content and some content pulled from outside the CMS

Aug 29, 2018 15:22

I figured out that I had to add the following:

.IncludeType<ISearchResult, ExternalUrlBestBet>(x => searchResultFactory.Create(x, new BestBetRepository()))

Unfortunately I'm now stuck with another problem:

Unhandled exception in ASP.NET
EPiServer.Find.ProjectionException: An exception of type JsonSerializationException was thrown while deserializing object. ---> Newtonsoft.Json.JsonSerializationException: Error setting value to 'IsPendingPublish' on 'XYZ'. ---> EPiServer.Core.EPiServerException: Property 'PagePendingPublish' does not exist, can only assign values to existing properties
vid EPiServer.Core.ContentData.SetValue(String index, Object value)
vid Newtonsoft.Json.Serialization.DynamicValueProvider.SetValue(Object target, Object value)

Aug 29, 2018 16:42

Try this:

Use SearchClient.Instance instead of Client.CreateFromConfig() if you using it and use GetContentResult() instead of GetResult()?

Aug 30, 2018 18:44

Old topic, but I think it is worth sharing.

You need to specify which properties you would like to fetch from the search engine in the projection.

.IncludeType<ISearchResult, ExternalUrlBestBet>(x => searchResultFactory.Create(x.Id, new BestBetRepository()))
Apr 23, 2024 11:55
* 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.