Hi Noel,
If you create your scheduled job to do the nightly rebuild as an Episerver scheduled job then you can trigger that job manually from the CMS admin (in addition to the scheduled runs) which would allow you to rebuild the index when needed rather than waiting for the next scheduled run.
In most cases there are very few scenarios where you would want to clear the index so I generally advise our editors/admins to avoid the "clear index" button.
Hi Paul,
Yeah definitely planning on using episerver's scheduled jobs, so everything you say is true, especially about running it whenever we need, but it leaves a problem...
Essentially, clearing the index breaks functionality on the site, and then if the editor is not aware of the consequences, that functionality will remain broken for too long. Training staff not to press the "break site" button is all fine and good, but we'd like to create solutions in code for these sorts of predictable situations.
Also part of the specification includes a message informing the user that the data is currently not accurate/unavailable during a re-import. Obviously the client doesn't understand why reindexing might affect stuff as we're using Find for its performance, not because the client mandates it. So making things as seamless and as simple for the editor as possible is our goal.
If you want your editors to be able to se, control and reindex those things you should build your own views inside Episerver editor where you show progress, status in index and availability to reindex (or remove from index).
I would recommend to look at my blog post on how to exend the index and then fill it with your implementation
Hi Henrik, your blog post is interesting but I dont see any part relating to how to subscribe to Episerver Find's events, sorry if I'm being thick.
What event do you mean?
There is no event (that I know of) for when someone clears an index or simular
As Henrik said, I'm not aware of any events being fired when the index is cleared so I think the best way to do what you need is to use a scheduled job to periodically check the status of the index and, if it's not in a usable state, reindex it.
If you wanted to do that in a single scheduled job you could do something like this:
[ScheduledPlugIn(DisplayName = "Index Rebuilding Job", DefaultEnabled = true, IntervalLength = 5, IntervalType = EPiServer.DataAbstraction.ScheduledIntervalType.Minutes, GUID = "4425FF7D-1C88-4715-B8B6-308296999F8F")]
public class RebuildIndexJob : ScheduledJobBase
{
private bool _stopSignaled;
public RebuildIndexJob()
{
IsStoppable = true;
}
/// <summary>
/// Called when a user clicks on Stop for a manually started job, or when ASP.NET shuts down.
/// </summary>
public override void Stop()
{
_stopSignaled = true;
}
/// <summary>
/// Called when a scheduled job executes
/// </summary>
/// <returns>A status message to be stored in the database log and visible from admin mode</returns>
public override string Execute()
{
//Call OnStatusChanged to periodically notify progress of job for manually started jobs
OnStatusChanged(String.Format("Starting execution of {0}", this.GetType()));
//Check if we're within 5 minutes of 2AM
if (DateTime.Now.Hour.Equals(2) && DateTime.Now.Minute >= 0 && DateTime.Now.Minute < 5)
{
//Running on a schedule so run indexing
RebuildIndex();
return "Ran on a schedule";
}
//Manually triggered jobs are run in the context of the authenticated user
if (PrincipalInfo.CurrentPrincipal.Identity.IsAuthenticated)
{
//Triggered manually so run indexing
RebuildIndex();
return "Ran manually";
}
if (!IsIndexValid())
{
//Index has been cleared so rebuild
RebuildIndex();
return "Rebuilt empty index";
}
return "Index checked, no action required";
}
/// <summary>
/// Rebuilds the index
/// </summary>
private void RebuildIndex()
{
//Put rebuilding logic here
}
/// <summary>
/// Checks whether the index is in a valid state
/// </summary>
/// <returns>A boolean value indicating whether the index is valid</returns>
private bool IsIndexValid()
{
//Add index validation code here
return true;
}
}
We've a client with a bunch of data we are going to be importing nightly into Find's Index, using POCO's to store data in Find (plain old C# objects, so not creating pages with the data).
My question is this: There is a button to allow re-indexing or clearing the index of Find, but if I'm going to be updating the index nightly, then if they hit "clear index" it wont be suitable for the site to not have data till the scheduled job does the import again that evening, having an 're-index' event would be very useful.
How have others dealt with storing POCO's and still allowing re-indexing to happen whenever the editor requires?