Thursday, December 22, 2016

Configure solr for sitecore 8.1 initial version

Hi All,
     Today I am going to tell you about how to configure the Solr instead of lucene.
Here we using solr via Tomacat server. So these points I need to cover.
·         Install/Configure the tomcat
·         Install/Configure solr
·         Configure for sitecore

Install Tomcat:
1. Install Java jre from below URL:
http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html
2. Install Windows Service Installer for apache tomcat from below URL:
http://tomcat.apache.org/download-80.cgi
Note: Please select host manager option ticked and default location for tomcat is:
C:\Program Files\Apache Software Foundation\Tomcat 8.0
The default port used by Tomcat is 8080 (used to be 8983) but you may elect to use some other port. Don’t choose port 80.
Note: If you want run more then one tomcat on on system then use different connector port and shutdown port.
Eg: connector port: 8983, 8038, 8039 etc.
Shutdown port: 8005, 8025 etc.
3. Type configure tomcat and select automatic mode.
4. you can also select for alias name for tomacat by update in conf/server.xml in tomcat directory.
<Alias>tomcat</Alias>

Install Solr:
Download Solr 4.10.3 from http://lucene.apache.org/solr/downloads.html. Since we are installing on a Windows machine, you will want to get the .zip file version of the download.
Note: Archives for all past versions of Solr are available at the Apache archives.
1.   Extract the contents of the .zip to a temporary location of your choice.
2.   Find the \dist folder in the extracted solr-4.10.3 directory. Rename the solr-4.10.3.war to solr.war and copy the file to the Tomcat’s \webapps folder. The path in my environment was C:\Program Files\Apache Software Foundation\Tomcat 8.0\webapps.
3.   Create an empty Solr home folder. This will be the permanent place of residence on your machine for your Solr instance. For example, D:\solr is where I put my Solr instance.
4.   Find the \example\solr folder in the extracted solr-4.10.3 directory. Copy the contents of \example\solr to the empty Solr home folder you just created in step 4.
5.   Find the \example\lib\ext folder in the extracted solr-4.10.3 directory. Copy the contents of \example\lib\ext to Tomcat’s \lib folder. The path in my environment was C:\Program Files\Apache Software Foundation\Tomcat 8.0\lib.
6.   Set the home directory for Solr in Tomcat. This is done by adding a new Java option with the Monitor Tomcat program. In my case, the option was -Dsolr.solr.home=D:\solr
7.   Stop/start Tomcat and try browsing to your Solr instance. For example, http://tomcat:8983/solr.

Configure for Sitecore:
1.   Stop the Tomcat service.
2.   Go to the root of your Solr instance, in my case, D:\solr. We need to modify the "collection1" directory to serve as one of the cores (folders with config files and index data) required by Sitecore.
a.   Rename the folder to "sitecore_analytics_index"
b.   Inside the folder you will find a file called “core.properties” which you may edit with a text editor. You need to change the “name” value to the name of your core. For example, when I create the “sitecore_analytics_index” core, then I will edit the “core.properties” file to have the value name=sitecore_analytics_index

3.      Start the Tomcat service and visit the Solr administration page. You may need to reload your browser page if it was already up. Click on the “Core Admin” menu item. If you modified the old “collection1” core correctly you should now see a sitecore_analytics_index core.




4.   Stop the Tomcat service. Now we need to fix the schema of our “sitecore_analytics_index” core, otherwise Sitecore cannot parse the xml correctly. Edit the file at \sitecore_analytics_index\conf\schema.xml according to Sitecore’s knowledge base article: https://kb.sitecore.net/articles/227897. Don’t forget to define the field type for pint since we are using a version of Solr later than 4.9! Start Tomcat and reload the Core Admin page.
5.   Next we must generate a new, Sitecore-specific schema. Sitecore provides a tool for this. Navigate to the Control Panel of your Sitecore instance. Look for the “Generate the Solr Schema.xml file” link and click it. Provide a path for the source and target files (they can’t be the same file.) Once you have generated your new schema, replace the old schema with it. Restart the Tomcat service and make sure the core loads correctly.
6.   A vanilla install of Sitecore 8 update 2 requires 13 cores to work correctly. So far we have one, but don’t despair, now that we have a generated a schema this process is much easier.  Essentially, we are going to use our sitecore_analytics_index core as a template to create the others. To do this:
a.   Copy the sitecore_analytics_index folder.
b.   Repeat steps 2a and 2b for each copy.
c.   When you are done, your Solr home folder should contain the following cores


d.   If you have done everything correctly you should be able to restart Tomcat and see all the cores listed above on the Core Admin page.
7.   Update (3-7-2015): I decided to create a PowerShell shortcut for this step. Save yourself time!

Still with me? Hang in there, we are halfway home! Next, we must tell Sitecore to start using Solr instead of Lucene. This is done by appending or removing “disabled” as an extension of a configuration file’s name.
a.   Config files to DISABLE:

