I am trying to retrieve the search result from specific Sub Site using KQL in SharePoint 2010.but I am getting only one result with custom code. However the OOTB Search result returns 5 results for the same Query Text.

I have already checked This Link

Here is my Code .

using (SPSite scSite = new SPSite(SPContext.Current.Web.Url)) 
          using (SPWeb webRoot = scSite.OpenWeb()) 
             scSite.AllowUnsafeUpdates = true;
             webRoot.AllowUnsafeUpdates = true;
             SearchServiceApplicationProxy proxy = (SearchServiceApplicationProxy)SearchServiceApplicationProxy.GetProxy(SPServiceContext.GetContext(SPContext.Current.Site));
             KeywordQuery keywordQuery = new KeywordQuery(proxy);
             keywordQuery.ResultsProvider = Microsoft.Office.Server.Search.Query.SearchProvider.Default;
             keywordQuery.TrimDuplicates = false;
             keywordQuery.EnableStemming = true;
             keywordQuery.QueryText = query;
             keywordQuery.HiddenConstraints = "This Site: " + SPContext.Current.Web.Name + "";
             keywordQuery.ResultTypes = ResultType.RelevantResults;
             ResultTableCollection searchResultTables = keywordQuery.Execute();
             ResultTable searchResult = searchResultTables[ResultType.RelevantResults];
             var resultsDataTable = new DataTable {TableName = "Results"};
             resultsDataTable.Load(searchResult, LoadOption.OverwriteChanges);
  • Have you tried using the Path managed property rather than your hidden constraint? Jul 6 '18 at 16:02
  • Thanks @MatthewMcDermott, It worked with Path Managed Property. Sep 10 '18 at 6:04

I solved the issue by using the Path managed property in the QueryText of KQL.

i.e., query = (Search Term) ((Path:a))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.