none
Need to access the best bets/special term results programmatically RRS feed

  • Question

  • Hello,

     I am working in FAST Search environment. I am trying to retrieve the special term results/ best bet results programmatically with the help of KeywordQuery class and using SPS 2010 search API only.

    I wrote following code to get it done.

    DataTable retResults = new DataTable();

    SearchServiceApplicationProxy ssap =

                    (SearchServiceApplicationProxy)SearchServiceApplicationProxy.GetProxy(SPServiceContext.GetContext(SPContext.Current.Site));

     

    using (KeywordQuery query = new KeywordQuery(ssap))

    {

         query.QueryText = queryText;

         query.ResultTypes = ResultType.SpecialTermResults;

         query.ResultsProvider = SearchProvider.Default;

     

         rtc = query.Execute();

     

        if (rtc.Count > 0)

        {

     

         using (ResultTable relevantResults = rtc[ResultType.SpecialTermResults])

             retResults.Load(relevantResults, LoadOption.OverwriteChanges);

     

        }

     

     }

                   

    The code is working fine for the enterprise search but the same code is not working in case of Fast Search.

    Can anyone help me to identify what goes wrong in above code?

    Thanks.

    • Moved by Wayne Fan Wednesday, February 9, 2011 7:40 AM It's FAST Search problem, thanks. (From:SharePoint 2010 - Using Visual Studio with SharePoint and other programming)
    Monday, February 7, 2011 1:34 PM

All replies

  • Try to get your SearchServiceApplicationProxy with this code instead:

    SearchQueryAndSiteSettingsServiceProxy settingsProxy = SPFarm.Local.ServiceProxies.GetValue<SearchQueryAndSiteSettingsServiceProxy>();
    SearchServiceApplicationProxy searchProxy = settingsProxy.ApplicationProxies.GetValue<SearchServiceApplicationProxy>("FASTQuery");

    And replace FASTQuery with the name of your FAST Query SSA.

    You can also change

    query.ResultsProvider = SearchProvider.Default
    
    with
    
    query.ResultsProvider = SearchProvider.FAST
    if the FAST Query SSA is not set as the default Search SSA in your proxy group.

    Regards,
    Mikael Svenson


    Search Enthusiast - MCTS SharePoint/WCF4/ASP.Net4
    http://techmikael.blogspot.com/ - http://www.comperiosearch.com/
    Wednesday, February 16, 2011 8:06 PM
  • I tried the same, but still did not get the special term results.

    Have a doubt here,you have used "SPFarm" in the first line, but best bets are at the site collection level(please correct me if wrong), then how can we get best bets with this?

    Any particular settings to be done on server side?

    OR need to have SP site colection level context to retrieve best  bets?

    Please help!

    Thanks in advance.

    Friday, September 9, 2011 10:18 AM
  • Hi,

    I have tried all of the constructors to KeywordQuery as well as different context's, and I can't get back anything on best bets or visual best bets from FAST. Seems like a bug to me, or the solution is so quirky we can't figure it out.

    -m


    Search Enthusiast - SharePoint MVP/WCF4/ASP.Net4
    http://techmikael.blogspot.com/
    Friday, September 9, 2011 7:46 PM
  • How do we get it then?

    Is it something by FAST design?

    And I tried "DefinitionResult type" - I am not getting this result type back in result.

     

    Monday, September 12, 2011 2:11 PM
  • Hi aggrawal,

    I don't think it's by design, but a bug (or we are missing something obvious). If you can, log an issue with MS/FAST on this. As a work-around you can retrieve the visual best bets from the list, and match it to the query words manually.

    If you browse the source code of http://spsearchparts.codeplex.com and look at the file FASTSynonymReader.cs you should get started in iterating the keyword list and then you have to find which one has best bets/visual best bets attached.

    This way you can actually create a better solution where you scan for single words and not just phrases.

    Regards,
    Mikael Svenson 


    Search Enthusiast - SharePoint MVP/WCF4/ASP.Net4
    http://techmikael.blogspot.com/
    Monday, September 12, 2011 6:28 PM
  • Hi Mikael,

     

    It seems like a bug in Sharepoint Fast Search itself. I tried using OM for best Bets but no luck :( but there is not problem while fetching the relevant results.

     

    The only way, we can get the Best bets is using the Sharepoint Search web service.

     

    Hope, this will solve your problem.

    Thanks,

    Gaurav Yakhmi

    Wednesday, November 9, 2011 6:52 PM
  • I know, it's an old post, but maybe still useful for someone out there...

    I had the exact same issue until I put the following line in:

    query.UserContextGroupID = SPContext.Current.Site.ID.ToString();

    Apparently you need this context ID, regardless of whether the Best Bets are targeted or not.

    Funny detail: I was put in the right direction by a code excerpt in "Working with Microsoft FAST Search Server for SharePoint" by Mikael Svenson (also taking part in the reactions to this post). Thanks Mikael :)

    Friday, November 6, 2015 11:32 AM