Skip to content

Instantly share code, notes, and snippets.

@rangler2
Last active June 17, 2022 11:51
Show Gist options
  • Save rangler2/1d2693ec77775328327e3fa9947ad35b to your computer and use it in GitHub Desktop.
Save rangler2/1d2693ec77775328327e3fa9947ad35b to your computer and use it in GitHub Desktop.
Simple aspx script to view or rebuild examine indexes for Umbraco 7 on Azure web app multiple instances autoscaled. Supporting blog post with screenshot - http://andrew.lansdowne.me/2022/06/17/how-to-check-and-rebuild-on-each-node-of-an-umbraco-azure-autoscaled-web-app/
<%@ Page language="c#" %>
<script runat="server" language="c#">
protected void Rebuild(object sender, System.EventArgs e){
if (machineName.Text == Environment.MachineName) {
var index = Examine.ExamineManager.Instance.IndexProviderCollection[indexName.Text];
if (index != null) {
index.RebuildIndex();
Response.Write("<h1>Triggered rebuild of " + index.Name + " on " + Environment.MachineName + "</h1>");
} else {
Response.Write("<h1>Index '" + indexName.Text + "' not found on " + Environment.MachineName + "</h1>");
}
}
else {
Response.Write("<h1>Try again, machine name is not '" + machineName.Text + "'</h1>");
}
}
</script>
<h1>Examine maintenance page</h1>
<p>
Machine name: <%=Environment.MachineName %>
</p>
<h2>Indexes</h2>
<%
foreach (Examine.Providers.BaseIndexProvider index in Examine.ExamineManager.Instance.IndexProviderCollection)
{
var indexer = index as Examine.LuceneEngine.Providers.LuceneIndexer;
var directory = indexer.GetLuceneDirectory();
var reader = Lucene.Net.Index.IndexReader.Open(directory, true);
var noOfDocs = reader.MaxDoc();
Response.Write(index.Name + " = " + noOfDocs + "<br>");
}
%>
<h2>Rebuild tool</h2>
<form runat="server">
<p>
Machine name: <asp:textbox runat="server" id="machineName"/>
</p>
<p>
Index: <asp:textbox runat="server" id="indexName"/>
</p>
<asp:button runat="server" id="btnRebuild" Text="Rebuild index" onclick="Rebuild"/>
<asp:button runat="server" Text="Refresh page" />
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment