Get ResultTable from ResultTableCollection in SharePoint 2010

In order to get a ResultTable object from a ResultTableCollection (typically obtained from a search query execution using the KeywordQuery class) you should use the property Item from the class ResultTableCollection documented here.

Through the access operator [ ] you must specify RelevantResults as ResultType:

ResultTable restab = results[ResultType.RelevantResults];

Into the ResultTable object you will get a table filled with search results.

Below a code snippet for counting the total number of results for a given query text:

public int SearchResultCount(string queryText) 
  int searchResultCount = 0;

  using (SPSite site = new SPSite(SPContext.Current.Web.Site.Url))
    KeywordQuery query = new KeywordQuery(site);

    query.ResultsProvider = SearchProvider.Default;
    query.ResultTypes = ResultType.RelevantResults;
    query.KeywordInclusion = KeywordInclusion.AllKeywords;
    query.QueryText = queryText;

    ResultTableCollection results = query.Execute();

    if (results.Count > 0)
      ResultTable restab = results[ResultType.RelevantResults];
      searchResultCount = restab.TotalRows;

  } // using site

  return searchResultCount;



Category BootstrapCategory CoffeescriptCategory DrupalCategory GravCategory HTMLCategory JavascriptCategory JoomlaCategory jQueryCategory LaravelCategory MagentoCategory PHPCategory SharePointCategory SpringCategory ThymeleafCategory WordPressCategory Workflow


Developed and designed by Netgloo
© 2019 Netgloo