If you want to limit the KeywordQuery to current site only, use the HiddenConstraints property.
Following is an example:
Following is an example:
string siteName = SPContext.Current.Site.RootWeb.Title;
SearchServiceApplicationProxy proxy = (SearchServiceApplicationProxy)SearchServiceApplicationProxy.GetProxy
(SPServiceContext.GetContext(SPContext.Current.Site));
KeywordQuery query = new KeywordQuery(proxy);
query.ResultsProvider = Microsoft.Office.Server.Search.Query.SearchProvider.Default;
query.QueryText = queryText;
query.HiddenConstraints = "This Site: " + siteName + "";
query.ResultTypes |= ResultType.RelevantResults;
References:
No comments:
Post a Comment