Skip to content

Instantly share code, notes, and snippets.

@klpatil
Created January 15, 2019 16:57
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/244317e8fd1560cf48ff4b8383b0e20b to your computer and use it in GitHub Desktop.
Save klpatil/244317e8fd1560cf48ff4b8383b0e20b to your computer and use it in GitHub Desktop.
Sitecore Indexing Snippets
case "DisableIndex":
stringBuilder.AppendFormat("Sitecore.Configuration.Settings.Indexing.Enabled Status -Before {0} : ",
Sitecore.Configuration.Settings.Indexing.Enabled);
stringBuilder.Append("<br/>");
Sitecore.Configuration.Settings.Indexing.Enabled = false;
stringBuilder.AppendFormat("Sitecore.Configuration.Settings.Indexing.Enabled Status - After {0} : ",
Sitecore.Configuration.Settings.Indexing.Enabled);
stringBuilder.Append("<br/>");
break;
case "EnableIndex":
stringBuilder.AppendFormat("Sitecore.Configuration.Settings.Indexing.Enabled Status - Before {0} :",
Sitecore.Configuration.Settings.Indexing.Enabled);
stringBuilder.Append("<br/>");
Sitecore.Configuration.Settings.Indexing.Enabled = true;
stringBuilder.AppendFormat("Sitecore.Configuration.Settings.Indexing.Enabled Status - After {0} :",
Sitecore.Configuration.Settings.Indexing.Enabled);
stringBuilder.Append("<br/>");
break;
case "PauseIndexing":
IndexCustodian.PauseIndexing();
stringBuilder.AppendFormat("Indexing Paused : {0}",
"");
stringBuilder.Append("<br/>");
break;
case "ResumeIndexing":
IndexCustodian.ResumeIndexing();
stringBuilder.AppendFormat("Indexing Resumed : {0}",
"");
stringBuilder.Append("<br/>");
break;
case "ReIndexTree":
// http://sitecoreunleashed.blogspot.in/2014/06/refresh-tree-partial-re-indexing.html
dbName = QueryString.Current["database"];
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)
{
SitecoreIndexableItem indexableFolder = new SitecoreIndexableItem(rootItem);
if (indexableFolder != null)
{
stringBuilder.Append("Database Name: " + db.Name);
stringBuilder.Append("<br/>Item Path: " + rootItem.Paths.FullPath);
stringBuilder.Append("<br/>Index Name: " + indexableFolder.AbsolutePath);
stopWatch = new System.Diagnostics.Stopwatch();
stopWatch.Start();
IEnumerable<Job> job =
Sitecore.ContentSearch.Maintenance.IndexCustodian.RefreshTree(indexableFolder);
if (stopWatch != null && job.Any())
{
stopWatch.Stop();
stringBuilder.Append("<br/>ReIndexTree Job started successfully! Name : " + job.FirstOrDefault().Name + "<br/>Time Taken: " + stopWatch.Elapsed);
}
}
else
{
stringBuilder.Append("Index is null.");
}
}
else
{
stringBuilder.Append("Root Item is null. Querystring is : itemPath");
}
}
else
{
stringBuilder.Append("Database is null. Querystring is : database");
}
}
else
{
stringBuilder.Append("Please enter database & itemPath querystrings value.");
}
break;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment