Class DefaultDocValuesFormatFactory
Implements the default functionality of IDocValuesFormatFactory.
To replace the DefaultDocValuesFormatFactory instance, call SetDocValuesFormatFactory(IDocValuesFormatFactory) at application start up. DefaultDocValuesFormatFactory can be subclassed or passed additional parameters to register additional codecs, inject dependencies, or change caching behavior, as shown in the following examples. Alternatively, IDocValuesFormatFactory can be implemented to provide complete control over doc values format creation and lifetimes.
Register Additional DocValuesFormats
Additional codecs can be added by initializing the instance of DefaultDocValuesFormatFactory and passing an array of DocValuesFormat-derived types.
// Register the factory at application start up.
DocValuesFormat.SetDocValuesFormatFactory(new DefaultDocValuesFormatFactory {
CustomDocValuesFormatTypes = new Type[] { typeof(MyDocValuesFormat), typeof(AnotherDocValuesFormat) }
});
Only Use Explicitly Defined DocValuesFormats
PutDocValuesFormatType(Type) can be used to explicitly add codec types. In this example,
the call to base.Initialize()
is excluded to skip the built-in codec registration.
Since AnotherDocValuesFormat
doesn't have a default constructor, the NewDocValuesFormat(Type)
method is overridden to supply the required parameters.
public class ExplicitDocValuesFormatFactory : DefaultDocValuesFormatFactory
{
protected override void Initialize()
{
// Load specific codecs in a specific order.
PutDocValuesFormatType(typeof(MyDocValuesFormat));
PutDocValuesFormatType(typeof(AnotherDocValuesFormat));
}
protected override DocValuesFormat NewDocValuesFormat(Type type)
{
// Special case: AnotherDocValuesFormat has a required dependency
if (typeof(AnotherDocValuesFormat).Equals(type))
return new AnotherDocValuesFormat(new SomeDependency());
return base.NewDocValuesFormat(type);
}
}
// Register the factory at application start up.
DocValuesFormat.SetDocValuesFormatFactory(new ExplicitDocValuesFormatFactory());
See the Lucene.Net.Codecs namespace documentation for more examples of how to inject dependencies into DocValuesFormat subclasses.
Use Reflection to Scan an Assembly for DocValuesFormats
ScanForDocValuesFormats(Assembly) or ScanForDocValuesFormats(IEnumerable<Assembly>) can be used to scan assemblies using .NET Reflection for codec types and add all subclasses that are found automatically.
public class ScanningDocValuesFormatFactory : DefaultDocValuesFormatFactory
{
protected override void Initialize()
{
// Load all default codecs
base.Initialize();
// Load all of the codecs inside of the same assembly that MyDocValuesFormat is defined in
ScanForDocValuesFormats(typeof(MyDocValuesFormat).Assembly);
}
}
// Register the factory at application start up.
DocValuesFormat.SetDocValuesFormatFactory(new ScanningDocValuesFormatFactory());
Doc values formats in the target assembly can be excluded from the scan by decorating them with the ExcludeDocValuesFormatFromScanAttribute.
Inherited Members
Namespace: Lucene.Net.Codecs
Assembly: Lucene.Net.dll
Syntax
public class DefaultDocValuesFormatFactory : NamedServiceFactory<DocValuesFormat>, IDocValuesFormatFactory, IServiceListable
Constructors
| Improve this Doc View SourceDefaultDocValuesFormatFactory()
Creates a new instance of DefaultDocValuesFormatFactory.
Declaration
public DefaultDocValuesFormatFactory()
Properties
| Improve this Doc View SourceAvailableServices
Gets a list of the available DocValuesFormats (by name).
Declaration
public virtual ICollection<string> AvailableServices { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.ICollection<System.String> | A ICollection{string} of DocValuesFormat names. |
CustomDocValuesFormatTypes
An array of custom DocValuesFormat-derived types to be registered. This property can be initialized during construction of DefaultDocValuesFormatFactory to make your custom codecs known to Lucene.
These types will be registered after the default Lucene types, so if a custom type has the same name as a Lucene DocValuesFormat (via DocValuesFormatNameAttribute) the custom type will replace the Lucene type with the same name.
Declaration
public IEnumerable<Type> CustomDocValuesFormatTypes { get; set; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Type> |
Methods
| Improve this Doc View SourceGetDocValuesFormat(String)
Gets the DocValuesFormat instance from the provided name
.
Declaration
public virtual DocValuesFormat GetDocValuesFormat(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The name of the DocValuesFormat instance to retrieve. |
Returns
Type | Description |
---|---|
DocValuesFormat | The DocValuesFormat instance. |
GetDocValuesFormat(Type)
Gets the DocValuesFormat instance from the provided type
.
Declaration
protected virtual DocValuesFormat GetDocValuesFormat(Type type)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The System.Type of DocValuesFormat to retrieve. |
Returns
Type | Description |
---|---|
DocValuesFormat | The DocValuesFormat instance. |
GetDocValuesFormatType(String)
Gets the DocValuesFormat System.Type from the provided name
.
Declaration
protected virtual Type GetDocValuesFormatType(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The name of the DocValuesFormat System.Type to retrieve. |
Returns
Type | Description |
---|---|
System.Type | The DocValuesFormat System.Type. |
Initialize()
Initializes the doc values type cache with the known DocValuesFormat types.
Override this method (and optionally call base.Initialize()
) to add your
own DocValuesFormat types by calling PutDocValuesFormatType(Type)
or ScanForDocValuesFormats(Assembly).
If two types have the same name by using the DocValuesFormatNameAttribute, the last one registered wins.
Declaration
protected override void Initialize()
Overrides
NewDocValuesFormat(Type)
Instantiates a DocValuesFormat based on the provided type
.
Declaration
protected virtual DocValuesFormat NewDocValuesFormat(Type type)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The System.Type of DocValuesFormat to instantiate. |
Returns
Type | Description |
---|---|
DocValuesFormat | The new instance. |
PutDocValuesFormatType(Type)
Adds a DocValuesFormat type to the Lucene.Net.Codecs.DefaultDocValuesFormatFactory.docValuesFormatNameToTypeMap, using the name provided in the DocValuesFormatNameAttribute, if present, or the name of the codec class minus the "DocValuesFormat" suffix as the name by default.
Note that if a DocValuesFormat with the same name already exists in the map, calling this method will update it to the new type.
Declaration
protected virtual void PutDocValuesFormatType(Type docValuesFormat)
Parameters
Type | Name | Description |
---|---|---|
System.Type | docValuesFormat | A type that subclasses DocValuesFormat. |
ScanForDocValuesFormats(IEnumerable<Assembly>)
Scans the given assemblies
for subclasses of Codec
and adds their names to the Lucene.Net.Codecs.DefaultDocValuesFormatFactory.docValuesFormatNameToTypeMap. Note that names will be
automatically overridden if the DocValuesFormat name appears multiple times - the last match wins.
Declaration
protected virtual void ScanForDocValuesFormats(IEnumerable<Assembly> assemblies)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<System.Reflection.Assembly> | assemblies | A list of assemblies to scan. The assemblies will be scanned from first to last, and the last match for each DocValuesFormat name wins. |
ScanForDocValuesFormats(Assembly)
Scans the given assembly
for subclasses of DocValuesFormat
and adds their names to the Lucene.Net.Codecs.DefaultDocValuesFormatFactory.docValuesFormatNameToTypeMap. Note that names will be
automatically overridden if the DocValuesFormat name appears multiple times - the last match wins.
Declaration
protected virtual void ScanForDocValuesFormats(Assembly assembly)
Parameters
Type | Name | Description |
---|---|---|
System.Reflection.Assembly | assembly | The assembly to scan. |