Friday 30 November 2018

Create custom Solr index configuration file


Hello Devs,

If you want to create a custom Solr index file in your solution and having trouble in doing so (we too had trouble), you are at right place.

Earlier we used custom Lucene indexes in our solution but due to performance issues we decided to move all the custom indexes to SOLR (Read more about using Solr or Lucene).

If you are moving your custom Lucene indexes to Solr you would need to change few configurations to make it working.

Below I have created a custom Solr index file (e.g. employeecustomindex)

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <contentSearch>
      <configuration type="Sitecore.ContentSearch.ContentSearchConfiguration, Sitecore.ContentSearch">
        <indexes hint="list:AddIndex">
          <index id="employeecustomindex" type="Sitecore.ContentSearch.SolrProvider.SolrSearchIndex, Sitecore.ContentSearch.SolrProvider">
            <param desc="name">$(id)</param>
            <param desc="folder">$(id)</param>
            <!-- This initializes index property store. Id has to be set to the index id -->
            <param desc="propertyStore" ref="contentSearch/indexConfigurations/databasePropertyStore" param1="$(id)" />

            <configuration ref="contentSearch/indexConfigurations/employeeCustomIndexConfiguration" />

            <strategies hint="list:AddStrategy">
              <!-- NOTE: order of these controls the execution order -->
              <strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/rebuildAfterFullPublish" />
              <strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/onPublishEndAsync" />
              <strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/remoteRebuild" />
            </strategies>

            <commitPolicyExecutor type="Sitecore.ContentSearch.CommitPolicyExecutor, Sitecore.ContentSearch">
              <policies hint="list:AddCommitPolicy">
                <policy type="Sitecore.ContentSearch.TimeIntervalCommitPolicy, Sitecore.ContentSearch" />
              </policies>
            </commitPolicyExecutor>

            <locations hint="list:AddCrawler">
              <crawler type="Sitecore.ContentSearch.SitecoreItemCrawler, Sitecore.ContentSearch">
                <Database>web</Database>
                <Root>/sitecore/content/Home/Employee/</Root>
              </crawler>
            </locations>

          </index>
        </indexes>
      </configuration>

      <indexConfigurations>
        <employeeCustomIndexConfiguration ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration" type="Sitecore.ContentSearch.SolrProvider.SolrSearchIndex, Sitecore.ContentSearch.SolrProvider">
          <indexAllFields>false</indexAllFields>

          <include hint="list:IncludeTemplate">
            <Employee>{AB47C5E1-000E-4DF1-B74F-0FC226FB19BB}</Employee>
          </include>

          <include hint="list:IncludeField">
            <EmployeeName>{6244D370-D460-41B6-A6D1-34040C828523}</EmployeeName>
            <EmployeeCity>{8B8BDA9E-C728-44D3-8859-204448812B3F}</EmployeeCity>
            <DoNotDisplay>{6F2DAA38-8467-43F1-85DD-5B5A14BB1719}</DoNotDisplay>
          </include>

          <exclude hint="list:ExcludeField">
            <EmployeeDOB>{E16B5AEE-3E7A-4CEB-A743-9CEB1CCE636F}</EmployeeDOB>
            <EmployeeBio>{6B50DE85-DCC3-4592-9746-6170E1657321}</EmployeeBio>
          </exclude>

          <fieldReaders ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration/fieldReaders"/>
          <indexFieldStorageValueFormatter ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration/indexFieldStorageValueFormatter"/>
          <indexDocumentPropertyMapper ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration/indexDocumentPropertyMapper"/>
        </employeeCustomIndexConfiguration>
      </indexConfigurations>
    </contentSearch>
  </sitecore>
</configuration>


     1. First, we need to change the reference to (e.g.    contentSearch/indexConfigurations/employeeCustomIndexConfiguration).

  <configuration ref="contentSearch/indexConfigurations/employeeCustomIndexConfiguration" />

2. If we want to index only specific fields, set the indexAllFields property to false.

  <indexAllFields>false</indexAllFields>

3.  Set templates which we want to index in below configuration section.
  
   <include hint="list:IncludeTemplate">
       <Employee>{AB47C5E1-000E-4DF1-B74F-0FC226FB19BB}</Employee>
  </include>

