1. Solr
  2. SOLR-2155

Geospatial search using geohash prefixes


    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:



      The status of this issue is a plugin for Solr 3.x located here: Look at the introductory readme and download the plugin .jar file. Lucene 4's new spatial module is largely based on this code. The Solr 4 glue for it should come very soon but as of this writing it's hosted temporarily at For more information on using SOLR-2155 with Solr 3, see This JIRA issue is closed because it won't be committed in its current form.

      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 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.

      1. GeoHashPrefixFilter.patch
        37 kB
        David Smiley
      2. GeoHashPrefixFilter.patch
        49 kB
        David Smiley
      3. GeoHashPrefixFilter.patch
        69 kB
        David Smiley
      4. SOLR.2155.p3.patch
        10 kB
        Bill Bell
      5. SOLR.2155.p3tests.patch
        86 kB
        Bill Bell
      6. SOLR-2155_GeoHashPrefixFilter_with_sorting_no_poly.patch
        177 kB
        David Smiley
        95 kB
        David Smiley
      8. Solr2155-for-1.0.2-3.x-port.patch
        5 kB
        Mikhail Khludnev
        96 kB
        David Smiley
        136 kB
        David Smiley

        Issue Links


          No work has yet been logged on this issue.


            • Assignee:
              David Smiley
              David Smiley
            • Votes:
              21 Vote for this issue
              25 Start watching this issue


              • Created: