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?
Note
This API is experimental and might change in incompatible ways in the next release.
Inherited Members
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 |
|
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?
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?
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.
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
.
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 |
UnsupportedSpatialOperationException | If the strategy does not support the SpatialOperation in |
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 |
UnsupportedSpatialOperationException | If the strategy does not support the SpatialOperation in |
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. |