4.  Set fields we want to add in index in our case we have 
    (Employee Name,Employee City,EmployeeDOB,EmployeeBio,DoNotDisplay) in Employee template

 <include hint="list:IncludeField">
   <EmployeeName>{6244D370-D460-41B6-A6D1-34040C828523}</EmployeeName>
   <EmployeeCity>{8B8BDA9E-C728-44D3-8859-204448812B3F}</EmployeeCity>
   <DoNotDisplay>{6F2DAA38-8467-43F1-85DD-5B5A14BB1719}</DoNotDisplay>
 </include>

   Set fields we don't want to add in index.

 <exclude hint="list:ExcludeField">
  <EmployeeDOB>{E16B5AEE-3E7A-4CEB-A743-9CEB1CCE636F}</EmployeeDOB>
  <EmployeeBio>{6B50DE85-DCC3-4592-9746-6170E1657321}</EmployeeBio>
 </exclude>

 5.  At last we need to add references for

    <fieldReaders   ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration/fieldReaders"/>

    <indexFieldStorageValueFormatter    ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration/indexFieldStorageValueFormatter"/>

    <indexDocumentPropertyMapper ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration/indexDocumentPropertyMapper"/>  

which references to defaultSolrIndexConfiguration file.

After making all the changes restart your Solr service, re-build index and preview your index in Solr admin panel.

Happy Solr Indexing!!! 😊


Monday 6 August 2018

Sitecore Commerce 9u1 : One or more exception occurred while processing the subscribers to the ‘packageinstall:items:ended’ event


Hello Devs,

While Installing Sitecore Commerce 9 update 1, I faced below error -





This error seems to be from the Sitecore side.The log file from Sitecore showed below Stacktrace

