Răspuns How to get query suggestions?

  • Monday, August 22, 2011 10:55 AM
     
     

    Hello everyone,

    is there a way to get all the available search suggestions via c# code? I know there are many tutorials how to do this in PowerShell. But I want to get and set them via Code. Is that possible?

    Thanks!
    Regards
    Christian

All Replies

  • Wednesday, August 24, 2011 3:13 AM
     
     Answered Has Code

    The query suggestions that show up in the search box as the user types in his query can be obtained through code using the SearchServiceApplicationProxy.GetQuerySuggestions method. It only retrieves available suggestions based on the QueryText property of the QueryProperties.

    http://msdn.microsoft.com/en-us/library/microsoft.office.server.search.administration.searchserviceapplicationproxy.getquerysuggestions.aspx

    The code below is an example:

     public static StringCollection GetQuerySuggestions()
     {
    
          StringCollection sc = null;
    
          SPServiceContext context =
            SPServiceContext.GetContext(SPServiceApplicationProxyGroup.Default,
            SPSiteSubscriptionIdentifier.Default);
    
          SearchServiceApplicationProxy ssap =
              context.GetDefaultProxy(typeof(SearchServiceApplicationProxy))
              as SearchServiceApplicationProxy;
    
    
          QueryProperties qp = new KeywordQueryProperties();
          qp.QueryText = "doc";
    
          sc = ssap.GetQuerySuggestions(qp, 8, true, true, true);
          return sc;
    
    }
    

     

     


    Blog | SharePoint Field Notes Dev Tool | ClassMaster
  • Thursday, May 10, 2012 7:05 PM
     
     

    Hi,

     How to use this method in KeyWordQuery ?

    Thanx.