lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Erick Erickson" <erickerick...@gmail.com>
Subject Re: Sorting by Score
Date Tue, 27 Feb 2007 23:48:29 GMT
This may be off base, but I've recently been in something similar.

The first part was just to iterate through the TopDocs that's available to
my and normalize the scores right in the ScoreDocs. Like this...

        for (ScoreDoc scd : this.topDocs.scoreDocs) {
            scd.score = this.getBucket(scd.score, maxScore);
        }

where getBucket is my score normalizer, and in your case it would round your
scores.


Then I constructed a Sort object with SortField.FIELD_SCORE as the first
sotrField, like this...

        Sort stuff = new Sort(
                    new SortField[] {
                        SortField.FIELD_SCORE,
                        new SortField("somefield"),
                        new SortField("someotherfield")
                    });

and passed that object to the FieldSortedHitQueue.

Erick

On 2/27/07, Peter Keegan <peterlkeegan@gmail.com> wrote:
>
> I'm building up the Sort object for the search with 2 SortFields - first
> is
> for the custom rounded scoring, second is for date. This Sort object is
> used
> to construct a FieldSortedHitQueue which is used with a custom
> HitCollector.
> And yes, this comparator ignores the field name.
>
> > hmmm, actually i see now that SortField(String,SortComparatorSource)
> says
> it cannot > be null ... not sure if that's actually enforced or not
>
> The constructor doesn't complain, but FieldSortedHitQueue expects a field
> name when it tries to locate the comparator from the cache:
>
>     at org.apache.lucene.search.FieldCacheImpl$Entry.<init>(
> FieldCacheImpl.java:60)
>     at org.apache.lucene.search.FieldSortedHitQueue.lookup(
> FieldSortedHitQueue.java:157)
>     at org.apache.lucene.search.FieldSortedHitQueue.getCachedComparator(
> FieldSortedHitQueue.java:185)
>     at org.apache.lucene.search.FieldSortedHitQueue.<init>(
> FieldSortedHitQueue.java:58)
>
> Peter
>
> On 2/27/07, Chris Hostetter <hossman_lucene@fucit.org> wrote:
> >
> >
> > : Suppose one wanted to use this custom rounding score comparator on all
> > : fields and all queries. How would you get it plugged in most
> > efficiently,
> > : given that SortField requires a non-null field name?
> >
> > i'm not sure i understand the first part of question .. this custom
> > SortComparatorSource would deal only with the score, it wouldn't matter
> > what other fields you'd want to make SortFields on to do secondary
> > sorting. .. You as the client have to specify the Sort obejct when
> > executing the search, and you can build that Sort object up anyway you
> > want.
> >
> > Yes the SortField class has a constructor arg for field, but
> > as you can see from the javadocs, it can be null in many circumstances
> > (consider SortFiled#FIELD_SCORE and SortField#FIELD_DOC for instance)
> ...
> > hmmm, actually i see now that SortField(String,SortComparatorSource)
> says
> > it cannot be null ... not sure if that's actually enforced or not, but
> > it's no bother -- all that matters is that you don't make any attempt to
> > use the field name in your SortComparatorSource.
> >
> >
> > -Hoss
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> > For additional commands, e-mail: java-user-help@lucene.apache.org
> >
> >
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message