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: Help with a fieldcomparator!
Date Sat, 17 Jan 2015 00:31:57 GMT
Personally I would do this on the ingestion side with a new field.
That is, analyze the input field when you were indexing the doc,
extract the min value from any numbers, and put that in a
new field. Then it's simply sorting by the new field. This is likely
to be much more performant than reprocessing this at query
time in a comparator.

FWIW,
Erick

On Fri, Jan 16, 2015 at 4:00 PM, Victor Podberezski
<vpodberezski@cms-medios.com> wrote:
> I need a hand with a custom comparator.
>
> I have a field filled with words separated by spaces. Some words has
> numbers inside.
>
>  I need to extract those numbers and sort the documents by this number. I
> need to get the lower if there are more than 1 number .
>
> For example:
>
> doc1 "val2 aaaa val3" --> 2, 3 --> 2
> doc2 "val5 aaaa val1" --> 5, 1 --> 1
> doc3 "val7 bbbbb val5" --> 7, 5 ---> 5
>
> the sorted results have to be:
>
> doc2
> doc1
> doc3
>
> how can I achieve this?
>
> I have trouble migrating a functional solution from lucene 2.4 to lucene
> 3.9 or higher (migration from ScoreDocComparator to fieldComparator).
>
> I try this:
>
>     public void setNextReader(IndexReader reader, int docBase) throws
> IOException {
>
>       currentReaderValues = FieldCache.DEFAULT.getInts(reader, field, new
> FieldCache.IntParser() {
>       public final int parseInt(final String val) {
>      return extractNumber(val);
>       }
> });
>
> and the rest equal to the IntComparator.
> but this is not working
>
> Anybody has an idea of how resolve this problem?
> Thanks,
>
> VĂ­ctor Podberezski

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


Mime
View raw message