Re: Comparable ScoreDoc

2007-12-10 Thread Shai Erera
BTW, HitQueue performs this comparison: protected final boolean lessThan(Object a, Object b) { ScoreDoc hitA = (ScoreDoc)a; ScoreDoc hitB = (ScoreDoc)b; if (hitA.score == hitB.score) return hitA.doc > hitB.doc; else return hitA.score < hitB.score; } As you can see, t

Re: Comparable ScoreDoc

2007-12-09 Thread Shai Erera
I looked up the difference between Comparator and Comparable. I found this post http://forum.java.sun.com/thread.jspa?threadID=522388&messageID=2500053from Java's forum. In short, Comparable is used for a natural ordering of the objects. Comparator allows for custom comparisons of the same objects.

Re: Comparable ScoreDoc

2007-12-07 Thread Chris Hostetter
: In general I would agree that people may want different implementations for : compare(), but I hardly see that's the case for ScoreDoc. After all, you can : either compare it by score or by doc (at least now). I believe that since : most people use the TopDocsHitCollector, they prefer the compar

Re: Comparable ScoreDoc

2007-12-07 Thread Shai Erera
In general I would agree that people may want different implementations for compare(), but I hardly see that's the case for ScoreDoc. After all, you can either compare it by score or by doc (at least now). I believe that since most people use the TopDocsHitCollector, they prefer the compare-by-scor

Re: Comparable ScoreDoc

2007-12-06 Thread Michael Busch
Shai Erera wrote: > > Comparators however have an advantage - in that specific case I could create > two Comparators: (1) compares by the score and then by doc (2) compares by That's why I hesitate to add the Comparable interface to ScoreDoc: Different people might want different implementations

Re: Comparable ScoreDoc

2007-12-06 Thread Shai Erera
That is indeed one alternative. I think however that Comparable objects are cleaner. It is evident by just looking at the code how they are compared. Otherwise (with the Comparator approach), you need to pair objects with comparators, and it's not always clear which comparator to use with each obje

Re: Comparable ScoreDoc

2007-12-06 Thread Michael Busch
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;

Comparable ScoreDoc

2007-12-06 Thread Shai Erera
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 S