指定要在sitecore lucene中使用的索引
我有一个由我继承的sitecore制作的网站。搜索似乎无法正常工作。基本上,文档似乎没有正确返回。我注意到,有默认的sitecore_web_索引,也有一个自定义索引,似乎或多或少索引相同的内容。当前搜索查询自定义索引,但是我想将查询更改为默认索引,以查看文档是否会返回。我被告知你可以指定使用哪个索引,但那个人从来没有告诉我怎么做。有人知道我如何更改此设置吗?Sitecore 8内容搜索使用指定要在sitecore lucene中使用的索引,sitecore,sitecore8,Sitecore,Sitecore8,我有一个由我继承的sitecore制作的网站。搜索似乎无法正常工作。基本上,文档似乎没有正确返回。我注意到,有默认的sitecore_web_索引,也有一个自定义索引,似乎或多或少索引相同的内容。当前搜索查询自定义索引,但是我想将查询更改为默认索引,以查看文档是否会返回。我被告知你可以指定使用哪个索引,但那个人从来没有告诉我怎么做。有人知道我如何更改此设置吗?Sitecore 8内容搜索使用Sitecore.ContentSearch.ContentSearchManager.GetIndex(
Sitecore.ContentSearch.ContentSearchManager.GetIndex(…)
方法检索所选索引
您可以通过以下任一考试:
Sitecore.ContentSearch.ContentSearchManager.GetIndex(“Sitecore\u web\u index”)
IIndexable
item-在这种情况下,Sitecore将尝试为您查找第一个注册索引:Sitecore.ContentSearch.ContentSearchManager.GetIndex(iIndexable)
只需找到代码中使用的GetIndex
,并将其替换为默认索引名
有一件事你应该注意——你的自定义索引可能添加了一些自定义项(比如计算字段、索引字段列表等)。任何变化都要小心。也许你的搜索不起作用还有其他原因。尝试使用
IndexingManager
应用程序重建索引,看看是否有帮助。您还需要记住,在Content Manager环境中,将使用“sitecore\u主索引”,而在CD环境中,将使用“sitecore\u web\u索引”
因此,这可能会导致测试错误
您可以尝试动态获取索引,在这种情况下,代码将根据其环境选择正确的索引使用
var indexable = Sitecore.Context.Item as SitecoreIndexableItem;
ISearchIndex index = ContentSearchManager.GetIndex(indexable);
using (IProviderSearchContext context = index.CreateSearchContext())
{
//search code...
}