3
在Lucene.Net中,可以使用TopDocs.TotalHits
屬性檢索匹配文檔的總數。如何從Sitecore 7 LINQ ContentSearch API檢索總計結果數量?
此功能was exposed in the Advanced Database Crawler API在QueryRunner類中使用out
參數。
什麼是建議使用Sitecore 7的新LINQ API檢索總結果數的方法?沒有列舉整個結果集似乎不可能。以下是我迄今爲止:
var index = ContentSearchManager.GetIndex("sitecore_web_index");
using (var context = index.CreateSearchContext())
{
var query = context.GetQueryable<SearchResultItem>()
.Where(item => item.Content == "banana");
var totalResults = query.Count(); // Enumeration
var topTenResults = query.Take(10); // Enumeration again? this can't be right?
...
}
Sitecore開發團隊的這篇博客文章也介紹了這個主題 - http://www.sitecore.net/Community/Technical-Blogs/Sitecore-7-Development-Team/Posts/2013/07/Sitecore- 7決策 - 谷歌 - 部分 - 3.aspx –