Indexing:
The latlong coordinate is split into two fields with name which stores lat and long part separately, with name as [origFieldName]_0[subFieldSuffix] and [origFieldName]_1[subFieldSuffix] and type as TrieDoubleField (faster for range search).
Note: Tries field split the original field into multiple searchable ranges governed by precision steps
Query:
Spatial query: create a bounding box centered at given point (pt=xxx) and distance (d=xxx). If query type is bounding box, create two range queries for lat and long part joined by "AND". A special scorer "SpatialScorer" is created. Distance will be calculated in "match/score/explain" method if query type is not bbox and latlong value of the current doc falls within the bounding box
Note: Match method will be used to filter docs
Solr.GeoHashField
Definition:
Indexing:
Split the lat, long part and calculate geohash of lat and long and create a single filed (See GeoHashField.toInternal)
Query:
Delegate to GeohashHaversineFunction: iterate through all docs, decode the geohash field, calculate the distance of given point (pt=xxx) and the decoded geo point. Note that distance is always calculated (See DoubleDocValues.getRangeScorer and GeohashHaversineFunction.getValues), compare to latLongType, this is not optimizedSpatialFilterQParser is used to produce a spatial filter query, which is in turn created by plugin (SpatialBoxQparserPlugin(name=geofilt) SpatialFilterQParserPlugin(name=bbox))
Solr.SpatialRecursivePrefixTreeFieldType
Definition:
Advantages:
can be multi-valued, support complex shapes, faster filtering. Utlize lucene spatial package
Indexing:
A global GeoHashPrefixTree is created to represent the word with max 24 levels Each point to index is coverted to a Point shap and a list of cell is generated, each cell represent a prefix of the geohash of the point (eg, the geohash length is 12, 11 cells will be generated), the cell values are concatinated to form a token stream
Query:
Create a circle shape with the given point (pt=xxx) and distance (d=xxx) Delegate to PrefixTreeStrategy's makeDistanceValueSource method For each indexReader, a cached will be built to store docId -> list of geohash cell's center point. Dinstance is calculated for each cell and the minimum is returned. For filter query (no score is required eg: q={!geofilt score=none sfield=geo pt=54.729696, -98.525491 d=10}) distance calculation is not needed. Delegates to IntersectsPrefixTreeFilter. It traverses the prefix tree and find cells that intersect with the circle(the cell's geohash is prefix of the circle). It then iterate through the terms. If the term's value equals the cell's geohash, the sub cells are added to the set to traverse until reaching the given prefix grid scan level. All matching term's docIds are added to the result Field's SpatialStrategy will be cached to avoid repeated creation