Fork me on GitHub
  • API

    Show / Hide Table of Contents

    Class AttributeSource

    An AttributeSource contains a list of different Attributes, and methods to add and get them. There can only be a single instance of an attribute in the same AttributeSource instance. This is ensured by passing in the actual type of the IAttribute to the AddAttribute<T>(), which then checks if an instance of that type is already present. If yes, it returns the instance, otherwise it creates a new instance and returns it.

    Inheritance
    System.Object
    AttributeSource
    TokenStream
    Inherited Members
    System.Object.Equals(System.Object, System.Object)
    System.Object.GetType()
    System.Object.MemberwiseClone()
    System.Object.ReferenceEquals(System.Object, System.Object)
    Namespace: Lucene.Net.Util
    Assembly: Lucene.Net.dll
    Syntax
    public class AttributeSource

    Constructors

    | Improve this Doc View Source

    AttributeSource()

    An AttributeSource using the default attribute factory DEFAULT_ATTRIBUTE_FACTORY.

    Declaration
    public AttributeSource()
    | Improve this Doc View Source

    AttributeSource(AttributeSource)

    An AttributeSource that uses the same attributes as the supplied one.

    Declaration
    public AttributeSource(AttributeSource input)
    Parameters
    Type Name Description
    AttributeSource input
    | Improve this Doc View Source

    AttributeSource(AttributeSource.AttributeFactory)

    An AttributeSource using the supplied AttributeSource.AttributeFactory for creating new IAttribute instances.

    Declaration
    public AttributeSource(AttributeSource.AttributeFactory factory)
    Parameters
    Type Name Description
    AttributeSource.AttributeFactory factory

    Properties

    | Improve this Doc View Source

    HasAttributes

    Returns true, if this AttributeSource has any attributes

    Declaration
    public bool HasAttributes { get; }
    Property Value
    Type Description
    System.Boolean

    Methods

    | Improve this Doc View Source

    AddAttribute<T>()

    The caller must pass in an interface type that extends IAttribute. This method first checks if an instance of the corresponding class is already in this AttributeSource and returns it. Otherwise a new instance is created, added to this AttributeSource and returned.

    Declaration
    public T AddAttribute<T>()
        where T : IAttribute
    Returns
    Type Description
    T
    Type Parameters
    Name Description
    T
    | Improve this Doc View Source

    AddAttributeImpl(Attribute)

    Expert: Adds a custom Attribute instance with one or more IAttribute interfaces.

    Please note: It is not guaranteed, that att is added to the AttributeSource, because the provided attributes may already exist. You should always retrieve the wanted attributes using GetAttribute<T>() after adding with this method and cast to your System.Type. The recommended way to use custom implementations is using an AttributeSource.AttributeFactory.

    Declaration
    public void AddAttributeImpl(Attribute att)
    Parameters
    Type Name Description
    Attribute att
    | Improve this Doc View Source

    CaptureState()

    Captures the state of all Attributes. The return value can be passed to RestoreState(AttributeSource.State) to restore the state of this or another AttributeSource.

    Declaration
    public virtual AttributeSource.State CaptureState()
    Returns
    Type Description
    AttributeSource.State
    | Improve this Doc View Source

    ClearAttributes()

    Resets all Attributes in this AttributeSource by calling Clear() on each IAttribute implementation.

    Declaration
    public void ClearAttributes()
    | Improve this Doc View Source

    CloneAttributes()

    Performs a clone of all Attribute instances returned in a new AttributeSource instance. This method can be used to e.g. create another TokenStream with exactly the same attributes (using AttributeSource(AttributeSource)). You can also use it as a (non-performant) replacement for CaptureState(), if you need to look into / modify the captured state.

    Declaration
    public AttributeSource CloneAttributes()
    Returns
    Type Description
    AttributeSource
    | Improve this Doc View Source

    CopyTo(AttributeSource)

    Copies the contents of this AttributeSource to the given target AttributeSource. The given instance has to provide all IAttributes this instance contains. The actual attribute implementations must be identical in both AttributeSource instances; ideally both AttributeSource instances should use the same AttributeSource.AttributeFactory. You can use this method as a replacement for RestoreState(AttributeSource.State), if you use CloneAttributes() instead of CaptureState().

    Declaration
    public void CopyTo(AttributeSource target)
    Parameters
    Type Name Description
    AttributeSource target
    | Improve this Doc View Source

    Equals(Object)

    Declaration
    public override bool Equals(object obj)
    Parameters
    Type Name Description
    System.Object obj
    Returns
    Type Description
    System.Boolean
    Overrides
    System.Object.Equals(System.Object)
    | Improve this Doc View Source

    GetAttribute<T>()

    The caller must pass in an interface type that extends IAttribute. Returns the instance of the corresponding Attribute contained in this AttributeSource

    Declaration
    public virtual T GetAttribute<T>()
        where T : IAttribute
    Returns
    Type Description
    T
    Type Parameters
    Name Description
    T
    Exceptions
    Type Condition
    System.ArgumentException

    if this AttributeSource does not contain the Attribute. It is recommended to always use AddAttribute<T>() even in consumers of TokenStreams, because you cannot know if a specific TokenStream really uses a specific Attribute. AddAttribute<T>() will automatically make the attribute available. If you want to only use the attribute, if it is available (to optimize consuming), use HasAttribute<T>().

    | Improve this Doc View Source

    GetAttributeClassesEnumerator()

    Returns a new iterator that iterates the attribute classes in the same order they were added in.

    Declaration
    public IEnumerator<Type> GetAttributeClassesEnumerator()
    Returns
    Type Description
    System.Collections.Generic.IEnumerator<System.Type>
    | Improve this Doc View Source

    GetAttributeFactory()

    Returns the used AttributeSource.AttributeFactory.

    Declaration
    public AttributeSource.AttributeFactory GetAttributeFactory()
    Returns
    Type Description
    AttributeSource.AttributeFactory
    | Improve this Doc View Source

    GetAttributeImplsEnumerator()

    Returns a new iterator that iterates all unique IAttribute implementations. This iterator may contain less entries than GetAttributeClassesEnumerator(), if one instance implements more than one IAttribute interface.

    Declaration
    public IEnumerator<Attribute> GetAttributeImplsEnumerator()
    Returns
    Type Description
    System.Collections.Generic.IEnumerator<Attribute>
    | Improve this Doc View Source

    GetHashCode()

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    System.Int32
    Overrides
    System.Object.GetHashCode()
    | Improve this Doc View Source

    HasAttribute<T>()

    The caller must pass in an interface type that extends IAttribute. Returns true, if this AttributeSource contains the corrsponding Attribute.

    Declaration
    public bool HasAttribute<T>()
        where T : IAttribute
    Returns
    Type Description
    System.Boolean
    Type Parameters
    Name Description
    T
    | Improve this Doc View Source

    ReflectAsString(Boolean)

    This method returns the current attribute values as a string in the following format by calling the ReflectWith(IAttributeReflector) method:

    • if prependAttClass=true: "AttributeClass.Key=value,AttributeClass.Key=value"
    • if prependAttClass=false: "key=value,key=value"
    Declaration
    public string ReflectAsString(bool prependAttClass)
    Parameters
    Type Name Description
    System.Boolean prependAttClass
    Returns
    Type Description
    System.String
    See Also
    ReflectWith(IAttributeReflector)
    | Improve this Doc View Source

    ReflectWith(IAttributeReflector)

    This method is for introspection of attributes, it should simply add the key/values this AttributeSource holds to the given IAttributeReflector.

    This method iterates over all IAttribute implementations and calls the corresponding ReflectWith(IAttributeReflector) method.

    Declaration
    public void ReflectWith(IAttributeReflector reflector)
    Parameters
    Type Name Description
    IAttributeReflector reflector
    See Also
    ReflectWith(IAttributeReflector)
    | Improve this Doc View Source

    RestoreState(AttributeSource.State)

    Restores this state by copying the values of all attribute implementations that this state contains into the attributes implementations of the targetStream. The targetStream must contain a corresponding instance for each argument contained in this state (e.g. it is not possible to restore the state of an AttributeSource containing a ICharTermAttribute into a AttributeSource using a Token instance as implementation).

    Note that this method does not affect attributes of the targetStream that are not contained in this state. In other words, if for example the targetStream contains an IOffsetAttribute, but this state doesn't, then the value of the IOffsetAttribute remains unchanged. It might be desirable to reset its value to the default, in which case the caller should first call ClearAttributes() (TokenStream.ClearAttributes() on the targetStream.

    Declaration
    public void RestoreState(AttributeSource.State state)
    Parameters
    Type Name Description
    AttributeSource.State state
    | Improve this Doc View Source

    ToString()

    Returns a string consisting of the class's simple name, the hex representation of the identity hash code, and the current reflection of all attributes.

    Declaration
    public override string ToString()
    Returns
    Type Description
    System.String
    Overrides
    System.Object.ToString()
    See Also
    ReflectAsString(Boolean)
    • Improve this Doc
    • View Source
    Back to top Copyright © 2020 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.