We’re doing a lot with Solr lately, and I wanted to make a note of the difference in how one defines custom fields to include in your Sitecore indexes. I’m not including how one defines a full custom index, but just the field definition; if one has a “Description” and “Conversation” field to include in a search index for Sitecore, this summarizes the basics of how to make that happen.
Lucene
One adds <field> nodes to the fieldNames and fieldMap sections of the XML configuration. Again, this example alters the defaultLuceneIndexConfiguration for Sitecore which isn’t a best-practice; it’s generally better to define your own index that is laser-focused just on the content you want to use for your implementation, but I wanted as succinct an example as possible to note the caveat!
<sitecore>
<contentSearch>
<indexConfigurations>
<defaultLuceneIndexConfiguration type="Sitecore.ContentSearch.LuceneProvider.LuceneIndexConfiguration, Sitecore.ContentSearch.LuceneProvider">
<fieldMap type="Sitecore.ContentSearch.FieldMap, Sitecore.ContentSearch">
<fieldNames hint="raw:AddFieldByFieldName">
<field fieldName="Description" 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="Conversation" 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>
</defaultLuceneIndexConfiguration>
</indexConfigurations>
</contentSearch>
</sitecore>
Solr
One adds <fieldReader> nodes to the mapFieldByTypeName and FieldReaders sections of the XML configuration. Same caveat applies here for Solr as with Lucene — it’s generally recommended to define your own Solr index and work from that, but I wanted a minimal example:
<sitecore>
<contentSearch>
<indexConfigurations>
<defaultSolrIndexConfiguration type="Sitecore.ContentSearch.SolrProvider.SolrIndexConfiguration, Sitecore.ContentSearch.SolrProvider">
<FieldReaders type="Sitecore.ContentSearch.FieldReaders.FieldReaderMap, Sitecore.ContentSearch">
<mapFieldByTypeName hint="raw:AddFieldReaderByFieldTypeName">
<fieldReader fieldTypeName="Description" fieldReaderType="Sitecore.ContentSearch.FieldReaders.RichTextFieldReader, Sitecore.ContentSearch" />
<fieldReader fieldTypeName="Conversation" fieldReaderType="Sitecore.ContentSearch.FieldReaders.RichTextFieldReader, Sitecore.ContentSearch" />
</mapFieldByTypeName>
</FieldReaders>
</defaultSolrIndexConfiguration>
</indexConfigurations>
</contentSearch>
</sitecore>
This is really just the tip of the iceburg, as fieldReaderType definitions for Solr and Lucene analyzers — just two examples — open up so many possibilities. I struggled to find this side-by-side info for Lucene and Solr as it applies to Sitecore (Sitecore 8.1 update-1, specifically), so I wanted to share it here.