2

We are programmatically creating items and using Solr indexes so we want to disable solr indexing whenever we create an item.

We tried following code to disable during item creation Item.Add()

Sitecore.Configuration.Settings.Indexing.Enabled = false;

But it does not stop indexing and still happen in Solr. What can be the possible reason?

2 Answers 2

6

Code which you have used, it works only for "old" indexes, but not for the Sitecore 7 indexes. I am sure you must be using old one.

You should try to disable/enable indexing as follows

Sitecore.ContentSearch.Maintenance.IndexCustodian.PauseIndexing();
// Add code to create item
IndexCustodian.ResumeIndexing();

Also add check whether indexing is currently paused or not with the use of the following:

IndexCustodian.IsIndexingPaused(ISearchIndex index )
1
  • Thanks for giving the complete namespace of the IndexCustodian - I was struggeling to find it. Commented Jun 21, 2022 at 13:10
5

You can do in next way :

IndexCustodian.PauseIndexing();
  // Create items, etc 
  // Enable indexing again. 
IndexCustodian.ResumeIndexing();
1

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.