All index customization is done during composition (i.e. in Startup.ConfigureServices
) and is generally done by using the IOptions configuration pattern in .NET.
Change default analyzers
See Customization - Default Analyzers for details
services.PostConfigure<AzureSearchIndexOptions>("InternalIndex", options =>
{
// Replace the default analyzer for the internal index to be
// Microsoft's English Analyzer
options.AnalyzerName = LexicalAnalyzerName.EnMicrosoft.ToString();
});
Default field types & analyzers
See Customization - Default field types & analyzers for details
Set the field definition for “productPrice” to be a Double:
// Modify the options for the Internal index
services.PostConfigure<AzureSearchIndexOptions>("InternalIndex", options =>
{
options.FieldDefinitions.AddOrUpdate(new FieldDefinition("productPrice", AzureSearchFieldDefinitionTypes.Double));
});
Custom field types & analyzers
See Customization - Custom field types & analyzers for details
If you want to define a custom field type, you can do that during index composition by passing in a value to the IndexValueTypesFactory
property of the AzureSearchIndexOptions
. The value for this parameter is: IReadOnlyDictionary<string, IAzureSearchFieldValueTypeFactory> indexValueTypesFactory
. The dictionary Key
is the name of the field type and the Value
is a factory that returns a IAzureSearchFieldValueTypeFactory
for a given field name. ExamineX has a default implementation of this which includes all of the above default field types. If this parameter is specified, all of ExamineX’s default field types will still be used but you can override the custom implementations if a Key
that you provide matches a default implementation.
This will create a Japanese field type with a “ja.microsoft” analyzer.
// Modify the options for the Internal index
services.PostConfigure<AzureSearchIndexOptions>("InternalIndex", options =>
{
// create/assign custom value types factory
options.IndexValueTypesFactory = new Dictionary<string, IAzureSearchFieldValueTypeFactory>
{
["japaneseString"] =
// define the factory
new AzureSearchFieldValueTypeFactory(fieldName =>
new AzureSearchFieldValueType(
fieldName,
// This example will allow multiple values
// per field
AzureSearchFieldValueType.StringCollectionType,
// Use microsoft's Japanese analyzer
LexicalAnalyzerName.JaMicrosoft.ToString()))
};
// Assign the custom field type to the "japaneseTitle" field
options.FieldDefinitions.AddOrUpdate(
"japaneseTitle",
s => new FieldDefinition(s, "japaneseString"));
});