我们最近升级到 Sitecore 6.6,并遇到了来自 Lucene 的搜索和爬网功能的问题,因为 6.6 使用了更新的版本,并且一些方法/功能已经过时。
下面的代码在以前版本的 Lucene.NET 2.3 中可以正常工作,但在 2.9 中不能正常工作。你能告诉我们我们做错了什么并帮助我们纠正这段代码吗?我们在编译时得到的错误是
`Lucene.Net.Search.IndexSearcher` does not contain a definition for 'Search'
and no extension method 'Search' accepting a first argument of type
`Lucene.Net.Search.IndexSearcher` could be found (are you missing a using
directive or an assembly reference?)
此错误发生在这一行 - Sitecore.Search.SearchHits hits = new SearchHits(context.Searcher.Search(query,sort));
。我猜这将是一个简单的修复,但我不确定如何修复它。
private static SearchResultCollection GetSearchResults(Query query, Sort sort, int startingIndex, int getCount, out int totalHits)
{
SearchResultCollection retVal = new SearchResultCollection();
Sitecore.Search.Index searchIndex = Sitecore.Search.SearchManager.GetIndex("content");
using (Sitecore.Search.IndexSearchContext context = searchIndex.CreateSearchContext())
{
Sitecore.Search.SearchHits hits = new SearchHits(context.Searcher.Search(query,sort));
totalHits = hits.Length;
//since index is zero based... adjust the numbers
startingIndex = (startingIndex - 1) * getCount;
getCount = (getCount > totalHits || totalHits < startingIndex + getCount)
? hits.Length - startingIndex : getCount;
retVal = hits.FetchResults(startingIndex, getCount);
}
return retVal;
}
谢谢