Class DefaultPostingsFormatFactory
Implements the default functionality of IPostingsFormatFactory.
To replace the DefaultPostingsFormatFactory instance, call SetPostingsFormatFactory(IPostingsFormatFactory) at application start up. DefaultPostingsFormatFactory can be subclassed or passed additional parameters to register additional codecs, inject dependencies, or change caching behavior, as shown in the following examples. Alternatively, IPostingsFormatFactory can be implemented to provide complete control over postings format creation and lifetimes.
Register Additional PostingsFormats
Additional codecs can be added by initializing the instance of DefaultPostingsFormatFactory and passing an array of PostingsFormat-derived types.
// Register the factory at application start up.
PostingsFormat.SetPostingsFormatFactory(new DefaultPostingsFormatFactory {
    CustomPostingsFormatTypes = new Type[] { typeof(MyPostingsFormat), typeof(AnotherPostingsFormat) }
});
Only Use Explicitly Defined PostingsFormats
PutPostingsFormatType(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 AnotherPostingsFormat doesn't have a default constructor, the NewPostingsFormat(Type)
method is overridden to supply the required parameters.
public class ExplicitPostingsFormatFactory : DefaultPostingsFormatFactory
{
    protected override void Initialize()
    {
        // Load specific codecs in a specific order.
        PutPostingsFormatType(typeof(MyPostingsFormat));
        PutPostingsFormatType(typeof(AnotherPostingsFormat));
    }
    protected override PostingsFormat NewPostingsFormat(Type type)
    {
        // Special case: AnotherPostingsFormat has a required dependency
        if (typeof(AnotherPostingsFormat).Equals(type))
            return new AnotherPostingsFormat(new SomeDependency());
        return base.NewPostingsFormat(type);
    }
}
// Register the factory at application start up.
PostingsFormat.SetPostingsFormatFactory(new ExplicitPostingsFormatFactory());See the Lucene.Net.Codecs namespace documentation for more examples of how to inject dependencies into PostingsFormat subclasses.
Use Reflection to Scan an Assembly for PostingsFormats
ScanForPostingsFormats(Assembly) or ScanForPostingsFormats(IEnumerable<Assembly>) can be used to scan assemblies using .NET Reflection for codec types and add all subclasses that are found automatically.
public class ScanningPostingsFormatFactory : DefaultPostingsFormatFactory
{
    protected override void Initialize()
    {
        // Load all default codecs
        base.Initialize();
        // Load all of the codecs inside of the same assembly that MyPostingsFormat is defined in
        ScanForPostingsFormats(typeof(MyPostingsFormat).Assembly);
    }
}
// Register the factory at application start up.
PostingsFormat.SetPostingsFormatFactory(new ScanningPostingsFormatFactory());Postings formats in the target assembly can be excluded from the scan by decorating them with the ExcludePostingsFormatFromScanAttribute.
Inherited Members
Namespace: Lucene.Net.Codecs
Assembly: Lucene.Net.dll
Syntax
public class DefaultPostingsFormatFactory : NamedServiceFactory<PostingsFormat>, IPostingsFormatFactory, IServiceListableConstructors
| Improve this Doc View SourceDefaultPostingsFormatFactory()
Creates a new instance of DefaultPostingsFormatFactory.
Declaration
public DefaultPostingsFormatFactory()Properties
| Improve this Doc View SourceAvailableServices
Gets a list of the available PostingsFormats (by name).
Declaration
public virtual ICollection<string> AvailableServices { get; }Property Value
| Type | Description | 
|---|---|
| System.Collections.Generic.ICollection<System.String> | A ICollection{string} of PostingsFormat names. | 
CustomPostingsFormatTypes
An array of custom PostingsFormat-derived types to be registered. This property can be initialized during construction of DefaultPostingsFormatFactory 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 PostingsFormat (via PostingsFormatNameAttribute) the custom type will replace the Lucene type with the same name.
Declaration
public IEnumerable<Type> CustomPostingsFormatTypes { get; set; }Property Value
| Type | Description | 
|---|---|
| System.Collections.Generic.IEnumerable<System.Type> | 
Methods
| Improve this Doc View SourceGetPostingsFormat(String)
Gets the PostingsFormat instance from the provided name.
Declaration
public virtual PostingsFormat GetPostingsFormat(string name)Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | name | The name of the PostingsFormat instance to retrieve. | 
Returns
| Type | Description | 
|---|---|
| PostingsFormat | The PostingsFormat instance. | 
GetPostingsFormat(Type)
Gets the PostingsFormat instance from the provided type.
Declaration
protected virtual PostingsFormat GetPostingsFormat(Type type)Parameters
| Type | Name | Description | 
|---|---|---|
| System.Type | type | The System.Type of PostingsFormat to retrieve. | 
Returns
| Type | Description | 
|---|---|
| PostingsFormat | The PostingsFormat instance. | 
GetPostingsFormatType(String)
Gets the PostingsFormat System.Type from the provided name.
Declaration
protected virtual Type GetPostingsFormatType(string name)Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | name | The name of the PostingsFormat System.Type to retrieve. | 
Returns
| Type | Description | 
|---|---|
| System.Type | The PostingsFormat System.Type. | 
Initialize()
Initializes the codec type cache with the known PostingsFormat types.
Override this method (and optionally call base.Initialize()) to add your
own PostingsFormat types by calling PutPostingsFormatType(Type) 
or ScanForPostingsFormats(Assembly).
If two types have the same name by using the PostingsFormatNameAttribute, the last one registered wins.
Declaration
protected override void Initialize()Overrides
NewPostingsFormat(Type)
Instantiates a PostingsFormat based on the provided type.
Declaration
protected virtual PostingsFormat NewPostingsFormat(Type type)Parameters
| Type | Name | Description | 
|---|---|---|
| System.Type | type | The System.Type of PostingsFormat to instantiate. | 
Returns
| Type | Description | 
|---|---|
| PostingsFormat | The new instance. | 
PutPostingsFormatType(Type)
Adds a PostingsFormat type to the Lucene.Net.Codecs.DefaultPostingsFormatFactory.postingsFormatNameToTypeMap, using the name provided in the PostingsFormatNameAttribute, if present, or the name of the codec class minus the "Codec" suffix as the name by default.
Note that if a PostingsFormat with the same name already exists in the map, calling this method will update it to the new type.
Declaration
protected virtual void PutPostingsFormatType(Type postingsFormat)Parameters
| Type | Name | Description | 
|---|---|---|
| System.Type | postingsFormat | A type that subclasses PostingsFormat. | 
ScanForPostingsFormats(IEnumerable<Assembly>)
Scans the given assemblies for subclasses of Codec
and adds their names to the Lucene.Net.Codecs.DefaultPostingsFormatFactory.postingsFormatNameToTypeMap. Note that names will be
automatically overridden if the PostingsFormat name appears multiple times - the last match wins.
Declaration
protected virtual void ScanForPostingsFormats(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 PostingsFormat name wins. | 
ScanForPostingsFormats(Assembly)
Scans the given assembly for subclasses of PostingsFormat
and adds their names to the Lucene.Net.Codecs.DefaultPostingsFormatFactory.postingsFormatNameToTypeMap. Note that names will be
automatically overridden if the PostingsFormat name appears multiple times - the last match wins.
Declaration
protected virtual void ScanForPostingsFormats(Assembly assembly)Parameters
| Type | Name | Description | 
|---|---|---|
| System.Reflection.Assembly | assembly | The assembly to scan. |