gpt4 book ai didi

c# - SearchManager 与 ContentSearchManager?

转载 作者:行者123 更新时间:2023-11-30 23:19:27 25 4
gpt4 key购买 nike

我非常认真地研究了 sitecore 的搜索功能,直到现在我一直使用以前的开发人员使用的功能。我正在研究一个问题,其中某些谓词似乎没有在下面的代码中起作用:

public IEnumerable<IndexedEvent> SearchItems(Expression<Func<IndexedEvent, bool>> predicate)
{
using (IProviderSearchContext _context = ContentSearchManager.GetIndex(indexName).CreateSearchContext())
{
IEnumerable<IndexedEvent> results = _context
.GetQueryable<IndexedEvent>()
.Where(predicate);

return results;

}
}

上面的不是我写的,我只是用而已。

当我遇到这个示例问题时,我正在调查我的问题 Very basic usage of sitecore search其中包括代码:

// use id of from the index configuration
using (IndexSearchContext indexSearchContext = SearchManager.GetIndex("my-custom-index").CreateSearchContext())
{
// MatchAllDocsQuery will return everything. Use proper query from the link below
SearchHits hits = indexSearchContext.Search(new MatchAllDocsQuery(), int.MaxValue);
// Get Sitecore items from the results of the query
List<Item> items = hits.FetchResults(0, int.MaxValue).Select(result => result.GetObject<Item>()).Where(item => item != null).ToList();
}

现在这似乎使用了一种完全不同的方法来查询索引,IndexSearchContext,而我的代码(不是我写的)使用 IProviderSearchContext。我找不到关于这两者的任何文档,它们位于完全不同的程序集中。

那么问题来了,什么时候应该使用IndexSearchContext,什么时候应该使用IProviderSearchContext?这里有任何根本的区别,还是只是实现相同净结果的两种方式?

最佳答案

您在 SearchManager 中提到的问题和代码和 IndexSearchContext来自 Sitecore 6。带有 ContentSearchManager 的代码和 IProviderSearchContext适用于 Sitecore 7 或 8(好吧,就是 7+)。

因此,如果您的代码如您的标签和代码示例所建议的那样适用于 Sitecore8,则 ContentSearchManager 是最佳选择。

关于c# - SearchManager 与 ContentSearchManager?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40288582/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com