应用不同的RowLimit参数时,TotalRows属性显示不同的结果(SharePoint 2013搜索REST和CSOM Api)

时间:2014-10-28 12:55:23

标签: rest sharepoint sharepoint-2013 csom sharepoint-search

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

为什么会这样,我怎么能解决这个问题?

1 个答案:

答案 0 :(得分:3)

请参阅this link并提出类似问题:

  

搜索结果返回的计数不是准确的数字。这就是为什么它说&#34;关于410结果&#34;。每次更改页面时,都会执行查询,而SharePoint会再次猜测找到了多少结果,即使查询没有更改。

这就是为什么有ResultTable.IsTotalRowsExact属性,如果TotalRows是返回的确切结果数,那么这个属性将成立。