Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
IndexRebuild.aspx
<%@ Page Language="C#" AutoEventWireup="true" Inherits="System.Web.UI.Page" Debug="true" %>
<%@ Import Namespace="Sitecore" %>
<%@ Import Namespace="Sitecore.Configuration" %>
<%@ Import Namespace="Sitecore.Jobs" %>
<%@ Import Namespace="Sitecore.Search" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Rebuild database crawlers</title>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ShowIndexes();
}
}
protected void RebuildBtn_Click(object sender, EventArgs args)
{
foreach (ListItem item in cblIndexes.Items)
{
if (item.Selected)
{
var options = new JobOptions("RebuildSearchIndex", "index", Client.Site.Name, new Builder(item.Value), "Rebuild");
options.AfterLife = TimeSpan.FromMinutes(1.0);
JobManager.Start(options);
}
}
}
private IDictionary<string, Index> GetSearchIndexes()
{
var configuration = Factory.CreateObject("search/configuration", true) as SearchConfiguration;
return configuration.Indexes;
}
private void ShowIndexes()
{
foreach (var index in GetSearchIndexes())
{
cblIndexes.Items.Add(new ListItem(index.Key, index.Key));
}
}
public class Builder
{
private readonly string _indexName;
public Builder(string indexName)
{
_indexName = indexName;
}
public void Rebuild()
{
var index = SearchManager.GetIndex(_indexName);
if (index != null)
{
index.Rebuild();
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<thead>
<tr>
<td>Available crawlers</td>
</tr>
</thead>
<tr>
<td>
<asp:CheckBoxList ID="cblIndexes" runat="server">
</asp:CheckBoxList>
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnRebuild" runat="server" Text="Rebuild" OnClick="RebuildBtn_Click" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.