November Happy Hour will be moved to Thursday December 5th.

Get best bet hits only

Vote:
 

var bestBetsResults = SearchClient.Instance.UnifiedSearchFor(queryParam, Language.Swedish).ApplyBestBets().GetResult();

Is it possible to have something like that but ONLY get best bet hits added from Find admin?

#63687
Nov 26, 2012 17:52
Vote:
 

I don't think there's super easy way to do that. However, best bets are stored in the DDS meaning that you can retrieve them and then do pretty much anything you like. Some pseduoish code:

using EPiServer.Find.Framework.BestBets;

var queryParam = "Banana";

var repo = new BestBetRepository();
var allBestBets = repo.List();
//Only checking phrase here, you may also want to check site and language
var matching = allBestBets.Where(x => x.PhraseCriterion.Match(queryParam);



    

The matching variable now contains relevant best bets. Using these you could either figure out the ID of matching pages and files, for instance:

var pageLinks = matching
  .Select(x => x.BestBetSelector).OfType<PageBestBetSelector>()
  .Select(x => x.PageLink);

    

Or, you could use them to do pretty much what you described above (again pseudoish):

 

var filter = SearchClient.Instance.BuildFilter<ISearchContent>();

foreach(var selector in matching.Select(x => x.BestBetSelector))
{
  filter = filter.Or(selector.GetTargetSelectionFilter());
}

SearchClient.Instance.UnifiedSearchFor(queryParam, Language.Swedish).
.Filter(x => filter)
.GetResult();

    

#63688
Edited, Nov 26, 2012 18:16
Vote:
 

Thanks! I can work with that...

For this search page I'm building best bets should be listed completly separate from the other results.

We can live with them being the first hits of the normal result list but I'd still need to identify them for separate styling.

Because UnifiedSearchHit doesn't have a IsBestBet bool property or similiar not-having-to-visit-the-DDS-store-myself-way right?

#63690
Nov 26, 2012 23:55
Vote:
 

Yeah. The way best bets work in Find they are applied at query time. This means that it's optional to use them (for instance you may not want them in editorial search) and they are applied instantly. However, it also means that the search engine doesn't know about them. What you could in theory do is inspect the score for each hit. If the first hit(s) have significantly higher score it may be safe to assume that it's a best bet.

Alternatively you could figure out what pages are best bets using something like the first two code snippets above and then when you get the result back compare each hit to those pages.

#63698
Nov 27, 2012 9:56
Vote:
 

Alternatively you could figure out what pages are best bets using something like the first two code snippets above and then when you get the result back compare each hit to those pages.

OK, thanks for the info! I have something like that in play now.

#63699
Nov 27, 2012 10:01
Vote:
 

Sample code for IsBestBets will be helpful

#154285
Edited, Aug 29, 2016 22:33
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.