# lucene-dev mailing list archives

##### Site index · List index
Message view
Top
From "Lance Norskog (JIRA)" <j...@apache.org>
Subject [jira] Commented: (SOLR-2155) Geospatial search using geohash prefixes
Date Tue, 08 Feb 2011 07:11:57 GMT
```
[ https://issues.apache.org/jira/browse/SOLR-2155?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12991818#comment-12991818
]

Lance Norskog commented on SOLR-2155:
-------------------------------------

The lat/long version has to be rotated away from the "true". Then, the calculations don't
blow up at the poles or the equator.

The real answer to doing geo and have it always work is to use quaternions. A lat/lon pair
is essentially a complex number: latitude is the scalar and longitude rotates back to 0. A
quaternion is a 4-valued variation of complex numbers: "a + bi + cj + dk" where i,j,k are
separate values of sqrt(-1), assuming an infinite number of such values. A geo position, projected
onto quaternions, gives a subspace.

There are a bunch of 3D algorithms which use quaternions because they don't have problems
at the (0->1) boundary.  The classic apocryphal story is the jet fighter pilot on a test
flight: he crossed the equator and the plane flipped upside down. Quaternions don't have this
problem.

[SLERP|http://en.wikipedia.org/wiki/Slerp] explains the problem of distance on a sphere. How
to do distances, box containment, etc. I don't know. I am _so_ not a math guy.

> Geospatial search using geohash prefixes
> ----------------------------------------
>
>                 Key: SOLR-2155
>                 URL: https://issues.apache.org/jira/browse/SOLR-2155
>             Project: Solr
>          Issue Type: Improvement
>            Reporter: David Smiley
>         Attachments: GeoHashPrefixFilter.patch, GeoHashPrefixFilter.patch, GeoHashPrefixFilter.patch
>
>
> There currently isn't a solution in Solr for doing geospatial filtering on documents
that have a variable number of points.  This scenario occurs when there is location extraction
(i.e. via a "gazateer") occurring on free text.  None, one, or many geospatial locations might
be extracted from any given document and users want to limit their search results to those
occurring in a user-specified area.
> I've implemented this by furthering the GeoHash based work in Lucene/Solr with a geohash
prefix based filter.  A geohash refers to a lat-lon box on the earth.  Each successive character
added further subdivides the box into a 4x8 (or 8x4 depending on the even/odd length of the
geohash) grid.  The first step in this scheme is figuring out which geohash grid squares cover
the user's search query.  I've added various extra methods to GeoHashUtils (and added tests)
to assist in this purpose.  The next step is an actual Lucene Filter, GeoHashPrefixFilter,
that uses these geohash prefixes in TermsEnum.seek() to skip to relevant grid squares in the
index.  Once a matching geohash grid is found, the points therein are compared against the
user's query to see if it matches.  I created an abstraction GeoShape extended by subclasses
named PointDistance... and CartesianBox.... to support different queried shapes so that the
filter need not care about these details.
> This work was presented at LuceneRevolution in Boston on October 8th.

--
This message is automatically generated by JIRA.
-