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" <u...@thetaphi.de> 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: u...@thetaphi.de
> 
> 
>> -----Original Message-----
>> From: Adrien Grand [mailto:jpou...@gmail.com]
>> Sent: Friday, May 17, 2013 11:36 AM
>> To: java-user@lucene.apache.org
>> Subject: Re: how to get max value of a long field?
>> 
>> Hi,
>> 
>> On Fri, May 17, 2013 at 11:10 AM, Hu Jing <huj....@gmail.com> 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/Index
>> Reader.html#leaves()
>> [3]
>> http://lucene.apache.org/core/4_3_0/core/org/apache/lucene/index/Atomi
>> cReader.html#getNumericDocValues(java.lang.String)
>> 
>> --
>> Adrien
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org
>> For additional commands, e-mail: java-user-h...@lucene.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org
> For additional commands, e-mail: java-user-h...@lucene.apache.org
> 


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

Reply via email to