Fork me on GitHub
  • API

    Show / Hide Table of Contents

    Class SpatialStrategy

    The SpatialStrategy encapsulates an approach to indexing and searching based on shapes.

    Different implementations will support different features. A strategy should document these common elements:
    • Can it index more than one shape per field?
    • What types of shapes can be indexed?
    • What types of query shapes can be used?
    • What types of query operations are supported? This might vary per shape.
    • Does it use the Lucene.Net.Search.FieldCache, or some other type of cache? When?
    If a strategy only supports certain shapes at index or query time, then in general it will throw an exception if given an incompatible one. It will not be coerced into compatibility.

    Note that a SpatialStrategy is not involved with the Lucene stored field values of shapes, which is immaterial to indexing and search.

    Thread-safe.

    Note

    This API is experimental and might change in incompatible ways in the next release.

    Inheritance
    object
    SpatialStrategy
    PrefixTreeStrategy
    SerializedDVStrategy
    PointVectorStrategy
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    Namespace: Lucene.Net.Spatial
    Assembly: Lucene.Net.Spatial.dll
    Syntax
    public abstract class SpatialStrategy

    Constructors

    SpatialStrategy(SpatialContext, string)

    Constructs the spatial strategy with its mandatory arguments.

    Declaration
    protected SpatialStrategy(SpatialContext ctx, string fieldName)
    Parameters
    Type Name Description
    SpatialContext ctx
    string fieldName
    Exceptions
    Type Condition
    ArgumentNullException

    ctx or fieldName is null or fieldName is empty.

    Fields

    m_ctx

    The SpatialStrategy encapsulates an approach to indexing and searching based on shapes.

    Different implementations will support different features. A strategy should document these common elements:
    • Can it index more than one shape per field?
    • What types of shapes can be indexed?
    • What types of query shapes can be used?
    • What types of query operations are supported? This might vary per shape.
    • Does it use the Lucene.Net.Search.FieldCache, or some other type of cache? When?
    If a strategy only supports certain shapes at index or query time, then in general it will throw an exception if given an incompatible one. It will not be coerced into compatibility.

    Note that a SpatialStrategy is not involved with the Lucene stored field values of shapes, which is immaterial to indexing and search.

    Thread-safe.

    Note

    This API is experimental and might change in incompatible ways in the next release.

    Declaration
    protected readonly SpatialContext m_ctx
    Field Value
    Type Description
    SpatialContext

    Properties

    FieldName

    The name of the field or the prefix of them if there are multiple fields needed internally.

    Declaration
    public virtual string FieldName { get; }
    Property Value
    Type Description
    string

    Not null.

    SpatialContext

    The SpatialStrategy encapsulates an approach to indexing and searching based on shapes.

    Different implementations will support different features. A strategy should document these common elements:
    • Can it index more than one shape per field?
    • What types of shapes can be indexed?
    • What types of query shapes can be used?
    • What types of query operations are supported? This might vary per shape.
    • Does it use the Lucene.Net.Search.FieldCache, or some other type of cache? When?
    If a strategy only supports certain shapes at index or query time, then in general it will throw an exception if given an incompatible one. It will not be coerced into compatibility.

    Note that a SpatialStrategy is not involved with the Lucene stored field values of shapes, which is immaterial to indexing and search.

    Thread-safe.

    Note

    This API is experimental and might change in incompatible ways in the next release.

    Declaration
    public virtual SpatialContext SpatialContext { get; }
    Property Value
    Type Description
    SpatialContext

    Methods

    CreateIndexableFields(IShape)

    Returns the IndexableField(s) from the shape that are to be added to the Lucene.Net.Documents.Document. These fields are expected to be marked as indexed and not stored.

    Note: If you want to store the shape as a string for retrieval in search results, you could add it like this:
    document.Add(new StoredField(fieldName, ctx.ToString(shape)));
    The particular string representation used doesn't matter to the Strategy since it doesn't use it.
    Declaration
    public abstract Field[] CreateIndexableFields(IShape shape)
    Parameters
    Type Name Description
    IShape shape
    Returns
    Type Description
    Field[]

    Not null nor will it have null elements.

    Exceptions
    Type Condition
    NotSupportedException

    if given a shape incompatible with the strategy

    MakeDistanceValueSource(IPoint)

    See MakeDistanceValueSource(IPoint, double) called with a multiplier of 1.0 (i.e. units of degrees).

    Declaration
    public virtual ValueSource MakeDistanceValueSource(IPoint queryPoint)
    Parameters
    Type Name Description
    IPoint queryPoint
    Returns
    Type Description
    ValueSource

    MakeDistanceValueSource(IPoint, double)

    Make a ValueSource returning the distance between the center of the indexed shape and queryPoint. If there are multiple indexed shapes then the closest one is chosen. The result is multiplied by multiplier, which conveniently is used to get the desired units.

    Declaration
    public abstract ValueSource MakeDistanceValueSource(IPoint queryPoint, double multiplier)
    Parameters
    Type Name Description
    IPoint queryPoint
    double multiplier
    Returns
    Type Description
    ValueSource

    MakeFilter(SpatialArgs)

    Make a Filter based principally on SpatialOperation and Spatial4n.Shapes.IShape from the supplied args.

    If a subclasses implements MakeQuery(SpatialArgs) then this method could be simply:
    return new QueryWrapperFilter(MakeQuery(args).Query);
    Declaration
    public abstract Filter MakeFilter(SpatialArgs args)
    Parameters
    Type Name Description
    SpatialArgs args
    Returns
    Type Description
    Filter
    Exceptions
    Type Condition
    NotSupportedException

    If the strategy does not support the shape in args.

    UnsupportedSpatialOperationException

    If the strategy does not support the SpatialOperation in args.

    MakeQuery(SpatialArgs)

    Make a Query based principally on SpatialOperation and Spatial4n.Shapes.IShape from the supplied args. The default implementation is

    return new ConstantScoreQuery(MakeFilter(args));
    Declaration
    public virtual ConstantScoreQuery MakeQuery(SpatialArgs args)
    Parameters
    Type Name Description
    SpatialArgs args
    Returns
    Type Description
    ConstantScoreQuery
    Exceptions
    Type Condition
    NotSupportedException

    If the strategy does not support the shape in args.

    UnsupportedSpatialOperationException

    If the strategy does not support the SpatialOperation in args.

    MakeRecipDistanceValueSource(IShape)

    Returns a ValueSource with values ranging from 1 to 0, depending inversely on the distance from MakeDistanceValueSource(IPoint). The formula is c / (d + c) where 'd' is the distance and 'c' is one tenth the distance to the farthest edge from the center. Thus the scores will be 1 for indexed points at the center of the query shape and as low as ~0.1 at its furthest edges.

    Declaration
    public ValueSource MakeRecipDistanceValueSource(IShape queryShape)
    Parameters
    Type Name Description
    IShape queryShape
    Returns
    Type Description
    ValueSource

    ToString()

    Returns a string that represents the current object.

    Declaration
    public override string ToString()
    Returns
    Type Description
    string

    A string that represents the current object.

    Overrides
    object.ToString()
    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.