Book 390277 1280

This is an Umbraco package I created some time ago and I realized I never got to blog about it or even let people know about it, apart from the one tweet lost in the vast sea of tweets. 

Its purpose is to include lookup field names in index data for specific nodes. By "lookup fields" I mean all those Multi-Node TreePickers (MNTPs) that you have in place, referencing nodes somewhere else in the tree. For a blog post, it might be a list of categories. For a book, a list of authors. For a car, a list of resellers, and so on. Those "lookups" get saved as a list of IDs in the database, but in some cases we might need the actual name(s) to be included as part of the node so that it can appear in search results.

This is equivalent to, let's say, searching for "Terry Pratchett" and finding the author's bio AND a list of books written by the author (although fans probably have them already memorized). In order for Examine to return books written by the author, the author's name (not the node's id) must be part of the underlying Lucene index data.

How does it do that? Well, it just looks up the names of the nodes and then replaces their IDs (which are stored in the MNTP field) with their actual names. It does that as part of the indexing process.

The interesting part is that it doesn't have to do that globally, only where you need it. For this reason you can setup rules (programmatically or via a configuration file or both) to define which document types and which of their MNTP properties will be indexed in this way.

The rules in the configuration file look like this one below, which indicates that documents of type "BlogPost" having a property named "categoryPicker" should be indexed in a way that selected category names are part of the blog post's index data.

<rule docTypeAlias="BlogPost" propertyAlias="categoryPicker"/>

You can also set rules programmatically on application start, like this:

public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
DotSee.ExamineLookupValues.Elv.Instance.RegisterRule(new DotSee.ExamineLookupValues.ElvRule("BlogPost", "categoryPicker"));
}

You can find more and download the package (available as an Umbraco package and also as a Nuget package) here: https://our.umbraco.org/projects/developer-tools/examinelookupvalues/

Just a warning though: This package may seriously slow your site down during a full index rebuild if there's a lot of data and a lot of rules. Actually, it's going against official recommendations on dealing with Examine, but it should be okay for a relatively small number of nodes.