Typed Search and Best Bets - Example?

Vote:
 

Hi!

I have code somewhat similar to the following:

var result = _searchClient.Search(Language.Swedish)
    .For(query)
    .WithAndAsDefaultOperator()
    .UsingSynonyms()
    .ExcludeDeleted()
    .FilterForVisitor()
    .ApplyBestBets()
    .Track()
    .Filter(x => x.Ancestors().In(searchNodeIds))
    .Skip(firstHit)
    .Take(10)
    .Select(x => searchResultFactory.Create(x))
    .IncludeType(x))
    .IncludeType(x))
    .GetResult();

As you can see I've added ApplyBestBets. However, after reading the documentation (https://world.episerver.com/documentation/developer-guides/find/NET-Client-API/searching/Best-Bets/) 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!

EPiServer 10.10.4.0
Find 12.6.2.0
Searching CMS-content and some content pulled from outside the CMS

#196402
Aug 29, 2018 15:22
Vote:
 

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)

#196404
Aug 29, 2018 16:42
Vote:
 

Try this:

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

#196437
Aug 30, 2018 18:44
Vote:
 

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()))
#320919
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.