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.
How To Manually Rebuild The Examine Index
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.
How To Rebuild The Examine Index In Code
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:
To rebuild all the indexes, you can use this snippet:
If you're unsure how to get Umbraco to this cod eon application start-up, I recommend reading, The Umbraco ApplicationEventHandler Explained