The default search provider that comes with Umbraco is called Examine. Under the hood, Examine uses a very popular search engine called Lucene. Out of the box, Lucene is configured to index all of your Umbraco pages and then when your website loads, it goes off, does its thing, builds your index and then stores that index within the file structure of your webroot. In today's tutorial, I'm going to quickly cover the different options that you have available to you in order to rebuild your Examine indexes.
If you've never had a peek in your Umbraco's website's config folder I recommend that you have a quick peek now. In there, you'll see two files, one called 'ExamineIndex.config' and the other called 'ExamineSettings.config'. The index file is the file that tells Lucene what to index. The settings file tells Lucene how to integrate the indexes into Umbraco.
If you look into the 'ExamineIndex.config' you should see a number of indexes each with an 'IndexPath' defined. This path is where the index files are stored within your webroot. So, the manual way to rebuild your indexes is to go onto the server and manually delete them. Note, you may need to do an IISRESET after you delete the index, but, most of the time you can probably get away without performing one. This isn't a very elegant way, but it works.
If you can't easily access your server, for example, if you're using Azure, then you might want to rebuild your index on application start, or, via a custom page within the Umbraco backend. The code to rebuild a specific index is shown below:
var indexName = "SiteContentIndexer";
To rebuild all you indexes, you can use this snippet:
ExamineManager.Instance.IndexProviderCollection.ToList().ForEach(index => index.RebuildIndex());
If you're unsure how to get Umbraco to this cod eon application start-up, I recommend reading, The Umbraco ApplicationEventHandler Explained
Software Architect, Programmer and Technologist Jon Jones is founder and CEO of London-based tech firm Digital Prompt. He has been working in the field for nearly a decade, specializing in new technologies and technical solution research in the web business. A passionate blogger by heart , speaker & consultant from England.. always on the hunt for the next challenge