Exception [1]: Microsoft.OData.Client.DataServiceQueryException  Message[1]: An error occurred while processing this request.  Source[1]: Sitecore.Commerce.ServiceProxy     at Sitecore.Commerce.ServiceProxy.Proxy.GetValue[T](DataServiceQuerySingle`1 query)    at Sitecore.Commerce.Engine.Connect.DataProvider.CatalogRepository.GetLanguages()    at Sitecore.Commerce.Engine.Connect.DataProvider.ReadOnlyCatalogDataProvider.GetItemVersions(ItemDefinition itemDefinition, CallContext context)    at Sitecore.Data.DataProviders.DataProvider.GetItemVersions(ItemDefinition item, CallContext context, DataProviderCollection providers)    at Sitecore.Data.DataSource.LoadVersions(ItemDefinition definition, Language language)    at Sitecore.Data.DataSource.GetVersions(ItemInformation itemInformation, Language language)    at Sitecore.Data.DataSource.GetLatestVersion(ItemInformation itemInformation, Language language)    at Sitecore.Data.DataSource.GetItemData(ID itemID, Language language, Version version) *** 

I tried to google this issue but was not able to find anything concrete. I raised this issue with Sitecore support and they provided me with few steps to resolve the issue.

1. Error that caused this exception is that sitecore can't connect to the Commerce Engine instance (Commerce Authoring). So, please ensure that this instance is up and running. 
Also check that sitecore has configured thumbprint to communicate with Commerce Authoring. You need specify certificate Thumbprint value (certificateThumbprint value of certificate which you've created before installation) in the App_Config\Include\Y.Commerce.Engine\Sitecore.Commerce.Engine.Connect.config
<certificateThumbprint> V A L U E </certificateThumbprint>

In my case it was fine.

2. The other approach is to disable index rebuild temporarily and rebuild all indexes after commerce is installed. To do it, you need to comment out this handler during installation process.

 <event name="packageinstall:items:ended">
        <handler type="Sitecore.ContentSearch.Events.PackagingEventHandler, Sitecore.ContentSearch" method="OnPackageInstallItemsEndHandler" />
</event>

It executes index rebuild after each package is installed. After commenting out this event I re-ran the installation process and was not able to see the error again.

Note : Don’t forget to Re-build indexes after the installation process is completed.

Happy Sitecore Commerce Installation!!! 😄😄😄

Friday 5 January 2018

Experience Editor : & removed while editing rendering parameter field

Hello Devs,

While trying to update rendering parameter field from experience editor and provide special characters like & or @ in the field value it would strip all the content after special character.

Lets re-produce the issue





















Now if we edit the rendering parameter field values with special character from the content editor and save it, text is not stripped. It happens from experience editor.

We raised this issue with the sitecore support and they reported it as a bug in version (8.1 update-1 (151207)).

They provided a patch to resolve it. (click on link to download the sitecore patch)

https://sitecore.box.com/s/pmv261bzomeinex9gtpoxc9tmziq3eda

Now Let's check after providing the patch.




















That's it for now
Happy Coding !!! 😊




Saturday 30 December 2017

Sitecore 9 : No matching command include parameter name signer

Hello Sitecore Devs,

While Installing Sitecore 9 on windows 8.1 machine I faced an error
No matching command include parameter named 'signer'. check the spelling of the parameter name and then try again.




















I found one post regarding above error 
https://neilkillen.com/2017/11/04/sitecore-9-0-sif-windows-8-1-server-2012-gotchas/

It says that windows 8.1 does not have parameter named "signer" and hence the error.
Also IIS 8.0/8.5 does not support creation of certificates automatically. so you need to manually create certificate.

After generating the certificates manually you need to update the installation script as follows :

For Step : #install client certificate for xconnect
remove line Install-SitecoreConfiguration @certParams -Verbose so that it does not try to install certificate automatically and we can get rid of the 'signer' error.

Search for XConnectCert = $certParams.CertificateName instances in your installation script and replace $certParams.CertificateName with the thumbprint of your created certificate (make sure to convert your thumbprint to uppercase and remove space between them).

e.g. XConnectCert ="C28BDFD63F84DAA28CF604345A1A5124F3E535D1"

Re-run your installation script and you should be able to solve certificate related error.

That's all for Now !!!





Thursday 6 April 2017

Solr Keyword Search with hyphen not working

Hello Devs,

While doing hands on with SOLR, faced issues while searching for keywords with hyphen. Just an overview, I have created list of items in Sitecore which has below fields:

Employee Name, Employee Birthdate, Employee City and Employee Bio and I’m reading its values from my custom SOLR Index.

When we search with Employee Name (for e.g. John - Smith), it does’nt give any search results even if its present in index.

The reason is Sitecore field types of “html|rich text|single-line text|multi-line text|text|memo|image|reference” are defined as a text field and it uses solr.StandardTokenizerFactory.

This Standard Tokenizer treats whitespace and punctuation as delimiters and it discards them (except (dots)). To read more about Tokenizers click here.
First, you need to add the Field (e.g. Employee name) in

Sitecore.ContentSearch.Solr.DefaultIndexConfiguration.config under

<fieldNames hint="raw:AddFieldByFieldName"> 

section or you can create a custom index configuration file and add the require fields as below:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <contentSearch>
      <!-- Configuration sections for indexes -->
      <indexConfigurations>
        <!-- If an index has no configuration specified, it will use the configuration below. The configuration is not merged if the index also has
         configuration, it is either this configuration or the index configuration. -->
    <defaultSolrIndexConfiguration  type="Sitecore.ContentSearch.SolrProvider.SolrIndexConfiguration,    Sitecore.ContentSearch.SolrProvider">

          <!-- DEFAULT FIELD MAPPING
               This field map allows you to take full control over how your data is stored in the index. This can affect the way data is queried, performance of searching and how data is retrieved and casted to a proper type in the API.
            -->
          <fieldMap type="Sitecore.ContentSearch.SolrProvider.SolrFieldMap, Sitecore.ContentSearch.SolrProvider">
            <fieldNames hint="raw:AddFieldByFieldName">
                   <field fieldName="Employee Name" returnType="string" />
            </fieldNames>
         </fieldMap>
        </defaultSolrIndexConfiguration>
      </indexConfigurations>
    </contentSearch>
  </sitecore>
</configuration>

In Schema.xml file for the SOLR index you created, comment out

<fieldType name="string" class="solr.StrField" sortMissingLast="true" />

and add,

<fieldType name="string" class="solr.TextField" sortMissingLast="true">
      <analyzer type="index">
        <tokenizer class="solr.KeywordTokenizerFactory" />
        <filter class="solr.LowerCaseFilterFactory" />
      </analyzer>
      <analyzer type="query">
        <tokenizer class="solr.KeywordTokenizerFactory" />
        <filter class="solr.LowerCaseFilterFactory" />
      </analyzer>
 </fieldType>

Once you make all these changes restart your SOLR Service once and Re-build index. Now Search for keywords with – in it and you would see the results.

Happy Coding 😊

Wednesday 5 April 2017

Issue with Publishing related items from experience editor

Hello Devs,

We faced one issue while publishing related items from Experience Editor. We are passing a datasource item (e.g. XXX) to a component.

The Datasource item have a multilist field where we select the items (Item: A, B) to be displayed.

When we Update field values of the below selected items (Item: A or B) from the experience editor. The values are updated from the experience editor and were reflected in content editor as well but when we publish with (Publish sub Items and Publish Related Items) the changes are not getting reflected.

Question: Is this an intended behaviour? (We raised a support ticket for it)

Yes, Sitecore does’nt process second level reference and therefore it’s not process by Sitecore. The reason is to prevent huge number of items being published. Sitecore doesn't process references of references.

You can customize your solution to implement the behaviour in the following way:

1. Create your custom processor based on the Sitecore.Publishing.Pipelines.GetItemReferences.AddItemLinkReferences 
one (i.e. copy sources of processor).

2. Modify the GetReferences() method so that it would recursively process reference references if item is being referenced by the Renderings field (i.e. reference is a data source item).

3. Replace predefined processor with your custom one.

Click here to download the custom code file provided by Sitecore.

That’s it !!!

Happy Coding 😊

Friday 13 January 2017

Validation error on adding image in Rich-Text field from Experience editor


Validation error on adding image in Rich-Text field from Experience editor 

When we add an image in Rich-Text field through Experience Editor it throws validation error in (Sitecore 8.1 update-1(151207)).






Steps to reproduce:

Add an image in Rich-Text field from Experience Editor

As soon as we save the changes a validation error is thrown in experience editor

In Experience Editor the <img> tag created is,

<img alt="XXX" src="-/media/XXX.ashx?h=111&amp;w=539&amp;hash=CAF8436CA168BC18D2FD5D95597E874E66EDD1DF" style="width: 539px; height: 111px;" />

Open Content Editor

Click on Edit Html -> Click Fix

The Original HTML and Corrected HTML show no difference but if you see the <img> tag / is removed.

<img alt="XXX" src="-/media/XXX.ashx?h=111&amp;w=539&amp;hash=CAF8436CA168BC18D2FD5D95597E874E66EDD1DF" style="width: 539px; height: 111px;" >

/> is removed

After accepting the above changes, it doesn't throw any error in content editor as well as validation error from experience editor is gone.

Solution:

We raised this with Sitecore Support and they reported it as a Bug in Sitecore 8.1 update-1(151207) Thanks to Sitecore support as they provided a patch to resolve this issue.

So the problem appears while decoding the HTML rich text value in System.Net.WebUtility.HtmlDecode method. To let HtmlDecode generate valid output for rich text field apply following patch provided by Sitecore:

1) Backup your \Website\sitecore\shell\client\Sitecore\ExperienceEditor\ExperienceEditor.js

2) Find following code in mentioned ExperienceEditor.js:

encodeHtml: function (htmlSource) {
    htmlSource = htmlSource.replace(/\\/g, '\\\\').replace(/\"/g, "\\\"");
    var encodedHtml = encodeURIComponent(htmlSource);
    return encodedHtml;
},

and replace it with:

encodeHtml: function (htmlSource) {
    htmlSource = htmlSource.replace(/\\/g, '\\\\').replace(/\"/g, "\\\"").replace(/&amp;/g, "&amp;amp;"); // fix 102239
    var encodedHtml = encodeURIComponent(htmlSource);
    return encodedHtml;
},

3) Clear your browser cache. That’s it.

Check by adding image from Experience Editor it wouldn't throw any validation error.

Happy Coding 😊.