Counting the no.of search results

Manohar reddy vangala asked on March 19, 2015 15:17

How can i find the no.of search results in result set in back-end i.e. in code behind file, on that i have the dependency of showing the load-more button in my custom search results control.

Recent Answers


Jan Hermann answered on March 24, 2015 07:39

Hello Manohar reddy,

If you want to display that total number of results on your live site, you can place following code to your transformation:

<%# DataItemIndex == 0 ? "<p>Total results: " + DataItemCount + "</p>" : "" %>

If you really want to do this in the code then this information is available in the Search results control that is used in all smart search related web parts:

~\CMSModules\SmartSearch\Controls\SearchResults.ascx.cs

There is a method called Search() that contains the following code:

// Search
DataSet results = SearchHelper.Search(parameters);
int numberOfResults = parameters.NumberOfResults;

You can store this number to a cookie or a session whatever else and render it in your transformation.

Another possibility which should be possible is to get the number of search results with the following code: Hashtable resultRows = RequestStockHelper.GetItem(SearchHelper.RESULTS_KEY) as Hashtable;int numberOfRows = resultRows.Count;

Best regards,
Jan Hermann

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.