0

I am creating lucene indexes using Sitecore 7.2 and I have Title field name common in Article's template as well as Author's template.

Is there any way to write separate field mapping as per included template?

Basically a way to differentiate author's title and Article's title indexes using a custom config file. Currently, I have included both templates & added a field mapping as shown below.


<include hint="list:IncludeTemplate">
 <Articles>{E38B8329-7ED5-460D-A493-5D3B07D66C8E}</Articles>
 <Authors>{362B8C48-CD98-4B9D-B99D-7F24AB67D87B}</Authors>
</include>

 <fieldMap type="Sitecore.ContentSearch.FieldMap, Sitecore.ContentSearch">
    <fieldNames hint="raw:AddFieldByFieldName">
        <field fieldName="**Title**"            storageType="YES" indexType="TOKENIZED"    vectorType="NO" boost="1f" type="System.String" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider">
                <analyzer type="Sitecore.ContentSearch.LuceneProvider.Analyzers.LowerCaseKeywordAnalyzer, Sitecore.ContentSearch.LuceneProvider" />
        </field>
    </fieldNames>
</fieldMap>

3
  • 1
    Do you really want a separate index for each template? Are the various Title fields conceptually different in any way, or are they all just single-line-text fields? The Title field in the index schema will work for any Sitecore Item that has a "Title" field, regardless of what the Sitecore Field ID is (assuming that they are all just text fields). Dec 8, 2017 at 14:35
  • Have to agree that separate indexes per template seems extremely bizarre in this case... there are very good reasons for having separate indexes but not for Articles and Authors (which one would assume logically belong together)
    – jammykam
    Dec 9, 2017 at 1:57
  • I just took an example above, the basic question is can sitecore allows us to have config based seperation between fieldnames.
    – Umar D
    Dec 11, 2017 at 23:11

2 Answers 2

0

I think what will get you there is to follow the Sitecore.FXM.Lucene.DomainsSearch.DefaultIndexConfiguration.config file from Sitecore. There are two important things to notice in this config. First is the setting <indexAllFields>false</indexAllFields>. This tells Sitecore to start with no field and ignore the default index fieldset. The hint from sitecore is

This setting allows you to specify which fields to include in the index when the indexAllFields setting is set to false.

Then you just include all the fields you want in this index.

       <include hint="list:AddIncludedField">
          <fieldId>{B5E02AD9-D56F-4C41-A065-A133DB87BDEB}</fieldId>
          <!-- display name -->
        </include>

The benefit being that it is by field ID. This gets you around the two fields called Title. Here is the config, but you can find it in Website\App_Config\Include\Sitecore.ContentSearch.Lucene.DefaultIndexConfiguration.config.

Hope this helps.

<?xml version="1.0" encoding="utf-8"?>
<!--

Purpose: This include file specifies the default configuration of the Lucene search index.

