【问题标题】:Sitecore Refresh IndexSitecore 刷新索引
【发布时间】:2017-03-09 23:22:30
【问题描述】:

我正在使用 Sitecore 7.2 并使用 Lucene 搜索,我创建了一些模板和页面并且搜索工作正常,现在我想从索引中排除一些模板,我有一个自定义爬虫,它确实从索引但索引未刷新,我正在使用以下代码更新索引

foreach (Cache cache in CacheManager.GetAllCaches())
{
    //WriteLog(string.Concat(" Clearing Cache, name = ", cache.Name));
    cache.Clear();
}
//WriteLog("Clearing caching finished");
var index = ContentSearchManager.GetIndex("sitecore_global_index");
index.RebuildAsync(IndexingOptions.ForcedIndexing, new System.Threading.CancellationToken(false));
index.Reset();
//index.Refresh();

【问题讨论】:

  • 您是否尝试过从 Sitecore Desktop 手动重建它?
  • 是的,它可以在桌面上工作,但我想用代码来做。

标签: indexing sitecore sitecore7 sitecore7.2


【解决方案1】:

以下代码以前对我有用,它将索引从 RootItemInTree 及以下开始的内容树:

index.Refresh(new SitecoreIndexableItem(RootItemInTree));

【讨论】:

  • 我用过这个方法,但是当我从控制面板索引时发生了一些神奇的事情。我还使用索引查看器来查看索引中的项目,当我从控制面板索引时它会显示新项目。我想有一个索引作业在通过控制面板执行索引时运行,但我无法找到该作业。您对索引作业有任何想法吗?
【解决方案2】:

以编程方式重建索引的最简单方法是:

Sitecore.ContentSearch.ContentSearchManager.GetIndex("Your_Index_Name").Rebuild();

这个 GetIndex() 方法已经被重构为 ContentSearchManager,之前它被保存在这个类中:

Sitecore.Search.SearchManager

..对于某些人来说,它已经引起了问题,记住这一点很好。

如果您想以编程方式找出索引名称(假设您想遍历它们),请从以下位置检索它们:

ContentSearchManager.Indexes

希望对您有所帮助,如果您还有其他问题,请告诉我们。

干杯!

【讨论】:

    【解决方案3】:

    由于您尝试使用异步方法,因此您使用不正确。使用“等待”前缀。

    **await** index.RebuildAsync(IndexingOptions.ForcedIndexing, new System.Threading.CancellationToken(false));
    

    它对我有用。

    protected async void RebuildIndexAsync()
    {
     foreach (Cache cache in CacheManager.GetAllCaches())
     {
        //WriteLog(string.Concat(" Clearing Cache, name = ", cache.Name));
        cache.Clear();
     }
     //WriteLog("Clearing caching finished");
     var index = ContentSearchManager.GetIndex("sitecore_global_index");
     await index.RebuildAsync(IndexingOptions.ForcedIndexing, new    System.Threading.CancellationToken(false));
     index.Reset();
     //index.Refresh();
    }
    

    【讨论】:

      猜你喜欢
      • 2015-07-27
      • 1970-01-01
      • 1970-01-01
      • 2016-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-01
      相关资源
      最近更新 更多