We are using Solr 5.4 and Sitecore 8.2 we plan to do daily/Weekly Rebuild of Indexes for Web Environment through Sitecore Job or Tasks. Can some body suggest me what is best way to do this
Note : We are already using PublishOnSync strategy
Cheers
Sitecore Stack Exchange is a question and answer site for developers and end users of the Sitecore CMS and multichannel marketing software. It only takes a minute to sign up.
Sign up to join this communityWe are using Solr 5.4 and Sitecore 8.2 we plan to do daily/Weekly Rebuild of Indexes for Web Environment through Sitecore Job or Tasks. Can some body suggest me what is best way to do this
Note : We are already using PublishOnSync strategy
Cheers
I did something similar to this not long ago to rebuild the sitemaps of 800+ sites. I used the Sitecore scheduled tasks.
namespace Sitecore.Sitemaps.Tasks
{
class GenerateSitemaps
{
public void Execute(
Sitecore.Data.Items.Item[] items,
Sitecore.Tasks.CommandItem command,
Sitecore.Tasks.ScheduleItem schedule)
{
// This is where you all your indexing code
var sitemapService = new SitemapService();
sitemapService.RebuildAllSitemaps();
}
}
}
Go to the path /sitecore/system/Tasks/Commands/
and create a new command item. In type enter the class you created above. i.e. Sitecore.Sitemaps.Tasks.GenerateSitemaps, Sitecore.Sitemaps
. In method enter Execute
Go to the item /sitecore/system/Tasks/Schedules/
and create a new schedule. For the command, select the command item you created above. The schedule field is a little hard to understand, but it makes sense in the end. The text below I borrowed from this page.
The Schedule field can be a bit tricky. You’ll notice in my example above that I have several piped values. They are defined as follows:
The start date in yyyyMMdd format.
The end date in yyyyMMdd format.
The days of the week that the task should be run. Each day is assigned a value: 1 = Sunday, 2 = Monday, 4 = Tuesday, 8 = Wednesday, 16 = Thursday, 32 = Friday, and 64 = Saturday. For example to run a task Monday through Friday you’d enter 62 (2 + 4 + 8 + 16 + 32). I have my task set up to run every day (1 + 2 + 4 + 8 + 16 + 32 + 64 = 127).
- The minimum interval the task is to be run in HH:mm:ss format. The example above is set to run once every 24 hours.
Thats it. Now on a schedule basis your indexing code will run.
If you need the code to rebuild an index, its pretty straight forward.
IndexCustodian.FullRebuild(ContentSearchManager.GetIndex("[INDEX NAME]"), true);