\App_Config\Include\Sitecore.ContentSearch.Lucene.DefaultConfigurations.config.disabled
\App_Config\Include\Sitecore.ContentSearch.Lucene.Index.Analytics.config.disabled
\App_Config\Include\Sitecore.ContentSearch.Lucene.Index.Core.config.disabled
\App_Config\Include\Sitecore.ContentSearch.Lucene.Index.Master.config.disabled
\App_Config\Include\Sitecore.ContentSearch.Lucene.Index.Web.config.disabled
\App_Config\Include\Sitecore.ContentSearch.Lucene.Indexes.Sharded.Core.config.example (left as is)
\App_Config\Include\Sitecore.ContentSearch.Lucene.Indexes.Sharded.Master.config.example (left as is)
\App_Config\Include\Sitecore.ContentSearch.Lucene.Indexes.Sharded.Web.config.example (left as is)
\App_Config\Include\Sitecore.Marketing.Definitions.MarketingAssets.Repositories.Lucene.Index.Master.config.disabled
\App_Config\Include\Sitecore.Marketing.Definitions.MarketingAssets.Repositories.Lucene.Index.Web.config.disabled
\App_Config\Include\Sitecore.Marketing.Definitions.MarketingAssets.Repositories.Lucene.IndexConfiguration.config.disabled
\App_Config\Include\ContentTesting\Sitecore.ContentTesting.Lucene.IndexConfiguration.config.disabled
\App_Config\Include\FXM\Sitecore.FXM.Lucene.Index.DomainsSearch.config.disabled
\App_Config\Include\ListManagement\Sitecore.ListManagement.Lucene.Index.List.config.disabled
\App_Config\Include\ListManagement\Sitecore.ListManagement.Lucene.IndexConfiguration.config.disabled
\App_Config\Include\Social\Sitecore.Social.Lucene.Index.Master.config.disabled
\App_Config\Include\Social\Sitecore.Social.Lucene.Index.Web.config.disabled
\App_Config\Include\Social\Sitecore.Social.Lucene.IndexConfiguration.config.disabled

b.   Config files to ENABLE:

\App_Config\Include\Sitecore.ContentSearch.Solr.DefaultIndexConfiguration.config
\App_Config\Include\Sitecore.ContentSearch.Solr.Index.Analytics.config
\App_Config\Include\Sitecore.ContentSearch.Solr.Index.Core.config
\App_Config\Include\Sitecore.ContentSearch.Solr.Index.Master.config
\App_Config\Include\Sitecore.ContentSearch.Solr.Index.Web.config
\App_Config\Include\Sitecore.Marketing.Definitions.MarketingAssets.Repositories.Solr.Index.Master.config
\App_Config\Include\Sitecore.Marketing.Definitions.MarketingAssets.Repositories.Solr.Index.Web.config
\App_Config\Include\Sitecore.Marketing.Definitions.MarketingAssets.Repositories.Solr.IndexConfiguration.config
\App_Config\Include\ContentTesting\Sitecore.ContentTesting.Solr.IndexConfiguration.config
\App_Config\Include\FXM\Sitecore.FXM.Solr.Index.DomainsSearch.config
\App_Config\Include\ListManagement\Sitecore.ListManagement.Solr.Index.List.config
\App_Config\Include\ListManagement\Sitecore.ListManagement.Solr.IndexConfiguration.config
\App_Config\Include\Social\Sitecore.Social.Solr.Index.Master.config
\App_Config\Include\Social\Sitecore.Social.Solr.Index.Web.config
\App_Config\Include\Social\Sitecore.Social.Solr.IndexConfiguration.config

8.   So I know that last step was pretty tedious, but if you've made it this far then the rest will be easier. Download the Solr Support Package from Sitecore and extract the contents of the zip file.
9.   Copy the following DLLs from the Solr Support Package into the \bin folder of your Sitecore Instance [N.B.: Castle Windsor is my Inversion of Control preference as Glass also uses it. Aside from Castle Windsor, Sitecore supports AutoFac, Ninject, StructureMap, and Unity.]:

o    Castle.Facilities.SolrNetIntegration.dll
o    Microsoft.Practices.ServiceLocation.dll
o    Sitecore.ContentSearch.Linq.Solr.dll
o    Sitecore.ContentSearch.SolrProvider.CastleWindsorIntegration.dll
o    Sitecore.ContentSearch.SolrProvider.dll
o    SolrNet.dll

Update (3-3-2015): If you are upgrading from Sitecore 8 update 1, then you only need to replace Sitecore.ContentSearch.SolrProvider.XXXXXIntegration.dll with the latest version from the Solr Support Package. All other DLLs remain unchanged.


