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: Field sorting when same doc has multiple values for a field
Date Mon, 22 Dec 2008 23:19:41 GMT
You're off in undefined territory. From the docs for the Sort
class:

<<<...Documents must contain a single term in such a field,
and the value of the term should indicate the document's
relative position in a given sort order. The field must be indexed,
but should not be tokenized, ...>

Whatever is actually going on under the covers, you can't
count on it anyway....

I'd create a "sort_letter" field that *only* got the single
value you want to sort on (as above) and sort on that....

Best
Erick



On Mon, Dec 22, 2008 at 5:13 PM, Andre Rubin <andre.rubin@gmail.com> wrote:

> Hi all,
>
> Has anyone been through this issue?
>
> I have documents that have one or more values for the same field. For
> example:
>
> doc1 = new Document();
> doc1.add(new Field("Letter"), "A", ...);
> doc1.add(new Field("Letter"), "C", ...);
> // doc1.add(other fields);
> //write to index
>
> Now I add another document:
> doc2 = new Document();
> doc2.add(new Field("Letter"), "B", ...);
> //...
> //write to index
>
> Now, when I query, sorting by "Letter" field, doc2 will return before
> doc1. I think it is sorting by the last value added to the field
> (therefore, B precedes C), but I cannot make any assumptions on the
> order that I add the fields to my documents.
>
> Is there a way to handle the sorting within a document as well,
> instead of only among different documents? I wanted doc1 to be sorted
> as if its "Letter" was "A" (lexicographic order).
>
> Thanks,
>
>
> Andre
>
> ---------------------------------------------------------------------
> 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