TotalRows属性在应用不同的RowLimit参数(SharePoint 2013 Search REST和CSOM



在使用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
} 

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

请参阅带有类似问题的链接:

为搜索结果返回的计数不是一个准确的数字。这就是为什么它说"大约410个结果"。每次更改页面时,都会执行查询,SharePoint会对找到的结果数量进行另一次猜测,即使查询没有更改。

这也是为什么如果TotalRows是返回的结果的确切数量,那么ResultTable.IsTotalRowsExact属性将为true。

最新更新