title: SpatialQuery for location based search using Lucene
body: <p>My lucene index has got latitude and longitudes fields indexed as follows:</p>
  
  <pre><code>doc.Add(new Field("latitude", latitude.ToString() , Field.Store.YES, Field.Index.UN_TOKENIZED));
  
  doc.Add(new Field("longitude", longitude.ToString(), Field.Store.YES, Field.Index.UN_TOKENIZED));
  </code></pre>
  
  <p>I want to retrieve a set of documents from this index whose lat and long values are in a given range.</p>
  
  <p>As you already know, Lat and long could be negative values. How do i correctly store signed decimal numbers in Lucene?
  Would the approach mentioned below give correct results or is there any other way to do this?</p>
  
  <pre><code> Term lowerLatitude = new Term("latitude", bounds.South.ToString() );
                  Term upperLatitude = new Term("latitude", bounds.North.ToString());
                  RangeQuery latitudeRangeQuery = new RangeQuery(lowerLatitude, upperLatitude, true);
                  findLocationQuery.Add(latitudeRangeQuery, BooleanClause.Occur.SHOULD);
  
  
  
                  Term lowerLongitude = new Term("longitude", bounds.West.ToString());
                  Term upperLongitude = new Term("longitude", bounds.East.ToString());
                  RangeQuery longitudeRangeQuery = new RangeQuery(lowerLongitude, upperLongitude, true);
                  findLocationQuery.Add(longitudeRangeQuery, BooleanClause.Occur.SHOULD);
  </code></pre>
  
  <p>Also,I wanted to know how Lucene's ConstantScoreRangeQuery is better than RangeQuery  class.</p>
  
  <p>Am facing another problem in this context:
  I've one of the documents in the index with the following 3 cities:</p>
  
  <ul>
  <li><p>Lyons, IL</p>
  
  <p>Oak Brook, IL</p>
  
  <p>San Francisco, CA</p></li>
  </ul>
  
  <p>If i give input as "Lyons, IL" then this record comes up.
  But if i give San Francisco, CA as input, then it does not.</p>
  
  <p>However, if i store the cities for this document as follows:</p>
  
  <ul>
  <li><p>San Francisco, CA </p>
  
  <p>Lyons, IL</p>
  
  <p>Oak Brook, IL</p>
  
  <p>and when i give San Francisco, CA  as input, then this record shows in the search results.</p></li>
  </ul>
  
  <p>What i want here is that if i type any of the 3 cities in input,I should get this document in the search results.</p>
  
  <p>Please help me achieve this.</p>
  
  <p>Thanks.</p>