title: Geohash: Using libgeohash to find neighbors
body: <p>In my application I am storing Geohash of all users in a table and want to find neighbors of a user using those Geohashes.</p>
  
  <p>As per info I gathered about Geohash on <a href="https://en.wikipedia.org/wiki/Geohash#Uses" rel="nofollow">Wiki</a>:</p>
  
  <blockquote>
    <p>When used in a database, the structure of geohashed data has two
    advantages. First, data indexed by geohash will have all points for a
    given rectangular area in contiguous slices (the number of slices
    depends on the precision required and the presence of geohash "fault
    lines"). This is especially useful in database systems where queries
    on a single index are much easier or faster than multiple-index
    queries. Second, this index structure can be used for a
    quick-and-dirty proximity search - the closest points are often among
    the closest geohashes.</p>
  </blockquote>
  
  <p>So for e.g. to find neighbors of "sj8101b085", I just had planned to search hashes by doing:</p>
  
  <pre><code>SELECT * FROM Users WHERE Geohash LIKE 'sj8101b085%'
  </code></pre>
  
  <p>And then by firing same query by reducing the hash length one by one i.e. "sj8101b08%", "sj8101b0%" and so on till I get desired number of neighbors. I was under impression that this is all I need to do.</p>
  
  <p>But then I found this C library <a href="https://github.com/lyokato/libgeohash" rel="nofollow">libgeohash</a> referred at the bottom of the same article. The library has a function called <code>GEOHASH_get_adjacent</code> which gives us neighboring hashes of given hash. A geohash string represents a rectangle area on earth. And this function returns geohashes representing neighboring rectangles. It means I got to run this function in recursion (neighbors and then neighbors of neighbors and so on) till I get desired number of neighbors.  </p>
  
  <p>Now I am really confused how shall I write my search algorithm? Using first approach or using second?</p>