lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Uwe Schindler" <>
Subject RE: Segment readers in Lucene 4.2
Date Tue, 02 Apr 2013 13:58:47 GMT

this is all not public tot he code because it is also subject to change!

With Lucene 4.x, you can assume:
directoryReader.leaves().get(i) corresponds to

WARNING: But this is only true if:
- the reader is instanceof DirectoryReader
- the segmentinfos were opened on the exact same commit point like the directory reader. If
you have IndexWriter concurrently committing in between, this is no longer correct. To make
this 100% correct, do DirectoryReader.listCommits(), chose one single "defined" commit and
use it for and the, commitPoint.getSegmentFileName()).
Ideally open the DirectoryReader first, so it holds a lock, so the segments file may not be
deleted before/while reading the segmentInfos.


Uwe Schindler
H.-H.-Meier-Allee 63, D-28213 Bremen

> -----Original Message-----
> From: andi rexha []
> Sent: Tuesday, April 02, 2013 3:45 PM
> To:
> Subject: Segment readers in Lucene 4.2
> Hi,
> I have a question about the Index Readers in Lucene.
> As far as I understand from the documentation, with the Lucene 4, we can
> create an Index Reader from;
> From the code of the DirectoryReader, I have seen that it uses the
> SegmentReader to create the reader. To get all the SegmentReaders we
> have to loop through the AtomicReaderContexts that we can get from the
> "dirReader.leaves()";
> Am I correct until here? Did I miss something from the whole picture?
> My question is: I want to associate each segment to its
> AtomicReaderContext. I have an application that caches information from
> each segment, and I want to keep the reference to the current opened
> segments. I have found a way to do that but that is not elegant :
> I could associate the reader.toString() method to each of the segment
> information.
>  SegmentInfos sis = new SegmentInfos();
>  for (int i = 0; i < sis.size(); i ++) {
>             segmentInfo[i] =;  }
> List<AtomicReaderContext> leaves = dirReader.leaves();
>         System.out.println(leaves.size());
>         for (AtomicReaderContext context : leaves) {
>             checkIfExist(segmentInfo(i), context.reader().toString()); //here the
> solution is that I use the toString() method to extract the information of the
> segment. I cannot extract the information of the segment because it is
> protected }
> Do you have any clue whether it is possible to have this mapping in a
> different way?
> Thanks in advance,
> Best regards,
> Andi

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message