Surendra Sharma

Surendra Sharma

Search This Blog

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.

Sunday, March 13, 2016

The mobile mind shift

Here is an analysis of session “The mobile mind shift” presented by Ted Schadler who is VP , Principal Analysts and Coauthor of The mobile mind shift. 

·         Most important point of this presentation is - Only content in context can deliver great mobile moments
·         The face of the world is changed by mobile. More particularly it was changed by – iPhone. Where developers like you and me developed Apps.
Mobile device is tiny, touch based, it’s always in your pocket, connected to internet and its knows your location.
By using these characteristics of mobile how a company can serve their customer better?
·         Main Agenda of this presentations is focus on
o    What is mobile mind shift?
o    What’s the critical role of context in mobile moments?
o    How can you find mobile moments and their context?
o    What technology will you need?

What is mobile mind shift?

·         Smartphone reached to almost everybody. According to Forrector Research World mobile and smartphone adoption forecast, up to 2016(First quarter), there are more than 230 million unique smartphone subscribers. The number is increasing day by day.
·         People using their mobile and tablets in home, office, even in their bedroom and bathroom. So mobile devices means a mobile life.
·         The demand for mobile apps and websites is generations based. What it means? A different age group people want companies must have a website which they can visit. Similarly they expect companies to have a mobile apps as well. These people want their experience to change based on their need and location which play an important role to provide better experience.
·         In general people browsing websites on an average for 3 minutes where a websites have lots of stuff, images etc. Out of these 3 minutes, some seconds are required to load the page. On mobile, information takes some milliseconds to load and on an average people focus on that information page for 30 seconds. While on smart watches, people look for on an average 3 seconds as it provide more precious information.
This all experience called mobile mind shift – The expectation that I can get what I want in my immediate context and moments of need.
·         What kind of experience changing here for customer. A customer expect 3 things - immediacy, simplicity and context. Overall a consumer wants convenience.
·         Immediacy + Simplicity + Context = Convenience
·         How a convenience can be achieved? For this innovators target mobile moments
o    A mobile moment is a point in time and space when someone pulls out a mobile device to get something they want in their immediate context. For example searching for nearby hotel, restaurant etc.
·         Mobile moments are pervasive i.e. they are applicable for all the customers whether they are at home, business, travel etc. At the same time these moments are powerful ways to focus on customer requirement. For example think about journey map in the context of mobile moment.
o    You are booking your flight tickets before few days of your journey.
o    Before few hours, you are check-in, access lounge, find a gate etc
o    In flight, you are ordering food, order movies, check ETA etc.
o    Once you reached at destination, you have to book a taxi etc.
o    After few days, you filled a customer service survey etc.
          In all these moments, applications have to handle three things
o    Who are we serving?
o    What is their context?
o    What is the motivation?

What’s the critical role of context in mobile moments?

·         In general there 1.5 million apps on mobile but there are 1000 million websites are web. So there is a large gap for websites where we don’t have equivalent apps.
·         On an average people don’t want more than 26 apps in their mobile however on an average they visit 52 websites monthly.
Responsive websites don’t deliver much information on mobile. These small mobile websites does not deliver great mobile moments.
So Personalization and contextual specific content delivery is the key here to serve your customer in better way and to improve mobile user experience.
·         We can achieve this by what customer want and what we deliver through contextual experiences.
·         What is context here?
o    The sum total of everything we know about customer based on her behavior, history, the environment and what she shared.
·         Context in action
o    Personalize web and mobile experiences
o    Target mobile moments based on locations
o    Send notifications based on time or location
o    Build profiles on the fly for segmentation
o    Even connected cars can embrace context

How can you find mobile moments and their context?
·         Use the IDEA cycle for agility. This cycle helps to build platform for agility
o    Identify the mobile moments and context
§  Who is seeking help
§  What kind of device
§  What is het context
§  What can you do to server her in that moment

§  Technics for finding moments
·         Survey research
·         Ethnographic research
·         Journey mapping
·         Ride-along investigations
·         Instrument to measure engagement
o    Define the mobile engagement – their tasks and your goals
§  Based on value to your business Vs value to your customer
o    Engineer your processes, platform and products for mobile moments
§  Are your technology platform ready to support mobile engagement?
§  Are your business processes designed for mobile moments?
§  Are your people recognized understand and iteratively deploy mobile services?
o    Analyze to optimize outcomes and improve the customer experience
§  Check real-time, operational, historical metrics for technology, engagement and business.

What technology will you need?
·         The need for content in context drives the biggest tech investment. We have to concentrate here on WCM, analytics majorly.
A digital experience platform need to develop to provide content according to context.