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 FieldCache, or some other type of cache? When?
Note that a SpatialStrategy is not involved with the Lucene stored field values of shapes, which is immaterial to indexing and search.
Thread-safe.
Inheritance
Namespace: Lucene.Net.Spatial
Assembly: Lucene.Net.Spatial.dll
Syntax
public abstract class SpatialStrategy : object
Constructors
| Improve this Doc View SourceSpatialStrategy(SpatialContext, String)
Constructs the spatial strategy with its mandatory arguments.
Declaration
protected SpatialStrategy(SpatialContext ctx, string fieldName)
Parameters
Type | Name | Description |
---|---|---|
SpatialContext | ctx | |
System.String | fieldName |
Fields
| Improve this Doc View Sourcem_ctx
Declaration
protected readonly SpatialContext m_ctx
Field Value
Type | Description |
---|---|
SpatialContext |
Properties
| Improve this Doc View SourceFieldName
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 |
---|---|
System.String | Not null. |
SpatialContext
Declaration
public virtual SpatialContext SpatialContext { get; }
Property Value
Type | Description |
---|---|
SpatialContext |
Methods
| Improve this Doc View SourceCreateIndexableFields(IShape)
Returns the IndexableField(s) from the shape
that are to be
added to the 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. |
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 | |
System.Double | multiplier |
Returns
Type | Description |
---|---|
ValueSource |
MakeFilter(SpatialArgs)
Make a Filter based principally on SpatialOperation
and 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 |
---|---|
UnsupportedSpatialOperation | If the strategy does not support the SpatialOperation in |
MakeQuery(SpatialArgs)
Make a Query based principally on SpatialOperation
and 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 |
---|---|
UnsupportedSpatialOperation | 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()
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String |