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
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.
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- Proposed As Answer by Jinchun ChenMicrosoft Employee, Moderator Thursday, August 25, 2011 9:29 AM
- Marked As Answer by Wayne Fan Monday, September 05, 2011 2:30 AM
-
Thursday, May 10, 2012 7:05 PM
Hi,
How to use this method in KeyWordQuery ?
Thanx.

