1

I'm trying to do something that I don't see a lot of descriptions of.

For our installation of Sitecore, we have a special index, for managing pictures via a service called "Digizuite".

This index breaks once in a while, and then needs to be reindexed. We have not been able to determine why, but maybe we will at some point, who knows.

But, in order to fix the issue more acutely, we decided to create a command in Sitecore that we could start via a Sitecore scheduled task, and then reindex it once a day.

So, I have created a command that points to a method in the code, and then is started via a scheduled task.

The code I have written so far looks like this:

public void Execute()
{
    RebuildIndexes("dfs_assets_master_index");
    RebuildIndexes("dfs_assets_web_index");
}

private void RebuildIndexes(string indexName)
{
    var index = GetIndex(indexName);
    var indexstate = index.IndexingState;

    if (indexstate == IndexingState.Started)
    {
        index.Rebuild();
        indexstate = index.IndexingState;
    }
}

Where I basically check the state of the index, and if it is not already running, then I run rebuild on it.

The only check I have implemented for avoiding double-indexing is to check whether the index is not stopped or paused. But could I implement some other important checks? such as checking the last index of the rebuild?

1 Answer 1

1

As you want to run this as scheduled job, so you can ensure that there is a sufficient gap between the last run and the new run. You could perhaps run it once a day. So, I feel that there is no need to check the index state.

  1. You should have a null check in place for indexName. If the indexName is empty or null, you should return.

  2. You could add try-catch clause so that if the jobs fails you get to know about it by checking the logs.

  3. You should also include additional logging comments like "Starting indexing for {indexName}" at the start of the function and "Finished indexing for {indexName}" at the end.

1
  • thx, I'll include those checks!
    – Ask Sejsbo
    Feb 18 at 20:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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