The best I could find in documentation was this: Rebuild search indexes
... but that doesn't really help me. I'm trying to do this programatically an would like best practices for doing this sort of thing.
Thanks.
Sitecore Stack Exchange is a question and answer site for developers and end users of the Sitecore CMS and multichannel marketing software. It only takes a minute to sign up.
Sign up to join this communityThe best I could find in documentation was this: Rebuild search indexes
... but that doesn't really help me. I'm trying to do this programatically an would like best practices for doing this sort of thing.
Thanks.
The ISearchIndex
is the interface that represents everything about the index. The concrete object that will get created will be determined by the index configuration file for the specific index (usually Lucene or Solr).
If we look at sitecore_web_index
on a default Sitecore install, you can see that it is using the Sitecore.ContentSearch.LuceneProvider.LuceneIndex
from line 6 of the configuration file.
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<contentSearch>
<configuration type="Sitecore.ContentSearch.ContentSearchConfiguration, Sitecore.ContentSearch">
<indexes hint="list:AddIndex">
<index id="sitecore_web_index" type="Sitecore.ContentSearch.LuceneProvider.LuceneIndex, Sitecore.ContentSearch.LuceneProvider">
<param desc="name">$(id)</param>
<param desc="folder">$(id)</param>
<!-- This initializes index property store. Id has to be set to the index id -->
<param desc="propertyStore" ref="contentSearch/indexConfigurations/databasePropertyStore" param1="$(id)" />
<configuration ref="contentSearch/indexConfigurations/defaultLuceneIndexConfiguration" />
<strategies hint="list:AddStrategy">
<!-- NOTE: order of these is controls the execution order -->
<strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/onPublishEndAsync" />
</strategies>
<commitPolicyExecutor type="Sitecore.ContentSearch.CommitPolicyExecutor, Sitecore.ContentSearch">
<policies hint="list:AddCommitPolicy">
<policy type="Sitecore.ContentSearch.ModificationCountCommitPolicy, Sitecore.ContentSearch">
<Limit>300</Limit>
</policy>
</policies>
</commitPolicyExecutor>
<locations hint="list:AddCrawler">
<crawler type="Sitecore.ContentSearch.SitecoreItemCrawler, Sitecore.ContentSearch">
<Database>web</Database>
<Root>/sitecore</Root>
</crawler>
</locations>
<enableItemLanguageFallback>false</enableItemLanguageFallback>
<enableFieldLanguageFallback>false</enableFieldLanguageFallback>
</index>
</indexes>
</configuration>
</contentSearch>
</sitecore>
</configuration>
The IndexCustodian
class is more of a helper class that can be used to perform maintenance on one or more indexes. If all you want to do is rebuild a specific index (or all of them) through some custom code you can use this class to do it.
Triggering indexing through 'IndexCustodian' could be very effective as
1.Indexing would be performed as a job.
2.You can get the log entries while triggering indexing since its running as a job.
3.Indexing through Index custodian is similiar to indexing through Sitecore UI Interface.
4.It will support switch-on-rebuild indexes i.e. swap between primary & secondary collection/core on every subsequent Indexing.
5.It performs 'ForcedIncremental Index Update' even if indexing is
paused or stopped.
IndexCustodian Class ( rebuild as job) Decompiled:
public static Job FullRebuild(ISearchIndex index, bool start = true)
{
return IndexCustodian.CreateRebuildJob(index, new EventHandler<JobStartedEventArgs>(IndexCustodian.RebuildStartedHandler), new EventHandler<JobFinishedEventArgs>(IndexCustodian.RebuildFinishedHandler), start, null);
}
public static Job FullRebuild(ISearchIndex index, IndexingOptions options, bool start = true)
{
return IndexCustodian.CreateRebuildJob(index, new EventHandler<JobStartedEventArgs>(IndexCustodian.RebuildStartedHandler), new EventHandler<JobFinishedEventArgs>(IndexCustodian.RebuildFinishedHandler), start, new object[]
{
options
});
}