Thanks Uwe, 

just thinking aloud about it. 
Maybe such feature would make sense, to keep transient min/max values for 
indexed fields during indexing and to write them to userComitData or some such 
on commit… 
One would just need to intercept add()  and add min/max maintenance.  Does not 
sound like performance would suffer? This way, the same could be done for 
stored fields as well.

I am not sure what other use cases would be, but keeping timestemp-like 
sequence ID (monotone increasing) is really useful for incremental updates. We 
do it at application level and write to userCommitDate

Would be nice to have it in Lucene,  but not sure if this is the right place, 
maybe better at application level like solr?   Not really sure, Lucene is 
(almost) Field Type agnostic and does not know  what min and max mean really?


regards...


  
On May 17, 2013, at 4:53 PM, Uwe Schindler <u...@thetaphi.de> wrote:

> 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: u...@thetaphi.de
> 
> 
>> -----Original Message-----
>> From: Savia Beson [mailto:eks...@googlemail.com]
>> Sent: Friday, May 17, 2013 1:23 PM
>> To: java-user@lucene.apache.org
>> 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" <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/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: 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
> 
> 
> ---------------------------------------------------------------------
> 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