lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Phillip Rhodes <spamsu...@rhoderunner.com>
Subject Re: all records within distance -- small index
Date Wed, 28 Feb 2007 19:24:56 GMT
I just add a 1000 to it, but in my rounding, I always make sure that I have 4 decimal places.


Here are some code snippets; 


//indexing the lat 
double lat = physicalAddress.getLatitude() + 1000.0; 
Double latitude = new Double(lat); 
document.add(new Field(Indexer.LATITUDE, latitude.toString(), Field.Store.YES, 
Field.Index.UN_TOKENIZED)); 


//constructing the lat filter 
Double minLatitude = new Double(sp.getInitialLatitude() 
- deltaLatitude + 1000.0); 
Double maxLatitude = new Double(sp.getInitialLatitude() 
+ deltaLatitude + 1000.0); 
RangeFilter latfilter = new RangeFilter(Indexer.LATITUDE, 
getRound(minLatitude), getRound(maxLatitude), true, 
true); 


//my rounding function 
public String getRound(Double value) { 
int decimalPlace = 4; 
BigDecimal bd = new BigDecimal(value); 
bd = bd.setScale(decimalPlace, BigDecimal.ROUND_UP); 
//r = bd.doubleValue(); 
String x = bd.toString(); 
log.debug("orig=" + value); 
log.debug("value=" + x); 
return x; 
//System.out.println(r); // output is 3.15 

} 


----- Original Message ----- 
From: "no spam" <mrs.nospam@gmail.com> 
To: java-user@lucene.apache.org 
Sent: Tuesday, February 27, 2007 11:09:04 PM (GMT-0500) America/New_York 
Subject: Re: all records within distance -- small index 

I just dug my book out. Chapter six shows a custom sort that implements a 
SortComparatorSource combined with a TermQuery. I like the way that works 
but I guess what I really need to do is a RangeQuery as well. 

I have another large index that has 1.2 million docs. I use a query along 
with a hit collector for that. I then get the lat/lon for each doc and calc 
the distance there. I use some radian math to prevent the expensive great 
circle distance first. I guess this is more expensive than your range query 
above? I've indexed my docs with lat/lon encoded in a single field comma 
separated. I still get < 1 second search times but I know there has to be a 
better way. 

Don't you have to multiply your lat/lon by 1000 to preserve decimal accuracy 
and then calc your offset? Maybe it's late and I'm not thinking about this 
right :) 

Mark 

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message