【发布时间】:2016-01-08 05:42:25
【问题描述】:
下面有人可以帮我理解吗?
在使用 Sitecore solr 搜索时,是否需要在代码中指定索引的名称?
如果我们创建名为“sitecore_web-index_custom”的新自定义索引。我们如何确保我们在代码中使用了这个索引?
谢谢。
【问题讨论】:
下面有人可以帮我理解吗?
在使用 Sitecore solr 搜索时,是否需要在代码中指定索引的名称?
如果我们创建名为“sitecore_web-index_custom”的新自定义索引。我们如何确保我们在代码中使用了这个索引?
谢谢。
【问题讨论】:
为了获取 Sitecore 索引,请使用 ContentSearchManager 类中的 GetIndex 方法:
Sitecore.ContentSearch.ContentSearchManager.GetIndex(...)
您可以传递索引名称:
// get Sitecore built in index for current database:
string dbName = (Sitecore.Context.ContentDatabase ?? Sitecore.Context.Database).Name;
var index = Sitecore.ContentSearch.ContentSearchManager.GetIndex("sitecore_" + dbName + "_index");
// get custom index
Sitecore.ContentSearch.ContentSearchManager.GetIndex("sitecore_web-index_custom")
或 Sitecore 项目:
// get index by Sitecore item
Sitecore.ContentSearch.ContentSearchManager.GetIndex((SitecoreIndexableItem)item);
在第二种情况下,Sitecore 将尝试查找项目所在的索引。
获取 Solr 或 Lucene 索引没有区别 - Sitecore API 在这里是透明的。
有关 Sitecore 搜索和索引的更多信息,请参见
【讨论】: