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/IndexReader.html#leaves()
[3]
http://lucene.apache.org/core/4_3_0/core/org/apache/lucene/index/AtomicReader.html#getNumericDocValues(java.lang.String)
--
Adrien
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]