In my post, Sitecore 7 and Language Fallback, among other things, I gave some tips and code for customizing the Lucene Document Builder so that it uses language fallback when creating lucene indexes.
Since then, I have successfully done the same with Solr and wanted to share that here.
What you need to do for this to work right is to:
This was more complicated to override than the Lucene Document Builder, the first reason being that the StoreField and GetFieldConfigurationBoost methods, which are in the out-of-the-box SolrDocumentBuilder, are private. So you can't just override the AddField method and then call StoreField and GetFieldConfigurationBoost. I had to reflect them as well and include copies of them in my class file, trying to keep it as close as possible to the same logic. Unfortunately I yet again ran into an inaccessible method within the StoreField method, this.settings.DefaultLanguage(), so I make an assumption here that 'en' is the default language.
From here, I had three rather significant departures from the original SolrDocumentBuilder.cs and the Lucene Document Builder I gave previously:
// recursive method to keep checking for value in fallback items
// until we find a value or until we reach an item that no longer falls back
public static string GetSitecoreFallbackValue(Item item, Field fld)
string currentValue = "";
// Cannot check 'item.Fields[fld.ID].HasValue' first, because it returns false
// even though '.Value' will return a value in situation where standard values on the template comes into play
if (item.Fields[fld.ID] != null)
var value = item.Fields[fld.ID].Value;
var fallbackItem = item.GetFallbackItem();
if (fallbackItem != null)
//Recursive call to get the item that has value for the particular field.
currentValue = GetSitecoreFallbackValue(fallbackItem, fld);
// TODO: Need comment
else if (fieldType.Name == "Guid" && ID.IsID(thisFieldValue))
fieldValue = ShortID.Encode(thisFieldValue).ToLowerInvariant();
The code for this can be found here:
PS: You'll also find a version of SearchHelper.cs that includes some customizations made for working with Solr, including a different way to search location, a workaround for forcing exact match searches that contain special characters for text fields and strings, non-plural searches that need to still find a match even if the non-plural version of the word does not actually exist within the content, and field boosting.
Hi Elizabeth, Great post. When reviewing your code on GitHub I found a reference to this class/method in the updated SearchHelper Verndale.SharedSource.Utilities.TextUtilityStatic.GetSingular It doesn't appear that its included in the Verndale.SharedSource project. Could you by chance update with this file? Thanks, Jay