Hi

Today ScoreDoc is not Comparable. That prevents applications that would like
to use it in Comparable data structures (such as priority queues), but still
use other Lucene's objects, like TopDocs, unless they create a
ComparableScoreDoc which extends ScoreDoc and implements Comparable. To make
ScoreDoc Comparable requires very minor changes:
- Add implements Comparable
- Add:
    public int compareTo(Object o) {
        ScoreDoc oScoreDoc = (ScoreDoc) o;
        float oScore = oScoreDoc.score;
        if (score == oScore) {
            return doc - oScoreDoc.doc;
        }
        return score - oScore < 0 ? -1 : 1;
    }

If you agree to do it, I'm willing to open an issue and provide a patch. It
shouldn't affect any current Lucene implementations.

Thanks,

Shai Erera

Reply via email to