如何使用 Sitecore Solr 自定义索引
How to use Sitecore Solr Custom Index
有人可以帮我理解下面吗?
使用Sitecore solr搜索时,是否需要在代码中指定索引名称?
如果我们将新的自定义索引命名为'sitecore_web-index_custom'。我们如何确保我们在代码中使用这个索引?
谢谢。
为了获取 Sitecore 索引,请使用 ContentSearchManager
class:
中的 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 搜索和索引的更多信息,请参阅
有人可以帮我理解下面吗?
使用Sitecore solr搜索时,是否需要在代码中指定索引名称?
如果我们将新的自定义索引命名为'sitecore_web-index_custom'。我们如何确保我们在代码中使用这个索引?
谢谢。
为了获取 Sitecore 索引,请使用 ContentSearchManager
class:
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 搜索和索引的更多信息,请参阅