Find indexing job + HierarchicalCatalogPartialRouter: A note

I ran into this problem recently and while in the end it’s quite simple issue (Everything is simple if we understand it, right?), it costed me quite many hairs in the process – as it involved debugging with 3 solutions – Find.Commerce (where the problem appears), Commerce (where the router does the work), CMS Core (where the routers are handled). It was both fun, and confusing.

The problem as a customer has this code in an initialization module:

Nothing is special here Рthis is a technique to remove the catalog name from the partial router url. If you use CatalogRouteHelper.MapDefaultHierarchialRouter, then the url will be something like this

where “fashion” is your catalog name. It’s fine, but you might want it to be

only. If you have only one catalog and you don’t want to expose it/or you want shorter url – why not? The snippet above solves that problem. But only if you are not using Find – and the Find indexing job.

If you try to run the Find content indexing job with the code above, then your log file will be filled with errors like this:

So what’s wrong?

At first sight, it seems that the wildcard mapping was not added. But it was there. I was pulling my hairs (and quite hard, actually) until I look into the scheduled job itself. It was running with all the SiteDefinition, plus SiteDefinition.Empty.

The reason was SiteDefinition.Empty was needed, for indexing global assets and other data. However, SiteDefinition.Empty.StartPage is an empty ContentReference, which is assigned to be the BasePathRoot of the returned PartialRouteData, which will mess up with IContentLoader.Get when it tries to load that content.

You might argue that as a bug. Maybe. But the fix is easy enough for you to do it in your implementation. Simply change this line

to

i.e. fall back to the RootPage if the StartPage is empty. This will only be used in Find content indexing job, and just to make the content loader happy.

CatalogRouteHelper.MapDefaultHierarchialRouter use the same technique internally, that’s why if you are using the default hierarchical router, all is well!

It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInShare on Reddit

Leave a Reply

Your email address will not be published. Required fields are marked *