There is a possibility, but it is not required to be implemented by all codecs:
If you have requested Terms for a specific field from the AtomicReader, you can get the total number of terms in the field, which can unfortunately be -1 (unknown). You can use this number to seek the TermsEnum using seekExact(termCount - 1L). Please note seeking by ord and getting the total term count is definitely not supported by MultiFields implementations used for non-atomic readers. This does not work with NumericField unless the precisionStep is infinite, as those fields contain additional terms with lower precision. Uwe ----- Uwe Schindler H.-H.-Meier-Allee 63, D-28213 Bremen http://www.thetaphi.de eMail: [email protected] > -----Original Message----- > From: Savia Beson [mailto:[email protected]] > Sent: Friday, May 17, 2013 1:23 PM > To: [email protected] > Subject: Re: how to get max value of a long field? > > should't there be a way to do it efficiently for any indexed field (even > max in > byte order)? Term dict is sorted > > > > On May 17, 2013, at 12:08 PM, "Uwe Schindler" <[email protected]> wrote: > > > Hi, > > > > Depending on the distinct number of actual values, it might be better to > iterate over the term dictionary and not index as doc-values. The lowest > value is easy to get, just seek to the first term in the dictionary. The last > term > is unfortunately not so easy to get, you have to iterate the term dictionary > until you reach the last term. > > > > Uwe > > > > ----- > > Uwe Schindler > > H.-H.-Meier-Allee 63, D-28213 Bremen > > http://www.thetaphi.de > > eMail: [email protected] > > > > > >> -----Original Message----- > >> From: Adrien Grand [mailto:[email protected]] > >> Sent: Friday, May 17, 2013 11:36 AM > >> To: [email protected] > >> Subject: Re: how to get max value of a long field? > >> > >> Hi, > >> > >> On Fri, May 17, 2013 at 11:10 AM, Hu Jing <[email protected]> wrote: > >>> I want to know the max value of a long field. > >>> I read lucene api , but don't find any api about this? > >>> does someone can supply any hits about how to implement this. > >> > >> To do this efficiently, your field needs to have doc values[1]. > >> > >> First, iterate over your DirectoryReader leaves[2]. Then for every > >> AtomicReaderContext.reader(), get a NumericDocValues instance for > >> your field[3]. Then iterate over the values to compute the maximum > value: > >> > >> IndexReader rd; > >> long max = Long.MIN_VALUE; > >> for (AtomicReaderContext ctx : rd.leaves()) { > >> final NumericDocValues longs = > >> ctx.reader().getNumericDocValues("my_long_field"); > >> final Bits liveDocs = ctx.reader().getLiveDocs(); > >> for (int i = 0; i < ctx.reader().maxDoc(); ++i) { > >> if (liveDocs != null || liveDocs.get(i)) { > >> max = Math.max(max, longs.get(i)); > >> } > >> } > >> } > >> > >> [1] > >> > http://lucene.apache.org/core/4_3_0/core/org/apache/lucene/document/ > >> NumericDocValuesField.html > >> [2] > >> > http://lucene.apache.org/core/4_3_0/core/org/apache/lucene/index/Inde > >> x > >> Reader.html#leaves() > >> [3] > >> > http://lucene.apache.org/core/4_3_0/core/org/apache/lucene/index/Atom > >> i > >> cReader.html#getNumericDocValues(java.lang.String) > >> > >> -- > >> Adrien > >> > >> --------------------------------------------------------------------- > >> To unsubscribe, e-mail: [email protected] > >> For additional commands, e-mail: [email protected] > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [email protected] > > For additional commands, e-mail: [email protected] > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
