A small Lucene hook

I haven’t posted in a while, so I just wanted to add a quick hack I posted earlier on today in the Umbraco Slack channel.

The following is a small hook into Lucene that you can utilise in your Umbraco builds to improve the usability and relevance of your search indexes.

There are a couple of things you can do at this stage. The example in the gist below skips the indexing of any document that is outside of the “Home” node — for example, a settings or widget tree.

After that, I have a document I really want to appear at the top of my search results, so I boost the score of those at the index stage.

You could also, for example, add any supplementary data to your Lucene index which will then be searchable against that document (for example, keywords that belong to a parent document — add the parent category keywords to the product page being indexed).

Now onto the code.

© 2016. All rights reserved.