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();
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With