10.          Download the Nuget package for Castle Windsor. Unzip the package by renaming the extension from .nupkg to .zip and extracting its contents. Copy the Castle.Windsor.dll from \lib\net40-client to the \bin folder of your Sitecore instance.
11.          Repeat step 10 for the Castle.Core Nuget package. Copy the Castle.Core.dll from \lib\net40-client to the \bin folder of your Sitecore instance.
12.          Since we are going to use IoC, we need to make our Sitecore instance aware of it by replacing the Application directive in the global.asax file with the following:

<%@Application Language='C#' Inherits="Sitecore.ContentSearch.SolrProvider.CastleWindsorIntegration.WindsorApplication" %>

13.          In order for Sitecore to talk to Solr, we need to give it a URL. This setting is maintained in the Sitecore.ContentSearch.Solr.DefaultIndexConfiguration.config file (remember, your address may differ from mine):

<setting name="ContentSearch.Solr.ServiceBaseAddress" value="http://tomcat:8983/solr" />

14.          When you browse to your Sitecore site you won't encounter any yellow screens of death. If you see a YSOD complaining about "Connection error to search provider [Solr] : Unable to connect to [http://tomcat:8983/solr]" then you are likely either missing a core or made typo when creating one. Assuming you are error free, the final step is to re-index. Go to the Control Panel and look for the "Indexing manager" link. Select all indexes and click the "Rebuild" button.

Note: Might be you face conflict in Castle.core and Castle.windsor dll because there different-2 version used by solr and glassmapper so you need to update the assembly binding in web.config for overcome that issue as below:

<dependentAssembly>
        <assemblyIdentity name="Castle.Windsor" publicKeyToken="407dd0808d44fbdc" culture="neutral" />
        <bindingRedirect oldVersion="3.1.0.0-3.1.9.0" newVersion="3.3.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Castle.Core" publicKeyToken="407dd0808d44fbdc" culture="neutral" />
        <bindingRedirect oldVersion="3.1.0.0-3.1.9.0" newVersion="3.3.0.0" />
 </dependentAssembly>

References:


Wednesday, October 26, 2016

Sitecore Content Migrator

Hi All,

Today we discuss about Sitecore Sidekick – Content Migrator which is useful for migrate content or sync content from another server.

For this follow below links:

