lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Armbrust, Daniel C." <Armbrust.Dan...@mayo.edu>
Subject RE: Document scoring - should I file a bug report?
Date Thu, 05 Jun 2003 21:52:47 GMT
Heres my quasi code (I just copied and pasted out the important pieces).....


		final ArrayList tempHits = new ArrayList(index.maxDoc() / 4);

			searcher.search(query, filter, new HitCollector()
			{
				public void collect(int doc, float score)
				{
					tempHits.add(new LuceneHits(doc, score));
				}
			});

		luceneHits = (LuceneHits[])tempHits.toArray(new LuceneHits[tempHits.size()]);

		Arrays.sort(luceneHits, new HitComparator());

		//normalize the scores
		float scoreNorm = 1.0f;
		if (luceneHits.length > 0 && luceneHits[0].score > 1.0f)
			scoreNorm = 1.0f / luceneHits[0].score;

		for (int i = 0; i < luceneHits.length; i++)
			luceneHits[i].score = luceneHits[i].score * scoreNorm;


public class LuceneHits
{
	public int doc;
	public float score;

	public LuceneHits(int doc, float score)
	{
		this.doc = doc;
		this.score = score;
	}
}

public class HitComparator implements Comparator
{
	public int compare(Object arg0, Object arg1)
	{
		LuceneHits a = (LuceneHits)arg0;
		LuceneHits b = (LuceneHits)arg1;

		if (a.score < b.score)
			return 1;
		else if (a.score == b.score)
			return 0;
		else
			return -1;
	}
}

---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-dev-help@jakarta.apache.org


Mime
View raw message