Run SmartSearch after Scheduled Task

James Mosquito asked on February 4, 2021 10:57

Hi, I have a Scheduled Task which will add/update pages on a regular basis. After running a recent test of the task the frontend site broke with lots of 40x errors when trying to navigate. The cause seemed to be related to the SmartSearch indexes which needed to be rebuilt - after doing so, everything worked again as normal.

Is there a way to stop SmartSearch when my task starts and to rebuild the index after it finishes?

Thanks, James

Correct Answer

Dmitry Bastron answered on February 4, 2021 18:44

Sure, here is the link to 12SP example.

Ok, so in theory if everything is right when you add/update the page via Kentico API it should update the index item automatically as well. Is this MVC site and do you have any customizations for index build in the code? Also, are there any errors in Kentico event log while import is running?

0 votesVote for this answer Unmark Correct answer

Recent Answers

Dmitry Bastron answered on February 4, 2021 15:02

Hi James,

SmartSearch is not a service or something, you cannot "stop" it. This is a search index and it just exists. In order to help you, could you provide a bit more information about your setup, please?

  • How do you add/update pages? Directly in the database, via code using Kentico API, using standard REST API endpoint or somehow else?
  • Do you have one or many search indexes? Are they standard or custom? And how are they used?

To your question, it is possible to rebuild indexes from the code, here is an example. So you cancall it in theory at the end of your import process.

0 votesVote for this answer Mark as a Correct answer

James Mosquito answered on February 4, 2021 15:22 (last edited on February 4, 2021 15:34)

Hi Dmitry,

I followed the link which shows a code example for Kentico Experience 13 - is the same possible in Kentico 12 SP? (Changing the documentation version removed those code examples).

  1. I am using the Kentico API to create and update pages.
  2. There is one index at the moment - using the Pages crawler index type and the Standard analyzer type - with a view to possibly adding a second index for searching within PageType fields.

Thanks, James

0 votesVote for this answer Mark as a Correct answer

James Mosquito answered on February 12, 2021 16:03

Thanks Dmitry,

There weren't any errors but the cause ended up being related to the storeId. In a form control this was being picked up from the SiteContext which isn't available in a ScheduledTask - so running an import was effectively changing the storeId of my documents when updating them and in turn was invalidating the indexes for those documents.

Adding a helper to get the storeId from the database solved this and everything is running fine now, indexes included.

Thanks for the code reference as it is still useful to be aware of.

0 votesVote for this answer Mark as a Correct answer

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