If you are developing a custom result page, some of the key requirements (in addition to showing relevant results) that are common across many types of projects are:
The SharePoint Object Model (OM) provides two types of classes to query against it content: KeywordQuery and FullTextSqlQuery. These queries have properties StartRow and RowLimit. Both of these queries get us result in ResultTable class and this class has one property TotalRows. These properties are defined below:
With the above understanding, isn't it too simple to implement to get both of the points – 1 and 2 stated above. Basically, your paging would be like this .. Result <StartRow> to <StartRow + RowLimit> of <TotalRows>. And based on TotalRows, you can show the links for pages to be displayed.
However, this is not that simple. It's very difficult for any search engine (including web search engines such as Live or Google) to get the exact number of total results found as it's very time consuming scheme. So, most search engines (including MOSS) perform only an "estimate" to provide total number of results. Hence, the value of TotalRows property can change for the same keyword. The value is more accurate when the StartRow is towards the end of search results. Hence any logic to display links for search pages can fail here. I recommend the following approach here:
The links for "page" numbers may get unstable. For example, let us say, you got total rows as 100 and you always show links for page 1, 2, 3, 4 and 5. But let us say, actual result is 27 only. Which would mean if user clicks on page "4" , you'll fire a query for item 31 to 40 and you'll get zero results. At this point rather than showing page with zero results, do the following:
Though, the approach seems "crude" , but it's one of the most efficient and least invasive way to achieve this functionality. Even internet search engines such as Live and Google employ the same technique.
There are some other approach that you can use to get the numbering correct as provided in the following blogs: