Apache Lucene: Is Relevance Score Always Between 0 and 1?
Posted
by
Eamorr
on Stack Overflow
See other posts from Stack Overflow
or by Eamorr
Published on 2011-01-09T22:09:21Z
Indexed on
2011/01/09
22:54 UTC
Read the original article
Hit count: 231
Greetings,
I have the following Apache Lucene snippet that's giving me some nice results:
int numHits=100;
int resultsPerPage=100;
IndexSearcher searcher=new IndexSearcher(reader);
TopScoreDocCollector collector=TopScoreDocCollector.create(numHits,true);
Query q=parser.parse(queryString);
searcher.search(q,collector);
ScoreDoc[] hits=collector.topDocs(0*resultsPerPage,resultsPerPage).scoreDocs;
Results r=new Results();
r.length=hits.length;
for(int i=0;i<hits.length;i++){
Document doc=searcher.doc(hits[i].doc);
double distanceKm=getGreatCircleDistance(lucene2double(doc.get("lat")), lucene2double(doc.get("lng")), Double.parseDouble(userLat), Double.parseDouble(userLng));
double newRelevance=((1/distanceKm)*Math.log(hits[i].score)/Math.log(2))*(0-1);
System.out.println(hits[i].doc+"\t"+hits[i].score+"\t"+doc.get("content")+"\t"+"Km="+distanceKm+"\trlvnc="+String.valueOf(newRelevance));
}
What I want to know, is hits[i].score always between 0 and 1? It seems that way, but I can't be sure. I've even checked the Lucene documentation (class ScoreDocs) to no avail. You'll see I'm calculating the log of the "newRelevance" value, which is based on hits[i].score. I need hits[i].score to be between 0 and 1, because if it is below zero, I'll get an error; above 1 and the sign will change from negative to positive.
I hope some Lucene expert out there can offer me some insight.
Many thanks,
© Stack Overflow or respective owner