3

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.

3

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.

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.