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
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.
: 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
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
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
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
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;
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