Creating search indexes programmatically for a new website (which is also created programmatically)

Ozgur Ozguven asked on July 24, 2015 12:23

I am programmatically creating search indexes via API and can see them listed in Smart Search application in Admin UI. I am also creating rebuild tasks as below:

SearchTaskInfoProvider.CreateTask( SearchTaskTypeEnum.Rebuild, index.IndexType, null, clone.IndexName, clone.IndexID, true );

But these tasks result in error. In DB I get 'error' and 'Object reference not set to an instance of an object.' in SearchTaskStatus and SearchTaskErrorMessage columns in CMS_SearchTask table.

Can someone see what I am doing wrong and suggest a correct way please?

Many thanks,


Recent Answers

Bryan Soltis answered on July 24, 2015 16:49

Hi Ozgur,

I have programatically rebuilt indexes using the following code:

(Note: this is v7 code)

// Get the search index foreach(SearchIndexInfo index in SearchIndexInfoProvider.GetSearchIndexes(null,null)) { if (index != null) { // Create rebuild task SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Rebuild, index.IndexType, null, index.IndexName); intCount +=1; } }

If you are creating the index and then rebuilding all in the same automated process, it's possible that the creation is not finished before the rebuild is execute. Seeing how a large index may take some time to create, this would probably result in an error. You would need to call the rebuild after the the creation process is completed.

If you are executing the rebuild after you know the index has been created, can you provide the stack trace or other details from the error?

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on July 24, 2015 20:15

If you're getting that ever so informational error, there's a good chance you're missing some data or don't have your code quite right when you're building your index. Have you attempted to debug the building of the index and the task to rebuild your index? Maybe have to post your code?

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.