Sitecore Refresh Index

瘦欲@ 提交于 2020-01-04 02:39:08

问题


I am working on Sitecore 7.2 and using Lucene search, I have created few templates and pages and search is working fine, now I want to exclude few templates from the index, I have a custom crawler and that does remove the templates from indexes but index is not refreshed, I am using following code to update index

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();

回答1:


The following code worked for me before, It will index the content tree starting from RootItemInTree and below:

index.Refresh(new SitecoreIndexableItem(RootItemInTree));



回答2:


The simplest way to rebuild index programmatically is:

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

This GetIndex() method has been refactored into ContentSearchManager, previously it was kept in this class:

Sitecore.Search.SearchManager

..for some people it has made issues, so good to keep in mind.

In case you want to find out index name(s) programmatically (let's say you'd like to iterate through them), retrieve them from:

ContentSearchManager.Indexes

Hope this helps, please let us know if you got further questions.

Cheers!




回答3:


Since you are trying to use Asynchronous method, you are using it incorrectly. Use "await" prefix.

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

It is working for me.

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();
}


来源:https://stackoverflow.com/questions/31419638/sitecore-refresh-index

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!