>
Blog
Book
Portfolio
Search

7/19/2010

5075 Views // 0 Comments // Not Rated

SharePoint Search: The Difference Between RowCount And TotalRows

I just wanted to post a real quick note about something that finally dawned on me regarding the SharePoint 2007 search API. There are two properties in the ResultTable object that I've been using interchangeably, as the documentation on MSDN does little to discern them from one another. These are RowCount and TotalRows.

Turns out, the way I usually customize my queries also technically didn't discern them. I'm working on a paged search result viewer control. The way it worked previously was that it got all of the data from a single query and chopped up the results into pages client side. Using Silverlight, these pages could then be navigated via prettily-animated transitions. With this style, since we are interested in ALL of the results in the query, RowCount is always the same as TotalRows.

As a performance enhancement, we punted the animations, and instead only started requesting a certain block of results. Now, each query gives us results X though Y of Z. When you tell SharePoint to only give you a certain number of results (Y) starting from a particular index (X), you actually get (Z) for free! So if you are doing paged searches, you don't need to worry about doing an "empty" search (in terms of columns) to just get the total number of rows; the API is smart enough give us this number without actually doing the work of calculating all the corresponding results.

So: RowCount is the actual number of search results, based on the StartRow and RowLimit properties. TotalRows is therefore the actual amount of search items that exist in the index that correspond to their query, irrespective to any paging trimming.

Here's a quick code block to demonstrate how to use these properties:

Code Listing 1

  1. private ResultTable RunQuery(string text, int rowLimit, int startIndex)
  2. {
  3. //initialization
  4. FullTextSqlQuery query = new FullTextSqlQuery(ServerContext.Current);
  5. //build query
  6. query.RowLimit = rowLimit;
  7. query.QueryText = "(query)";
  8. query.TrimDuplicates = true;
  9. query.StartRow = startIndex * rowLimit;
  10. query.ResultTypes = ResultType.RelevantResults;
  11. //return
  12. return query.Execute()[ResultType.RelevantResults];
  13. }

Have fun!

No Tags

No Files

No Thoughts

Your Thoughts?

You need to login with Twitter to share a Thought on this post.


Loading...