Skip to content

Instantly share code, notes, and snippets.

@klpatil
Created January 15, 2019 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klpatil/799fb0358baed63df582b6e6b018f2ca to your computer and use it in GitHub Desktop.
Save klpatil/799fb0358baed63df582b6e6b018f2ca to your computer and use it in GitHub Desktop.
Rebuild Index
string dbName = QueryString.Current["database"];
string itemPath = QueryString.Current["itemPath"];
if (!string.IsNullOrWhiteSpace(dbName) && !string.IsNullOrWhiteSpace(itemPath))
{
Sitecore.Data.Database db = Sitecore.Configuration.Factory.GetDatabase(dbName);
if (db != null)
{
rootItem = db.GetItem(itemPath);
if (rootItem != null)
{
//Sitecore.Search.Index index = Sitecore.Search.SearchManager.GetIndex("sitecore_master_index");
var index = rootItem.GetIndex();
if (index != null)
{
stringBuilder.Append("Database Name: " + db.Name);
stringBuilder.Append("<br/>Item Path: " + rootItem.Paths.FullPath);
stringBuilder.Append("<br/>Index Name: " + index.Name);
stopWatch = new System.Diagnostics.Stopwatch();
stopWatch.Start();
index.Rebuild();
if (stopWatch != null)
{
stopWatch.Stop();
stringBuilder.Append("<br/>Indexing Done Successfully!!!" + "<br/>Time Taken: " + stopWatch.Elapsed);
}
}
else
{
stringBuilder.Append("Index is null.");
}
}
else
{
stringBuilder.Append("Root Item is null.");
}
}
else
{
stringBuilder.Append("Database is null.");
}
}
else
{
stringBuilder.Append("Please enter database & itemPath querystrings value.");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment