Mailing List Archive

Lucene 5 Custom FieldComparator
Hi,

I'm doing a migration from Lucene 3.6.1 to 5.2.1 and I have a custom
FieldComparator that sort the search for availables discounts. For this,
first I check that the date range is valid and later sort by the discount
amount.

I did this in Lucene 3.6.1 but now in 5.2.1 version, the FieldComparator
has the method doSetNextReader that has a LeafReaderContext and I do not
know how to read all the fields from the LeafReader because I did not
indexed this field with DocValues.

I tried with MultiFields but I got only one result instead of an array, and
some values are Floats.

Someone know how to do this?

Thanks a lot for the help.

Regards,
Pablo.
Lucene 5 Custom FieldComparator [ In reply to ]
Hi,

I'm doing a migration from Lucene 3.6.1 to 5.2.1 and I have a custom
FieldComparator that sort the search for availables discounts. For this,
first I check that the date range is valid and later sort by the discount
amount.

I did this in Lucene 3.6.1 but now in 5.2.1 version, the FieldComparator
has the method doSetNextReader that has a LeafReaderContext and I do not
know how to read all the fields from the LeafReader because I did not
indexed this field with DocValues.

I tried with MultiFields but I got only one result instead of an array, and
some values are Floats.

Someone know how to do this?

Thanks a lot for the help.

Regards,
Pablo.
Lucene 5 Custom FieldComparator [ In reply to ]
Hi,

I'm doing a migration from Lucene 3.6.1 to 5.2.1 and I have a custom
FieldComparator that sort the search for availables discounts. For this,
first I check that the date range is valid and later sort by the discount
amount.

I did this in Lucene 3.6.1 but now in 5.2.1 version, the FieldComparator
has the method doSetNextReader that has a LeafReaderContext and I do not
know how to read all the fields from the LeafReader because I did not
indexed this field with DocValues.

I tried with MultiFields but I got only one result instead of an array, and
some values are Floats.

Someone know how to do this?

Thanks a lot for the help.

Regards,
Pablo.
RE: Lucene 5 Custom FieldComparator [ In reply to ]
You have to index as Docvalues since 5.0 to do that type of query. FieldCache is gone, see MIGRATE.txt.
MultiFields does not help here, it is more to view the whole index as a single LeafReader although it contains of multiple segments (LeafReaders). Its also used for merging, but user code should not use it.

The doSetNextReader is provided in the API because the collecting of results is done per index segment (means per LeafReader) and the document ids reported to collect() are relative to those readers, not valid globally. In setNextReader you have to fetch the docvalues from the index using LeafReader and access them later in the compare methods using the local docids.

Uwe

P.S.: FieldCache is still available as a reader wrapper in misc modules 'uninverting' package, but the API no longer returns arrays. You just get back a DocValues emulation, which is random access. You still have to do this per index segment (setNextReader).

-----
Uwe Schindler
H.-H.-Meier-Allee 63, D-28213 Bremen
http://www.thetaphi.de
eMail: uwe@thetaphi.de


> -----Original Message-----
> From: Pablo Mincz [mailto:pmincz@gmail.com]
> Sent: Thursday, August 13, 2015 5:35 PM
> To: general@lucene.apache.org
> Subject: Lucene 5 Custom FieldComparator
>
> Hi,
>
> I'm doing a migration from Lucene 3.6.1 to 5.2.1 and I have a custom
> FieldComparator that sort the search for availables discounts. For this, first I
> check that the date range is valid and later sort by the discount amount.
>
> I did this in Lucene 3.6.1 but now in 5.2.1 version, the FieldComparator has
> the method doSetNextReader that has a LeafReaderContext and I do not
> know how to read all the fields from the LeafReader because I did not
> indexed this field with DocValues.
>
> I tried with MultiFields but I got only one result instead of an array, and some
> values are Floats.
>
> Someone know how to do this?
>
> Thanks a lot for the help.
>
> Regards,
> Pablo.