Hi guys, just realized nobody replied on this post. Does anybody know a fix for this issue?
Hi Senura,
I believe you'll need to use UnifiedSearch. Once you're using that, the results will be of the type 'UnifiedSearchHit' and then the document on them will have the Title and Excerpt automatically.
i.e.
var unifiedSearch = _client.UnifiedSearch()
.For(query)
.ApplyBestBets()
.GetResult();
var excerpt = unifiedSearch.Hits.First().Document.Excerpt;
var title = unifiedSearch.Hits.First().Document.Title;
Cheers,
- JJ
@James Johnson, I appreciate your answer. However, isn't there a way to get the best bet title and excerpt using the ITypeSearch (Typed Search) ? Because the current search implementation is heavily configured with the ITypeSearch and moving to UnifiedSearch is not worth.
I am wondering why Episerver documentation has stated we could apply best bets to the typed search. What's the purpose of mentioning that in the documentation if we could not get the title and excerpt using the Typed Search ?
Hi Senura,
You can apply the best bets to typed searches but as far as I'm aware, the results are more or less bundled in together, versus the unified search which has more data on if the result is a best bet or not.
Given the lack of other responses, you might be better off submitting a support ticket to support@episerver.com to try and find out directly from them if it is possible or not...?
Should it not be available for typed search, I think you'd need to do something like querying the 'BestBetRepository' and finding the one(s) that match your query phrase, then grabbing the Title and Excerpt from there.
Cheers.
- JJ
Hi All,
I have exactly the same problem to solve. Did anyone find a solution to this?
Regards,
Paul
Hi,
As far as the ApplyBestBets method goes, it is simply responsible for applying a relevancy boosting in the search algorithm where a Best Bet phrase matches a content instance.
Best Bet data is not indexed against products so is not returned in a typed search.
The Best Bets Title and Description defined in edit mode are for the benefit of editors.
However your requirement is possible - just not out of the box so you need to be creative.
There is a BestBetsController that wraps the Find Rest API
Here's some code to get you started on a repository class that wraps the BestBetsController
public class EpiFindBestBetRepository : IEpiFindBestBetRepository
{
private readonly BestBetsController _bestBetsController;
public EpiFindBestBetRepository()
{
_bestBetsController = new BestBetsController
{
Request = new HttpRequestMessage(),
Configuration = new HttpConfiguration()
};
}
public bool Delete(string id)
{
var responseMessage = _bestBetsController.Delete(id);
return responseMessage.IsSuccessStatusCode;
}
public int DeleteAll()
{
var responseMessage = _bestBetsController.GetList();
var allBestBets = DeserializeResponse<BestBetsModel>(responseMessage).Hits;
int itemsRemoved = allBestBets.Select(x => Delete(x.Id)).Count(y => y);
return itemsRemoved;
}
public BestBetsModel Get(string id)
{
var responseMessage = _bestBetsController.Get(id);
var bestBetModel = DeserializeResponse<BestBetsModel>(responseMessage);
return bestBetModel;
}
public List<BestBetModel> List()
{
var responseMessage = _bestBetsController.GetList();
var result = DeserializeResponse<BestBetsModel>(responseMessage).Hits;
return result;
}
public List<BestBetModel> List(string siteId, string language, int from, int size)
{
var responseMessage = _bestBetsController.GetList($"siteid:{siteId}", from, size);
var result = DeserializeResponse<BestBetsModel>(responseMessage).Hits;
return result;
}
public bool Add(BestBetModel bestBetModel)
{
var responseMessage = _bestBetsController.Post(bestBetModel);
return responseMessage.IsSuccessStatusCode;
}
private T DeserializeResponse<T>(HttpResponseMessage responseMessage)
{
var responseContentAsync = responseMessage.Content.ReadAsStringAsync();
string response = responseContentAsync.Result;
T httpResponse;
using (var reader = new StringReader(response))
{
var jsonReader = new JsonTextReader(reader);
httpResponse = Serializer.CreateDefault().Deserialize<T>(jsonReader);
}
return httpResponse;
}
}
You'll need to
var result = client.Search<SamplePage>(GetLanguage(LanguageID))
.For(Query, SearchHelper.QueryStringQueryAction)
.Select(x => new SearchResult
{
Title = x.SamplePageTitle,
Description = x.SamplePageDescription ,
BestBetTitle = x.BestBetTitle(),
BestBetDescription = x.BestBetDescription()
})
.ApplyBestBets()
.Take(PageSize).GetResult();
I have applied best bets to the Typed search as the Episerver developer documentation stated it. Is there a way to get the Best bet Title and the Excerpt (which are defined in the best bet edit mode in Epi Admin).
My implementation as of now,
As I have mentioned above, is there a way to get the Title and Excerpt?
Thanks.