For install in solution:
or run below nugget command:
Install-Package SitecoreSidekickCore -Version 1.0.0
After install the module update the server list from zSCSContentMigrator.config file under
<servers hint="raw:BuildServerList">
                   <server>[enter server 2 url here i.e. https://sitecore-dev]</server>
</servers>

In this list fill the hostname of server from which you want to pull sitecore content.
Now follow these below steps:

Step 1:
Select a server.  A white list of servers is configured in the content migrator config file.  Keep in mind that the target server also needs to have the content migrator installed on it.
Step 2:
Select an item.  Select the main item to be pulled over from the remote server.
Step 3:
Configure options for your operation.
1.   Migrate all children of selected item.
1.    You would uncheck this option if you only wanted a single item.
2.   Overwrite all existing content with new content from the server.
1.   You would uncheck this option if you had content on the local server that you would rather not have deleted but you wanted to gather all new content items.
3.   If parent doesn’t exist locally add that too.
1.   You would uncheck this option if you only wanted the selected item or it’s children.
4.   Make the local content tree mirror the remote content tree.
1.   You would check this option if you wanted to get rid of all local content in favor for the content from the target, this would commonly be the case if you wanted to overwrite QA or Dev content with production content and dispose of the clutter.
Step 4:
Configure advanced sitecore options.
1.   Run using the event disabler.
1.   Unchecking this option will make all events run when installing, moving, deleting, etc.. Items.  This can slow down the operation but if you have lots of important custom on save events, it might be important.
2.   Checking this option will eliminate all events, this can greatly increase speed on installation.
2.   Run using the bulk update context.
1.   Unchecking this option will make the operation run without the bulk update context.  This makes it update the search indexes for each operation, as well as likely other side processes (it’s kind of a black box, if anyone can clarify further please comment).
2.   Checking this option will make the operation skip all index updates.  This is a good idea if you’re updating a lot of content at one time, just don’t forget to run an index rebuild when you’re done.
Step 5:
Select your operation type
1.   Pull – Execute the operation immediately.
2.   Preview – Execute an estimation of the results where no actual changes are made.  Note that this isn’t 100% accurate as some insertion operations could result in unforeseen errors.


Wednesday, September 28, 2016

Sitecore Command Template

Hi All,

Today we discuss about command template.
Command Template: allow insert of items according to logic rather than predefined structures.
Command template define a class and method to be called during an insert operation. Unlike data templates and branch templates, which consist of predefined structures, command templates reference Sitecore UI commands to invoke wizards or other logic used to create new items.


We can create a command template that displays no user interface, a command template that uses a JavaScript prompt to collect an item name, or a command template that displays an ASP.NET or Sitecore Sheer user interface.

We can assign command templates along with data templates and branch templates using insert options.
Following example demonstrates creation of a command template which would check if a folder with current year name exists under main item “News”  and add a “News Item” in that folder. This example uses a JavaScript prompt to collect News Item name.

Step 1: Create two templates “News” & “News Item” with required fields.

Step 2: Create a class that inherits from Sitecore.Shell.Framework.Commands.Command, and override the Execute() method.

namespace BasicSitecore.Custom_Code
{
    public class NewsItemCommand : Sitecore.Shell.Framework.Commands.Command
    {
        public override void Execute(Sitecore.Shell.Framework.Commands.CommandContext context)
        {
        }
    }
}

Step 3: Add a /configuration/command element to the file /App_Config/Commands.config.



Step 4: Insert a command template definition item using /System/Branches/Command Template data template.



Step 5: In the command template definition item, in the Data section, for the Command field, enter the command code.



The parameter id=$ParentID passes the ID of the item under which the user is inserting a new item. Without this parameter, Sitecore would pass the ID of the selected item rather than the item the user right-clicked.

Step 6: Assign this command template to standard values of the “News” template insert option created in step1.


Step 7: Create a new aspx page in “/sitecore modules/shell” With name News.aspx because we give reference of this page in command class code.










Step 8: Complete required code in the command class.

public override void Execute(Sitecore.Shell.Framework.Commands.CommandContext context)
        {
            if (context.Items != null && context.Items.Length > 0)
            {
                Item contextItem = context.Items[0];
                NameValueCollection parameters = new NameValueCollection();
                parameters["id"] = contextItem.ID.ToString();
                parameters["name"] = contextItem.Name;
                parameters["database"] = contextItem.Database.Name;
                parameters["language"] = contextItem.Language.ToString();
                Sitecore.Context.ClientPage.Start(this,"Run", parameters);//Run method executes on

            }
        }
        protected void Run(Sitecore.Web.UI.Sheer.ClientPipelineArgs args)
        {
            if (args.IsPostBack)
            {
                if (!(String.IsNullOrEmpty(args.Result)) && (args.Result != "undefined") && (args.Result != "null"))
                {
                }
            }
            else
            {
                Sitecore.Text.UrlString url = new Sitecore.Text.UrlString("/sitecore modules/shell/News.aspx");
                url.Append("id", args.Parameters["id"]);
                url.Append("database", args.Parameters["database"]);
                Sitecore.Context.ClientPage.ClientResponse.ShowModalDialog(url.ToString(), true);
                args.WaitForPostBack(true);
            }
        }   

Step 9: Handle “OK” and “Cancel” buttons of the user interface News.aspx

protected void btnOK_Click(object sender, EventArgs e)
        {
            if (! String.IsNullOrEmpty(txtNewsItem.Text))
            {
                Sitecore.Data.Database currentDatabase = Sitecore.Configuration.Factory.GetDatabase(Sitecore.Web.WebUtil.GetQueryString("database"));
                Item parentItem = currentDatabase.GetItem(Sitecore.Web.WebUtil.GetQueryString("id"));
                if (parentItem != null)
                {
                    //check if News item contains a folder with current year
                    Item[] children = parentItem.Axes.GetDescendants();
                    Item currentYearItem = children.Where(x => x.TemplateName == "Folder" && x.Name == DateTime.Now.Year.ToString()).SingleOrDefault();
                    if (currentYearItem == null)
                    {
                        Sitecore.Data.Items.TemplateItem folderTemplate = currentDatabase.GetTemplate(Sitecore.TemplateIDs.Folder);
                        if (folderTemplate != null)
                        {
                            Item i = parentItem.Add(DateTime.Now.Year.ToString(), folderTemplate);
                            currentYearItem = i;
                        }
                    }
                    //create a news item and add it to the current folder
//Enter your template ID for news item
                    Sitecore.Data.Items.TemplateItem newsItemTemplate = currentDatabase.GetTemplate(new Sitecore.Data.ID("{42B8742F-FD44-4310-8717-39F1CD1EA7F6}"));
                    Item newsItem = currentYearItem.Add(txtNewsItem.Text, newsItemTemplate);
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Close", "window.top.dialogClose();", true);
                }
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Warning", "alert('Please enter news item');", true);
            }
        }
        protected void btnCancel_Click(object sender, EventArgs e)
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Close", "window.top.dialogClose();", true);
        }

Step 10: Create a main news item based on “News” template.

Step 11: Create a news item under main item by clicking the command template which would create a folder with current year and a “News Item” under that folder.












Helpful link or references:
http://techblogsearch.com/a/example-of-sitecore-command-template-with-user-interface.html
http://sitecoreworld.blogspot.in/2014/09/example-of-sitecore-command-template_21.html