Fork me on GitHub
  • API

    Show / Hide Table of Contents

    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.
    Inheritance
    object
    NamedServiceFactory<PostingsFormat>
    DefaultPostingsFormatFactory
    Implements
    IPostingsFormatFactory
    IServiceListable
    Inherited Members
    NamedServiceFactory<PostingsFormat>.m_initializationLock
    NamedServiceFactory<PostingsFormat>.EnsureInitialized()
    NamedServiceFactory<PostingsFormat>.CodecsAssembly
    NamedServiceFactory<PostingsFormat>.IsServiceType(Type)
    NamedServiceFactory<PostingsFormat>.GetServiceName(Type)
    NamedServiceFactory<PostingsFormat>.GetCanonicalName(Type)
    NamedServiceFactory<PostingsFormat>.IsFullyTrusted
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Lucene.Net.Codecs
    Assembly: Lucene.Net.dll
    Syntax
    public class DefaultPostingsFormatFactory : NamedServiceFactory<PostingsFormat>, IPostingsFormatFactory, IServiceListable

    Constructors

    DefaultPostingsFormatFactory()

    Creates a new instance of DefaultPostingsFormatFactory.

    Declaration
    public DefaultPostingsFormatFactory()
    See Also
    IPostingsFormatFactory
    IServiceListable
    ExcludePostingsFormatFromScanAttribute

    Properties

    AvailableServices

    Gets a list of the available PostingsFormats (by name).

    Declaration
    public virtual ICollection<string> AvailableServices { get; }
    Property Value
    Type Description
    ICollection<string>

    A ICollection{string} of PostingsFormat names.

    See Also
    IPostingsFormatFactory
    IServiceListable
    ExcludePostingsFormatFromScanAttribute

    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
    IEnumerable<Type>
    See Also
    IPostingsFormatFactory
    IServiceListable
    ExcludePostingsFormatFromScanAttribute

    Methods

    GetPostingsFormat(string)

    Gets the PostingsFormat instance from the provided name.

    Declaration
    public virtual PostingsFormat GetPostingsFormat(string name)
    Parameters
    Type Name Description
    string name

    The name of the PostingsFormat instance to retrieve.

    Returns
    Type Description
    PostingsFormat

    The PostingsFormat instance.

    See Also
    IPostingsFormatFactory
    IServiceListable
    ExcludePostingsFormatFromScanAttribute

    GetPostingsFormat(Type)

    Gets the PostingsFormat instance from the provided type.

    Declaration
    protected virtual PostingsFormat GetPostingsFormat(Type type)
    Parameters
    Type Name Description
    Type type

    The Type of PostingsFormat to retrieve.

    Returns
    Type Description
    PostingsFormat

    The PostingsFormat instance.

    See Also
    IPostingsFormatFactory
    IServiceListable
    ExcludePostingsFormatFromScanAttribute

    GetPostingsFormatType(string)

    Gets the PostingsFormatType from the provided name.

    Declaration
    protected virtual Type GetPostingsFormatType(string name)
    Parameters
    Type Name Description
    string name

    The name of the PostingsFormatType to retrieve.

    Returns
    Type Description
    Type

    The PostingsFormatType.

    See Also
    IPostingsFormatFactory
    IServiceListable
    ExcludePostingsFormatFromScanAttribute

    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
    NamedServiceFactory<PostingsFormat>.Initialize()
    See Also
    IPostingsFormatFactory
    IServiceListable
    ExcludePostingsFormatFromScanAttribute

    NewPostingsFormat(Type)

    Instantiates a PostingsFormat based on the provided type.

    Declaration
    protected virtual PostingsFormat NewPostingsFormat(Type type)
    Parameters
    Type Name Description
    Type type

    The Type of PostingsFormat to instantiate.

    Returns
    Type Description
    PostingsFormat

    The new instance.

    See Also
    IPostingsFormatFactory
    IServiceListable
    ExcludePostingsFormatFromScanAttribute

    PutPostingsFormatType(Type)

    Adds a PostingsFormat type to the 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
    Type postingsFormat

    A type that subclasses PostingsFormat.

    See Also
    IPostingsFormatFactory
    IServiceListable
    ExcludePostingsFormatFromScanAttribute

    ScanForPostingsFormats(IEnumerable<Assembly>)

    Scans the given assemblies for subclasses of Codec and adds their names to the 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
    IEnumerable<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.

    See Also
    IPostingsFormatFactory
    IServiceListable
    ExcludePostingsFormatFromScanAttribute

    ScanForPostingsFormats(Assembly)

    Scans the given assembly for subclasses of PostingsFormat and adds their names to the 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
    Assembly assembly

    The assembly to scan.

    See Also
    IPostingsFormatFactory
    IServiceListable
    ExcludePostingsFormatFromScanAttribute

    Implements

    IPostingsFormatFactory
    IServiceListable

    See Also

    IPostingsFormatFactory
    IServiceListable
    ExcludePostingsFormatFromScanAttribute
    Back to top Copyright © 2024 The Apache Software Foundation, Licensed under the Apache License, Version 2.0
    Apache Lucene.Net, Lucene.Net, Apache, the Apache feather logo, and the Apache Lucene.Net project logo are trademarks of The Apache Software Foundation.
    All other marks mentioned may be trademarks or registered trademarks of their respective owners.