【问题标题】:Specifying which index to use in sitecore lucene指定要在 sitecore lucene 中使用的索引
【发布时间】:2017-05-30 10:20:52
【问题描述】:

我有一个在我继承的 sitecore 中生成的网站。搜索似乎无法正常工作。基本上文件似乎没有正确返回。我注意到有默认的 sitecore_web_index 索引和一个自定义索引,似乎或多或少地索引相同的内容。目前,搜索查询自定义索引,但是我想将查询更改为默认索引,以查看文档是否被返回。有人告诉我您可以指定要使用的索引,但该人从未告诉我该怎么做。有谁知道我该如何改变这个?

【问题讨论】:

    标签: sitecore sitecore8


    【解决方案1】:

    Sitecore 8 内容搜索使用Sitecore.ContentSearch.ContentSearchManager.GetIndex(...) 方法检索所选索引。

    你可以通过:

    1. 字符串形式的索引名称:
    Sitecore.ContentSearch.ContentSearchManager.GetIndex("sitecore_web_index")
    
    1. IIndexable item - 在这种情况下,Sitecore 将尝试为您找到第一个注册索引:
    Sitecore.ContentSearch.ContentSearchManager.GetIndex(iIndexable)
    

    只需找到代码中GetIndex 的使用位置,并将其替换为默认索引名称即可。

    您应该注意的一件事 - 您的自定义索引有可能添加了一些自定义项(例如计算字段、索引字段列表等)。小心任何变化。也许还有其他原因导致您的搜索不起作用。尝试使用IndexingManager app 重建索引,看看是否有帮助。

    【讨论】:

      【解决方案2】:

      您还需要记住,在 Content Manager 环境中,将使用“sitecore_master_index”,而在 CD 环境中,将使用“sitecore_web_index” 所以这可能会导致测试错误

      你可以尝试动态获取索引,这样的话,代码会根据自己的环境选择正确的索引使用

      var indexable = Sitecore.Context.Item as SitecoreIndexableItem;
      
      ISearchIndex index = ContentSearchManager.GetIndex(indexable);
      
      using (IProviderSearchContext context = index.CreateSearchContext())
      {
       //search code...
      }
      

      【讨论】:

        【解决方案3】:

        不得不这样做......

        var indexable = (SitecoreIndexableItem)Sitecore.Context.Item;

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-08-01
          • 1970-01-01
          相关资源
          最近更新 更多