SearchTaskInfoProvider.CreateTask example/explanation?

Quang Lai asked on October 1, 2017 19:54

I've been looking at this old article on creating custom search index: https://devnet.kentico.com/articles/smart-search-in-kentico-cms-6 as it provides the full package (includes creating search tasks when content is modified); but it's obviously old. Although, we are still using Kentico 8.2 at the moment.

I'm trying to make use of the following function: http://devnet.kentico.com/docs/8_2/api/html/M_CMS_Search_SearchTaskInfoProvider_CreateTask_1.htm

But I don't quite understand what the parameters really mean, and what to pass in for example: SearchTaskTypeEnum.Delete and SearchTaskTypeEnum.Update; in scenarios for both media files and Kentico documents.

Is there an article around that would explain the parameters, and the global events which we should be aware of?

Correct Answer

Juraj Ondrus answered on October 2, 2017 08:11

Hi,
There were huge changes between version 6 and 8.x - basically major part of Kentico was refactored and rewritten again. The video you were referring to was basically a hack.
1. Yes, it should be OK to catch the event handler events and perform the search index update tasks.
2. It depends on what kind of changes you will be doing. The rebuild of the index is needed when you change the structure of the index - e.g. you add or remove some field which is being indexed. For content updates, the rebuild is not needed as you just need to update content, not the structure.

0 votesVote for this answer Unmark Correct answer

Recent Answers


Juraj Ondrus answered on October 1, 2017 20:48

Hi,
I would recommend following the official documentation for Kentico 8.2 on creating custom smart search indexes. There is also an example on how to create index and also how to update it. It is not possible to use the standard search tasks in this case. The method you are referring to is used only with the default, out of the box indexes.
With additional custom development, you can update indexes by calling the Update or Delete methods of the CMS.Search.SearchHelper class. Typically, you need to update the index from custom code outside of the index class whenever the indexed content changes. However, in this case you need to ensure that the API is never called concurrently – problems can occur if multiple processes attempt to update the same index at the same time.

0 votesVote for this answer Mark as a Correct answer

Quang Lai answered on October 2, 2017 00:54 (last edited on October 2, 2017 01:01)

Thanks Juraj, I read that block a bit more carefully and I think I understand it a bit better. Was that a change between CMS 6 - 8.2? I'm just not sure why Miro's original example had what I'm referring to.

I'd still like to know if there is an article explaining how to properly use the SearchTaskInfoProvider.CreateTask method?

Also, is there any article explaining how to "...[with] additional custom development, you can update indexes by calling the Update or Delete methods of the CMS.Search.SearchHelper class. Typically, you need to update the index from custom code outside of the index class whenever the indexed content changes." ?

Edit: is it as simple as catching the global (insert/update/delete)_after events, and using the SearchHelper.Update/Delete method like Peter's last code snippet at: https://devnet.kentico.com/forums/f68/fp9/t37659/update-smart-index-after-edit-delete-insert-d ?

Edit #2: would doing the above suffice, or will an index rebuild still be necessary for the SearchHelper.Update/Delete to "take affect"?

0 votesVote for this answer Mark as a Correct answer

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