ChernikovP
ChernikovP

Reputation: 471

TotalRows property shows different results while applying different RowLimit parameter (SharePoint 2013 Search REST and CSOM Api)

While using SharePoint Search REST Api I encountered the following problem, if I use different rowlimit values, the totalrows property varies it value. For example, with such request:

http://my-site/_api/search/query?querytext='test'&rowlimit=10

I got following response:

<d:RowCount m:type="Edm.Int32">10</d:RowCount>
<d:Table m:type="SP.SimpleDataTable"></d:Table>
<d:TotalRows m:type="Edm.Int32">22</d:TotalRows>

On the other hand, with this request http://my-site/_api/search/query?querytext='test'&rowlimit=5 I acquire this:

<d:RowCount m:type="Edm.Int32">5</d:RowCount>
<d:Table m:type="SP.SimpleDataTable"></d:Table>
<d:TotalRows m:type="Edm.Int32">28</d:TotalRows>

I've done a check with CSOM Api and it returns the same values as REST:

using (var clientContext = new ClientContext(_url))
{
    var keywordQuery = new KeywordQuery(clientContext)
    {
        QueryText = "test",
        RowLimit = 10 //and then 5
    };
    var searchExecutor = new SearchExecutor(clientContext);
    var results = searchExecutor.ExecuteQuery(keywordQuery);
    clientContext.ExecuteQuery();

    Console.WriteLine("total rows: {0}", results.Value[0].TotalRows); // 22 and then 28
} 

Why it happens so and how could I solve this problem?

Upvotes: 2

Views: 2659

Answers (1)

Tatjana N.
Tatjana N.

Reputation: 6225

See this link with similar question:

The count returned for search results is not an accurate number. That is why it says "About 410 results". Every time you change pages, the query is executed and SharePoint takes another guess at how many results are found, even though the query has not changed.

That is also why there is ResultTable.IsTotalRowsExact property which will be true if TotalRows is the exact number of results returned.

Upvotes: 4

Related Questions