It should be possible, but probably not that simple - at least not if you want to use a different analyzer at search time.
Please note that I haven't tested any of the stuff below.
Changing the analyzer (both indexin and searching)
You should be able to change the analyzer of the _content
field like this:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<contentSearch>
<indexConfigurations>
<defaultLuceneIndexConfiguration>
<fieldMap type="Sitecore.ContentSearch.FieldMap, Sitecore.ContentSearch">
<fieldNames hint="raw:AddFieldByFieldName">
<field fieldName="_content" storageType="NO" indexType="TOKENIZED" vectorType="NO" boost="1f" type="System.String" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider">
<analyzer type="Sitecore.ContentSearch.LuceneProvider.Analyzers.StandardAnalyzerWithStemming, Sitecore.ContentSearch.LuceneProvider">
<param hint="version">Lucene_30</param>
</analyzer>
</field>
</fieldNames>
</fieldMap>
</defaultLuceneIndexConfiguration>
</indexConfigurations>
</contentSearch>
</sitecore>
</configuration>
This should then use the specified analyzer for both indexing and searching this field.
Copying the _content field with different analyzer
The _content
field is a special field added by Sitecore at index time.
If you want to index _content
more than once, using different analyzers, I think you would need
to extend Sitecore.ContentSearch.LuceneProvider.LuceneDocumentBuilder
and override the method void AddField(IIndexableDataField field)
.
object obj = fieldConfiguration1.FormatForWriting(fieldValue);
float boost = BoostingManager.ResolveFieldBoosting(field);
if (IndexOperationsHelper.IsTextField(field))
{
LuceneSearchFieldConfiguration fieldConfiguration2 = this.Index.Configuration.FieldMap.GetFieldConfiguration("_content") as LuceneSearchFieldConfiguration;
this.AddField("_content", obj, fieldConfiguration2 ?? this.defaultTextField, 0.0f);
}
this.AddField(name, obj, fieldSettings, boost);
In that method you could then add your own _content_ngram
or something like that and control the used analyzer in the field configuration as shown above.
Using another analyzer at search time
If you want to use another analyzer at search time than the one specified on the field configuration, then you could probably
utilize execution contexts by implementing Sitecore.ContentSearch.Linq.Common.IExecutionContext
. The implementations themselves do not need any logic.
public class NGramExecutionContext : IExecutionContext
{
}
You would then need to create a custom analyzer which uses a specific analyzer depending on the field name.
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<contentSearch>
<indexConfigurations>
<defaultLuceneIndexConfiguration>
<analyzer type="Sitecore.ContentSearch.LuceneProvider.Analyzers.PerExecutionContextAnalyzer, Sitecore.ContentSearch.LuceneProvider">
<param desc="map" type="System.Collections.Generic.List`1[[Sitecore.ContentSearch.LuceneProvider.Analyzers.PerExecutionContextAnalyzerMapEntry, Sitecore.ContentSearch.LuceneProvider]]">
<map hint="list:Add">
<mapEntry type="Sitecore.ContentSearch.LuceneProvider.Analyzers.PerExecutionContextAnalyzerMapEntry, Sitecore.ContentSearch.LuceneProvider">
<!-- Your custom execution context -->
<param hint="executionContext" type="YourNamespace.NGramExecutionContext, YourAssembly">
<!-- Any parameters for your execution context constructor -->
</param>
<!-- Your custom analyzer -->
<param desc="analyzer" type="YourNamespace.CustomAnalyzer, YourAssembly">
<!-- Any paramters for your custom analyzer constructor -->
</param>
</mapEntry>
</map>
</param>
</analyzer>
</defaultLuceneIndexConfiguration>
</indexConfigurations>
</contentSearch>
</sitecore>
</configuration>
How to implement the custom analyzer I'll leave up to you. You could take a look at how Sitecore.ContentSearch.LuceneProvider.Analyzers.DefaultPerFieldAnalyzer
works to get some inspiration.