2

在使用 SharePoint Search REST Api 时,我遇到了以下问题,如果我使用不同rowlimit的值,totalrows属性会改变它的值。例如,对于这样的请求:

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

我得到以下回复:

<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>

另一方面,通过这个请求,http://my-site/_api/search/query?querytext='test'&rowlimit=5我得到了这个:

<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>

我已经使用 CSOM Api 进行了检查,它返回与 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
} 

为什么会这样,我该如何解决这个问题?

4

1 回答 1

4

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.

于 2014-10-28T23:03:56.027 回答