Surendra Sharma

Surendra Sharma

Search This Blog

Monday, June 27, 2016

Sitecore Template Report Generator Module at Sitecore MarketPlace



Developers don’t like documentation specially when they have to do itJ, but documentation is equally important for project and organization.

It’s always great if there are tools for generating documents.

I created one such tool which is available on Sitecore MarketPlace and its my first Sitecore tool.

The Sitecore Template Reporting Tool allows you to generate documentation of the templates in the HTML form.

Without this tools a developer require around 10-20 hours to generate such a report depending upon number of templates. However by using this tool one can generate better reports within a minute which ultimately save your time and impress your manager/client with the report.

Steps to generate the report

·         Download and install Sitecore package
·         Package install web page and DLL in bin directory
·         Access your Sitecore instance or website by http://<Instance Name>/TemplateReportGenerator.aspx
·         All template folders are listed in Dropdown list

 
 
·         Select one of the template folder for which report need to be generated
·         Click on "Generate Report" button
·         Your report is ready.


This tool generates report in tabular format.
Each template details are displayed in alternate color.
Each template details display as section wise which include below details
·         Template ID
·         Template Created Date time
·         Template Last modified Date time
·         Field names
·         Field Title
·         Field Description
·         Field Type
·         Is Shared Field
·         Is Unversioned


You can also change report aspx file as per your need however I tried my best to include all the details.


In future I have plans to create more such helpful tools. 

Let me know for any query / suggestion / improvements.

Friday, June 10, 2016

How to rebuild index programmatically in Sitecore



We have DR(Disaster Recovery) environment and everyday SQL job taking Production WEB database backup and restoring it on next day on our DR SQL server.

We are using SOLR search in our project.

Due to this database restoration, index rebuild is required for SOLR search. Initially we are doing indexing manually on daily basis.

But later on I make this rebuild process automatically.

Solution:
The easiest way to rebuild an index automatically is to create a scheduled agent that will call and run the below code.

There are two questions before do it automatically.
·         Do you want to rebuild particular items and its children?
·         Do you want to rebuild full indexing?

Rebuild Particular Item and its children

You can use Refresh() method that will take few minutes for execution:
/// <summary>
/// Rebuild Index
/// </summary>
/// <returns></returns>
public string RebuildIndex()
{
    string result = string.Empty;

    try
    {
        result = "Custom Index Rebuild Process Start : " + System.DateTime.Now.ToString() + System.Environment.NewLine;

        foreach (Sitecore.Caching.Cache cache in Sitecore.Caching.CacheManager.GetAllCaches())
        {
            cache.Clear();
        }

        result += "Cache completed : " + System.DateTime.Now.ToString() + System.Environment.NewLine;

        Sitecore.ContentSearch.ISearchIndex index = Sitecore.ContentSearch.ContentSearchManager.GetIndex("sitecore_web_index");
        if (index != null)
        {
            result += "Home Indexing : " + System.DateTime.Now.ToString() + System.Environment.NewLine;

            string homeID = "{97FF4F41-A5FD-4BC3-838F-6A01E0E26B18}";   //Home
            index.Refresh(new Sitecore.ContentSearch.SitecoreIndexableItem(Sitecore.Data.Database.GetDatabase("web").GetItem(new Sitecore.Data.ID(homeID))));

        }

        result += "Indexing completed : " + System.DateTime.Now.ToString() + System.Environment.NewLine;
    }
    catch (System.Exception ex)
    {
        result += ex.ToString() + System.Environment.NewLine;
    }

    Sitecore.Diagnostics.Log.Error(result, this);

    return result;
}
               
Rebuild Full Indexing

You can use Rebuild() method that will also take few minutes for execution.

Sitecore.ContentSearch.ISearchIndex index = Sitecore.ContentSearch.ContentSearchManager.GetIndex("sitecore_web_index");
if (index != null)
{
index.Rebuild(Sitecore.ContentSearch.IndexingOptions.ForcedIndexing);
}

What’s the difference between Rebuild() and Refresh() method?

The Refresh method allows you to update the full index or a part of it. The FullRebuild method deletes the index completely and builds it starting from the root.

The Refresh method also seems to be correct method to update the index, but if you need to rebuild the index completely, try Rebuild(Sitecore.ContentSearch.IndexingOptions.ForcedIndexing) - you should see the changes after as it forces the index rebuild.

Please leave your comments or share this trick if it’s useful for you.