Contate-nos

Sitecore 7: Creating a custom index

janeiro 22, 2014

Your Sitecore 7 has three out of the box, built in default indexes. Join a nonlinear developer to learn how to create a custom configuration and an index definition.

We've been looking at the new Sitecore 7 release from a number of different angles, but one of the biggest improvements we've identified is in its search configuration. You can take a deeper look at the improvements on the Sitecore page, which highlights customizable update strategies that can be configured by data, but to get started, you will want to create a custom index. This will allow you to limit the indexed pages by template type, for example, without interfering with the three built-in out of the box default indexes in Sitecore 7.

Define your custom configuration:

In the /App_Config/Include folder, create your custom configuration file with the following content: 

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <contentSearch>
      <siteSearch type="Sitecore.ContentSearch.LuceneProvider.
LuceneIndexConfiguration,
Sitecore.ContentSearch.LuceneProvider">

         <!-- Place all needed custom configuration here -->
  <indexAllFields>true</indexAllFields>

  <!-- You also can reference sections from
DefaultIndexConfiguration -->
  <analyzer ref="contentSearch/configuration/
defaultIndexConfiguration/analyzer" />

         <!--(AddCustomConfigurationHere)-->

</siteSearch>
    </contentSearch>
  </sitecore>
</configuration>

Index definition:

In the /App_Config/Include folder, create your custom index definition file with the following content:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <contentSearch>
      <configuration type="Sitecore.ContentSearch.LuceneProvider.
LuceneSearchConfiguration,
Sitecore.ContentSearch.LuceneProvider">
        <indexes hint="list:AddIndex">
          <index id="sitesearch_web" 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/
databasePropertyStore"
param1="$(id)" />

            <Configuration ref="contentSearch/siteSearch" />

            <strategies hint="list:AddStrategy">
              <!-- NOTE: order of these is controls the execution order -->
              <strategy ref="contentSearch/indexUpdateStrategies/onPublishEndAsync" />
            </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>master</Database>
                <Root>/sitecore</Root>
              </crawler>
            </locations>
          </index>

          <!--
            * Required to avoid the error: "Index has no configuration."
              Alternatively - You can change the files 'Sitecore.
ContentSearch.Lucene.Index.[DB].config'
          -->
          <index id="sitecore_core_index" type="Sitecore.ContentSearch.
LuceneProvider.LuceneIndex,
Sitecore.ContentSearch.LuceneProvider">
            <Configuration ref="contentSearch/configuration/
defaultIndexConfiguration"/>
          </index>
          <index id="sitecore_master_index" type="Sitecore.ContentSearch.
LuceneProvider.LuceneIndex,
Sitecore.ContentSearch.LuceneProvider">
            <Configuration ref="contentSearch/configuration/
defaultIndexConfiguration"/>
          </index>
          <index id="sitecore_web_index" type="Sitecore.ContentSearch.
LuceneProvider.LuceneIndex,
Sitecore.ContentSearch.LuceneProvider">
            <Configuration ref="contentSearch/configuration/
defaultIndexConfiguration"/>
          </index>
        </indexes>

      </configuration>
    </contentSearch>
  </sitecore>
</configuration>

Note that at the end of this configuration file you must reference the default configuration for the

pre-existing index configuration files. Failing to add this reference will result in a Sitecore error.

Contate-nos