Searching for all descendants of a node with Umbraco 6 and Examine

If you already use the Umbraco Examine add on, you would already know Examine is a very powerful tool for searching for Umbraco nodes.

Unfortunately it does become a little tricky when you need to return a node that has a particular ancestor somewhere up the chain.

On a first attempt one may try to use the property “__Path” which contains a comma delimited string of ancestors to a node. The problem I found with this is that Examine/Lucene will treat this string as one word which makes it unsearchable for individual ancestors.

The work around for this is to create a new index delimited by spaces instead of commas. Below is an example of doing this on the start of your application:

Note, this will run on the start of your application if the index doesn’t already exist. Ie. The index in your “~/AppData/Temp/” folder

For this to work you also need to changes your Examine query analyser from the default whitespace analyser to be “Lucene.Net.Analysis.Standard.StandardAnalyzer” in your ExamineSettings.config as below:

 

Once you have configured your Examine indexer you need to trigger a rebuild of your index. You can do this by executing the code snippet above by:

 

  1. Stopping your application pool to release handles on your index files.
  2. Then delete ~/appdata/temp/ folder and ~/appdata/umbraco.config.
  3. Now your new index “__luceneFriendlyAncestors” will be created once you start your app pool and visit your site.

 

Now use the following code to search for nodes that have a particular ancestor: