Fork me on GitHub
  • API

    Show / Hide Table of Contents

    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.
    Inheritance
    object
    NamedServiceFactory<DocValuesFormat>
    DefaultDocValuesFormatFactory
    Implements
    IDocValuesFormatFactory
    IServiceListable
    Inherited Members
    NamedServiceFactory<DocValuesFormat>.m_initializationLock
    NamedServiceFactory<DocValuesFormat>.EnsureInitialized()
    NamedServiceFactory<DocValuesFormat>.CodecsAssembly
    NamedServiceFactory<DocValuesFormat>.IsServiceType(Type)
    NamedServiceFactory<DocValuesFormat>.GetServiceName(Type)
    NamedServiceFactory<DocValuesFormat>.GetCanonicalName(Type)
    NamedServiceFactory<DocValuesFormat>.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 DefaultDocValuesFormatFactory : NamedServiceFactory<DocValuesFormat>, IDocValuesFormatFactory, IServiceListable

    Constructors

    DefaultDocValuesFormatFactory()

    Creates a new instance of DefaultDocValuesFormatFactory.

    Declaration
    public DefaultDocValuesFormatFactory()
    See Also
    IDocValuesFormatFactory
    IServiceListable
    ExcludeDocValuesFormatFromScanAttribute

    Properties

    AvailableServices

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

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

    A ICollection{string} of DocValuesFormat names.

    See Also
    IDocValuesFormatFactory
    IServiceListable
    ExcludeDocValuesFormatFromScanAttribute

    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
    IEnumerable<Type>
    See Also
    IDocValuesFormatFactory
    IServiceListable
    ExcludeDocValuesFormatFromScanAttribute

    Methods

    GetDocValuesFormat(string)

    Gets the DocValuesFormat instance from the provided name.

    Declaration
    public virtual DocValuesFormat GetDocValuesFormat(string name)
    Parameters
    Type Name Description
    string name

    The name of the DocValuesFormat instance to retrieve.

    Returns
    Type Description
    DocValuesFormat

    The DocValuesFormat instance.

    See Also
    IDocValuesFormatFactory
    IServiceListable
    ExcludeDocValuesFormatFromScanAttribute

    GetDocValuesFormat(Type)

    Gets the DocValuesFormat instance from the provided type.

    Declaration
    protected virtual DocValuesFormat GetDocValuesFormat(Type type)
    Parameters
    Type Name Description
    Type type

    The Type of DocValuesFormat to retrieve.

    Returns
    Type Description
    DocValuesFormat

    The DocValuesFormat instance.

    See Also
    IDocValuesFormatFactory
    IServiceListable
    ExcludeDocValuesFormatFromScanAttribute

    GetDocValuesFormatType(string)

    Gets the DocValuesFormatType from the provided name.

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

    The name of the DocValuesFormatType to retrieve.

    Returns
    Type Description
    Type

    The DocValuesFormatType.

    See Also
    IDocValuesFormatFactory
    IServiceListable
    ExcludeDocValuesFormatFromScanAttribute

    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
    NamedServiceFactory<DocValuesFormat>.Initialize()
    See Also
    IDocValuesFormatFactory
    IServiceListable
    ExcludeDocValuesFormatFromScanAttribute

    NewDocValuesFormat(Type)

    Instantiates a DocValuesFormat based on the provided type.

    Declaration
    protected virtual DocValuesFormat NewDocValuesFormat(Type type)
    Parameters
    Type Name Description
    Type type

    The Type of DocValuesFormat to instantiate.

    Returns
    Type Description
    DocValuesFormat

    The new instance.

    See Also
    IDocValuesFormatFactory
    IServiceListable
    ExcludeDocValuesFormatFromScanAttribute

    PutDocValuesFormatType(Type)

    Adds a DocValuesFormat type to the 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
    Type docValuesFormat

    A type that subclasses DocValuesFormat.

    See Also
    IDocValuesFormatFactory
    IServiceListable
    ExcludeDocValuesFormatFromScanAttribute

    ScanForDocValuesFormats(IEnumerable<Assembly>)

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

    See Also
    IDocValuesFormatFactory
    IServiceListable
    ExcludeDocValuesFormatFromScanAttribute

    ScanForDocValuesFormats(Assembly)

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

    The assembly to scan.

    See Also
    IDocValuesFormatFactory
    IServiceListable
    ExcludeDocValuesFormatFromScanAttribute

    Implements

    IDocValuesFormatFactory
    IServiceListable

    See Also

    IDocValuesFormatFactory
    IServiceListable
    ExcludeDocValuesFormatFromScanAttribute
    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.