Surendra Sharma

Surendra Sharma

Search This Blog

Friday, October 28, 2016

All About indexing an external database in Sitecore

This post is about indexing an External Database in Sitecore.

Flow of external indexing
Flow of external indexing

So will index data of external database tables and use LUCENE search to get result from index files. If you are new to LUCENE search, please refer my article on Lucene search.

There is one great post on the same topic by Cameron Palmer.

I setup most of the things according to this post and its work like a charm.

However for Sitecore 8.0, I need to do below changes.

  • You need to add reference of Sitecore.ContentSearch.dll, Sitecore.ContentSearch.Linq.dll, Sitecore.ContentSearch.Linq.Lucene.dll and Sitecore.Kernel.dll.
  • I added my fields in "<fieldNames hint="raw:AddFieldByFieldName">" section in Sitecore.ContentSearch.Lucene.DefaultIndexConfiguration.config.
  • I created new config file "People.Index.config" in "Include" folder as

<?xml version="1.0"?>
<configuration xmlns:patch="">
      <configuration type="Sitecore.ContentSearch.ContentSearchConfiguration, Sitecore.ContentSearch">
        <indexes hint="list:AddIndex">
          <index id="People_Index" type="Sitecore.ContentSearch.LuceneProvider.LuceneIndex, Sitecore.ContentSearch.LuceneProvider">
            <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/defaultLuceneIndexConfiguration" />
            <strategies hint="list:AddStrategy">
              <!-- NOTE: order of these is controls the execution order -->
              <strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/onPublishEndAsync" />
            <commitPolicyExecutor type="Sitecore.ContentSearch.CommitPolicyExecutor, Sitecore.ContentSearch">
              <policies hint="list:AddCommitPolicy">
                <policy type="Sitecore.ContentSearch.ModificationCountCommitPolicy, Sitecore.ContentSearch">
            <!--<locations hint="list:AddCrawler">
              <crawler type="Sitecore.ContentSearch.SitecoreItemCrawler, Sitecore.ContentSearch">
            <locations hint="list:AddCrawler">
              <crawler type="Testsite.ASPNET.UI.PeopleCrawler, Testsite.ASPNET.UI">

You need to change two yellow highlighted things in this "People.Index.config" file as
  • <index id="People_Index" name
  • Class type details with assmbly name as <crawler type="Testsite.ASPNET.UI.PeopleCrawler, Testsite.ASPNET.UI">

That's it from Sitecore point of view.

After this next challenge is how to rebuild/refresh index for any DML operation done on external database tables. For this you can refer my article "Rebuild Sitecore index on real time basis from external system".

Index rebuild process takes time on Sitecore side. So you must call index rebuild method in async function in C#.

I hope you like this Sitecore lesson. Stay tuned for more Sitecore related articles.

Till that happy sitecoring :)

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

Thursday, October 27, 2016

Lifetime and publishing in Sitecore

This post is about lifetime and publishing fields of an item in Sitecore.

Lifetime and publishing fields
Lifetime and publishing fields

If you check standard values of any item, you surely get two section - Lifetime and Publishing.

Lifetime fields

These fields are applied on individual version and language.

  • Valid from - Date and time from which this items version is available on delivery database and hence available for access to front end
  • Valid to - After this Date and time, this item version is removed from delivery database.
  • Hide version - Hide this item version from accessing. Its useful if you have created multilinguaal site and for specific language such as French, you don't want to publish it. So check this checkbox to hide French language version.

Publishing fields

All fields of publishing section are shared. These fields are applied on all versions and languages of an item.

  • Publish - Copy this item at specified datetime to web(delivery) database.
  • Unpublish - Delete this item at specified datetime from web(delivery) database
  • Publishing targets - Copy / Delete this item from selected targets instances delivery databases
  • Never publish - Don't publish this item. In this case item will not copied to your Web database. If item is already published, then this item will be deleted from WEB database.

If you had not published the item yet and now if you specify the datetime in Publish field and marked Publishing targets, then item will be automatically publish around specified date time on specified target delivery instances. Please note this will not published at exact specified date time but somewhere after to specified date time when publish agent will run.

Auto publish will only work if you have specified interval for publish agent in Web.config file as

<!-- Agent to publish database periodically -->
<agent type="Sitecore.Tasks.PublishAgent" method="Run" interval="00:00:00">
  <param desc="source database">master</param>
  <param desc="target database">web</param>
  <param desc="mode (full or smart or incremental)">incremental</param>
  <param desc="languages">en, da</param>

Here 00:00:00 means auto publish is disabled. So a value "00:10:00" means run scheduler once in every 10 minutes as

<agent type="Sitecore.Tasks.PublishAgent" method="Run" interval="00:10:00">

I hope you like this Sitecore lesson. Stay tuned for more Sitecore related articles.

Till that happy sitecoring :)

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