In this blog series about Language Fallback, I have been discussing what language fallback is all about, how to install and configure the fallback module, helpful customizations that can be added to it, and required customizations for using it with the Dictionary and other modules.
Two modules that could easily make their way into a Sitecore solution together are Alex Shyba's Partial Language Fallback Module and his Advanced Database Crawler (ADC).
Please note that ADC is unnecessary for versions of Sitecore 7 and above and in fact won't work correctly.
I've found both to be integral in the solutions that I have implemented in recent years. As you may know, the ADC leverages indexing, where upon publish, a crawler will grab the values from the fields of the items and add them to the index.
This index can be used to query the data in a faster, more efficient manner compared to constantly hitting the Sitecore database. In areas of the site where you are searching content, or listing content of a specific template, etc, it would make sense to use ADC's GetItems methods, instead of navigating the Sitecore content tree. One parameter of the GetItems method is for language and out-of-the-box, ADC will retrieve the correct values of the fields of an item for the language passed in.
When language fallback comes into play though, ADC needs an update. When you add a new version of an item in a different language and leave all of the fields as is, they are null in the database. This is what tells the fallback code to look at the language it falls back to and display those values instead. If the ADC crawler is not updated to check fallback as well, then when the item is indexed by the crawler, it would only save the values that are overridden and explicitly set for that language version. If you have an 'About Us' page in 'en', create a German 'de-DE' language version, and allow the fields to fallback, the index would not save any values for that page in German. When a search is run on the front end for 'About' while viewing the site through the context for 'de-DE', the About Us page will NOT be returned in the results.
The crawler needs to be updated in ADC so that as it indexes each field, it will check if it falls back, gets the fallback value, and saves that value instead to the index for that language.
Assuming you have downloaded the source code of the Advanced Database Crawler, you will need to modify and add some code.
First, in the AdvancedDatabaseCrawler.cs file, go to the FilteredFields method:
protected virtual List<SCField> FilteredFields(Item item)
The following line should be commented out:
And instead it should be replaced with the following:
foreach (SCField field in item.Fields)
var currentItem = item;
currentItem = CrawlerHelper.GetSitecoreFallbackItem(item, field);
if (currentItem.Fields[field.ID] != null)
Within a new CrawlerHelper class, we have the method, GetSitecoreFallbackItem. It essentially checks if the field in the language version of the item has a value. If it does, great, return it. Otherwise, use item.GetFallbackItem extension method (extension added via the Fallback module code) to get the fallback language version of the item and pass it into a recursive call to GetSitecoreFallbackItem. This will eventually return a value, if one exists, and that is what will get saved to the index.
Once this code is added to the ADC solution, you can compile and use that dll in your Sitecore solution instead of the original compiled dll that came with the ADC package.
I'd like to acknowledge my amazing co-worker Summit Phadke here. He and I discovered and talked through this issue together and he ultimately came up with and tested the solution for one of our clients.
Link to Resources: