SharePoint: Limit KeywordQuery to current site in SharePoint

If you want to limit the KeywordQuery to current site only, use the HiddenConstraints property.
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;
profile for Nadeem Yousuf at SharePoint Stack Exchange, Q&A for SharePoint enthusiasts

+