Return-Path: X-Original-To: apmail-lucene-java-user-archive@www.apache.org Delivered-To: apmail-lucene-java-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C1881F043 for ; Tue, 2 Apr 2013 13:59:17 +0000 (UTC) Received: (qmail 41007 invoked by uid 500); 2 Apr 2013 13:59:15 -0000 Delivered-To: apmail-lucene-java-user-archive@lucene.apache.org Received: (qmail 40849 invoked by uid 500); 2 Apr 2013 13:59:15 -0000 Mailing-List: contact java-user-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: java-user@lucene.apache.org Delivered-To: mailing list java-user@lucene.apache.org Received: (qmail 40760 invoked by uid 99); 2 Apr 2013 13:59:14 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Apr 2013 13:59:14 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of uwe@thetaphi.de designates 188.138.97.18 as permitted sender) Received: from [188.138.97.18] (HELO mail.sd-datasolutions.de) (188.138.97.18) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Apr 2013 13:59:09 +0000 Received: from VEGA (gate1.marum.de [134.102.237.1]) by mail.sd-datasolutions.de (Postfix) with ESMTPSA id 38A2814AA080 for ; Tue, 2 Apr 2013 13:58:48 +0000 (UTC) From: "Uwe Schindler" To: References: In-Reply-To: Subject: RE: Segment readers in Lucene 4.2 Date: Tue, 2 Apr 2013 15:58:47 +0200 Message-ID: <013b01ce2faa$32ae69c0$980b3d40$@thetaphi.de> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQImq9OEv36/XvQxC10Wi+ji35TmeJgR+pEA Content-Language: de X-Virus-Checked: Checked by ClamAV on apache.org Hi, 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 segmentsinfos.info(i) 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 DirectoryReader.open(CommitPoint) and the segmentInfos.read(Dir, = 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 ----- Uwe Schindler H.-H.-Meier-Allee 63, D-28213 Bremen http://www.thetaphi.de eMail: uwe@thetaphi.de > -----Original Message----- > From: andi rexha [mailto:a_rexha@hotmail.com] > Sent: Tuesday, April 02, 2013 3:45 PM > To: java-user@lucene.apache.org > Subject: Segment readers in Lucene 4.2 >=20 > 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 DirectoryReader.open(directory); >=20 > 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()"; >=20 > Am I correct until here? Did I miss something from the whole picture? >=20 > 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 : >=20 > I could associate the reader.toString() method to each of the segment > information. >=20 > SegmentInfos sis =3D new SegmentInfos(); > sis.read(open); > for (int i =3D 0; i < sis.size(); i ++) { > segmentInfo[i] =3D sis.info(i); } >=20 > List leaves =3D 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 } >=20 >=20 > Do you have any clue whether it is possible to have this mapping in a > different way? >=20 > Thanks in advance, > Best regards, > Andi >=20 >=20 >=20 --------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org For additional commands, e-mail: java-user-help@lucene.apache.org