Global Event for Smart Search Indexing not firing

Kentico Dev asked on February 25, 2020 16:31

I have local Smart Search indexes set up and I am following the examples given on this page to add custom content to the index.

I have the event handler assigned like this:

DocumentEvents.GetContent.Execute += OnGetPageContent;

But it never gets fired. (I go to the Smart Search app in admin and rebuild my indexes. I expect the above event to get triggered, but it never does.)

I even tried attaching the event handler to a specific page type:

MyCustomPageType.TYPEINFO.Events.GetContent.Execute += OnGetPageContent;

And that did not work either.

To make sure that I could debug this custom module class at all, I attached to other events like this:

DocumentEvents.Update.After += OnGetPageContent;

And, when a I save a page, the above function gets called and I can step through in debug mode.

I need to add custom content to certain pages when indexes are built, what am I doing wrong? Am I attaching the handler to the wrong events, or does this not work in MVC K12?

My event handler signature is as follows:

private void OnGetPageContent(object sender, DocumentSearchEventArgs e)

Recent Answers


Brenden Kehren answered on February 25, 2020 22:52

Did you properly register the custom module?

[assembly: RegisterModule(typeof(CustomSmartSearchModule))]

Did you rebuild your project after adding this code?

0 votesVote for this answer Mark as a Correct answer

Kentico Dev answered on February 25, 2020 23:05

Yes, I have that at the top of my class.

I also have this in my AssemblyInfo.cs class

[assembly: AssemblyDiscoverable] 

My CustomSmartSearchModule is in a different C# Class Library project. I have referenced the relevant Kentico Libraries with NuGet and after I compile, the .dll is copied into the CMS/bin project that accompanies the MVC site.

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on February 26, 2020 08:18

The event should be fired when the content changes - e.g. you add/remove/edit a page covered by the index. Also, if the changes are made also through the MVC site - e.g. a blog post is added, you also need to deploy the custom module class to the separate MVC application. Otherwise the customized search indexing will not work for content changes that occur through the live site.

0 votesVote for this answer Mark as a Correct answer

Kentico Dev answered on February 27, 2020 16:26

"The event should be fired when the content changes - e.g. you add/remove/edit a page covered by the index."

Yes, that is what I expected, but it is not happening. I tried updating pages that are specifically included in the indexes I am maintaining. I double-checked that these are part of the index. I also tried manually rebuilding the index. The event for DocumentEvents.GetContent.Execute never gets fired.

"Also, if the changes are made also through the MVC site - e.g. a blog post is added, you also need to deploy the custom module class to the separate MVC application. Otherwise the customized search indexing will not work for content changes that occur through the live site."

I have the custom module as a separate class library. After compiling and generating the .dll for it, I included that dll in both the mvc and cms applications. To make sure that I have done things correctly, I have attached to another even that I know works: DocumentEvents.Update.After. That is simply to test that the module is registered, and it is, because when I save a page, the DocumentEvents.Update.After event gets triggered, but the DocumentEvents.GetContent.Execute does not. All of this is in the same class, so I know for a fact that the module is developed correctly and registered with the site. The only problem is, I don't want or need the DocumentEvents.Update.After event. I need the DocumentEvents.GetContent.Execute event.

What else am I missing? Is there some admin setting that I need to enable?

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on March 2, 2020 08:17

What version of Kentico are you using? I am following this example and it is working fine for me. I am using Kentico 12.0.60, Dancing Goat MVC sample project. So far, I am testing it on the Kentico app side. This is my code and it gets logged into the event log when I change some page in the admin.
How are you modifying the pages from the MVC app? What are the steps I need to follow to reproduce the issue, please?

0 votesVote for this answer Mark as a Correct answer

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