To disable this file, change its extension to ".disabled".

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

          <documentOptions type="Sitecore.ContentSearch.LuceneProvider.LuceneDocumentBuilderOptions, Sitecore.ContentSearch.LuceneProvider">

            <indexAllFields>false</indexAllFields>

            <include hint="list:AddIncludedTemplate">
              <domainMatcherTemplateId>{036DB470-1850-4848-A48A-0931F825B867}</domainMatcherTemplateId>
            </include>

            <include hint="list:AddIncludedField">
              <fieldId>{B5E02AD9-D56F-4C41-A065-A133DB87BDEB}</fieldId>
              <!-- display name -->
            </include>

            <fields hint="raw:AddComputedIndexField">
              <field fieldName="urllink">Sitecore.ContentSearch.ComputedFields.UrlLink,Sitecore.ContentSearch</field>
              <field fieldName="createdby">Sitecore.FXM.Service.Data.DomainMatchers.ContentSearch.ComputedFields.CreatedBy, Sitecore.FXM.Service</field>
              <field fieldName="updatedby">Sitecore.FXM.Service.Data.DomainMatchers.ContentSearch.ComputedFields.UpdatedBy, Sitecore.FXM.Service</field>
              <field fieldName="revision">Sitecore.FXM.Service.Data.DomainMatchers.ContentSearch.ComputedFields.Revision, Sitecore.FXM.Service</field>
              <field fieldName="domainmatchrule">Sitecore.FXM.Service.Data.DomainMatchers.ContentSearch.ComputedFields.DomainMatcherRule, Sitecore.FXM.Service</field>
            </fields>

          </documentOptions>

          <initializeOnAdd>true</initializeOnAdd>

          <fieldMap type="Sitecore.ContentSearch.FieldMap, Sitecore.ContentSearch">
            <fieldNames hint="raw:AddFieldByFieldName">

              <field fieldName="_uniqueid" storageType="YES" indexType="TOKENIZED"    vectorType="NO" boost="1f" type="System.String" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider">
                <analyzer type="Sitecore.ContentSearch.LuceneProvider.Analyzers.LowerCaseKeywordAnalyzer, Sitecore.ContentSearch.LuceneProvider" />
              </field>

              <field fieldName="_database" storageType="YES" indexType="TOKENIZED"    vectorType="NO" boost="1f" type="System.String" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider">
                <analyzer type="Sitecore.ContentSearch.LuceneProvider.Analyzers.LowerCaseKeywordAnalyzer, Sitecore.ContentSearch.LuceneProvider" />
              </field>

              <field fieldName="urllink" storageType="YES" indexType="TOKENIZED"    vectorType="NO" boost="1f" type="System.String" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider">
                <analyzer type="Sitecore.ContentSearch.LuceneProvider.Analyzers.LowerCaseKeywordAnalyzer, Sitecore.ContentSearch.LuceneProvider" />
              </field>

              <field fieldName="createdby" storageType="YES" indexType="TOKENIZED"    vectorType="NO" boost="1f" type="System.String" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider">
                <analyzer type="Sitecore.ContentSearch.LuceneProvider.Analyzers.LowerCaseKeywordAnalyzer, Sitecore.ContentSearch.LuceneProvider" />
              </field>

              <field fieldName="updatedby" storageType="YES" indexType="TOKENIZED"    vectorType="NO" boost="1f" type="System.String" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider">
                <analyzer type="Sitecore.ContentSearch.LuceneProvider.Analyzers.LowerCaseKeywordAnalyzer, Sitecore.ContentSearch.LuceneProvider" />
              </field>

              <field fieldName="revision" storageType="YES" indexType="TOKENIZED"    vectorType="NO" boost="1f" type="System.String" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider">
                <analyzer type="Sitecore.ContentSearch.LuceneProvider.Analyzers.LowerCaseKeywordAnalyzer, Sitecore.ContentSearch.LuceneProvider" />
              </field>

              <field fieldName="domainmatchrule" storageType="YES" indexType="TOKENIZED" vectorType="NO" boost="1f" type="System.String" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider">
                <analyzer type="Sitecore.ContentSearch.LuceneProvider.Analyzers.LowerCaseKeywordAnalyzer, Sitecore.ContentSearch.LuceneProvider" />
              </field>
            </fieldNames>
          </fieldMap>

          <!-- **** Inherited default configuration **** -->

          <analyzer ref="contentSearch/indexConfigurations/defaultLuceneIndexConfiguration/analyzer" />
          <fieldReaders ref="contentSearch/indexConfigurations/defaultLuceneIndexConfiguration/fieldReaders" />
          <indexFieldStorageValueFormatter ref="contentSearch/indexConfigurations/defaultLuceneIndexConfiguration/indexFieldStorageValueFormatter" />
          <indexDocumentPropertyMapper ref="contentSearch/indexConfigurations/defaultLuceneIndexConfiguration/indexDocumentPropertyMapper" />
          <documentBuilderType ref="contentSearch/indexConfigurations/defaultLuceneIndexConfiguration/documentBuilderType" />
        </defaultFxmLuceneIndexConfiguration>
      </indexConfigurations>
    </contentSearch>
  </sitecore>
</configuration>
3

This is not an answer to your question, but I think you going to make your solution incredibly complex because of an architectural decision.

If you are creating so many indexes is because two templates have the same field name. Just filter you search queries on your template name or template ID. When you start needing to make search queries that talk to more than one template type, you search queries are going to become very complex as you try to join to indexes in a query.

ISearchIndex index = ContentSearchManager.GetIndex("sitecore_web_index")  
using (IProviderSearchContext context = index.CreateSearchContext())  
{
  var results = context.GetQueryable<SearchResultItem>()
      .Where(x => x.TemplateName = "Article"
           && x.Title = "Somee Stuff");
}

Hope this helps.

1
  • Thanks for your reply. Yes there are few more templates in my custom indexes and all indexes are generated successfully by Sitecore. I just used two in my question because I need to understand if there is way to map fields under specific template using "config" files.
    – Umar D
    Dec 8, 2017 at 3:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.