You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Ulf Dittmer <ul...@ulfdittmer.com> on 2007/03/01 15:43:45 UTC

question about ScoreDocComparator

Hello-

One of the fields in my index is an ID, which maps to a full text  
description behind the scenes. Now I want to sort the search results  
alphabetically according to the description, not the ID. This can be  
done via SortComparatorSource and a ScoreDocComparator without  
problems. But the code needed to do this is quite complicated - it  
involves retrieving the document ID from the ScoreDoc, then looking  
up the Document through an IndexReader, and then retrieving the ID  
field from the document. It seems that there should be an easier way  
to get at the ID field, since that is the one being used for the  
sort. There is a related class FieldDoc, through which it seems  
possible to get at the field values, but that doesn't seem applicable  
here.

I went through the custom sorting example of "Lucene In Action", but  
that doesn't deal with this case. Am I missing something obvious?

Thanks in advance,
Ulf


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: question about ScoreDocComparator

Posted by Ulf Dittmer <ul...@ulfdittmer.com>.
Well, I am using a Sort object ("Hits = Search.search(Query, Filter,  
Sort)" actually).
In setting up the SortField array for that Sort object with a  
SortComparatorSource the issue comes up that I need to access the  
field value that is being used for sorting.

Maybe that's just the way Lucene works, but it seems that there  
should be an easy way to get at the field value without having to  
retrieve the document from the index.

Cheers,
Ulf


On 05.03.2007, at 00:05, Erick Erickson wrote:

> Maybe I'm missing something in turn, but why not just use a Sort  
> object at
> search time?  You can have a Hits object or TopFIeldDocs object  
> returned
> (the Filter in some of these calls can be null).
>
> Best
> Erick
>
>
> On 3/1/07, Ulf Dittmer <ul...@ulfdittmer.com> wrote:
>>
>> Hello-
>>
>> One of the fields in my index is an ID, which maps to a full text
>> description behind the scenes. Now I want to sort the search results
>> alphabetically according to the description, not the ID. This can be
>> done via SortComparatorSource and a ScoreDocComparator without
>> problems. But the code needed to do this is quite complicated - it
>> involves retrieving the document ID from the ScoreDoc, then looking
>> up the Document through an IndexReader, and then retrieving the ID
>> field from the document. It seems that there should be an easier way
>> to get at the ID field, since that is the one being used for the
>> sort. There is a related class FieldDoc, through which it seems
>> possible to get at the field values, but that doesn't seem  
>> applicable here.
>>
>> I went through the custom sorting example of "Lucene In Action", but
>> that doesn't deal with this case. Am I missing something obvious?
>>
>> Thanks in advance,
>> Ulf


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: question about ScoreDocComparator

Posted by Erick Erickson <er...@gmail.com>.
Maybe I'm missing something in turn, but why not just use a Sort object at
search time?  You can have a Hits object or TopFIeldDocs object returned
(the Filter in some of these calls can be null).

Best
Erick


On 3/1/07, Ulf Dittmer <ul...@ulfdittmer.com> wrote:
>
> Hello-
>
> One of the fields in my index is an ID, which maps to a full text
> description behind the scenes. Now I want to sort the search results
> alphabetically according to the description, not the ID. This can be
> done via SortComparatorSource and a ScoreDocComparator without
> problems. But the code needed to do this is quite complicated - it
> involves retrieving the document ID from the ScoreDoc, then looking
> up the Document through an IndexReader, and then retrieving the ID
> field from the document. It seems that there should be an easier way
> to get at the ID field, since that is the one being used for the
> sort. There is a related class FieldDoc, through which it seems
> possible to get at the field values, but that doesn't seem applicable
> here.
>
> I went through the custom sorting example of "Lucene In Action", but
> that doesn't deal with this case. Am I missing something obvious?
>
> Thanks in advance,
> Ulf
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>