Hi Shai,

I think you don't have to subclass ScoreDoc. Can't you simply implement
a Comparator and pass it in the data structure you need?

E. g.:
Arrays.sort(scoreDocs, new Comparator() {

public int compare(Object o1, Object o2) {
  ScoreDoc d1 = (ScoreDoc) o1;
  ScoreDoc d2 = (ScoreDoc) o2;

    if (d1.score == d2.score) {
      return d1.doc - d2.doc;
    }
    return d1.score - d2.score < 0 ? -1 : 1;            
  }
});

-Michael

Shai Erera wrote:
> 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
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to