Return-Path: Delivered-To: apmail-jakarta-lucene-user-archive@apache.org Received: (qmail 98607 invoked from network); 3 Apr 2003 04:14:32 -0000 Received: from exchange.sun.com (192.18.33.10) by daedalus.apache.org with SMTP; 3 Apr 2003 04:14:32 -0000 Received: (qmail 9670 invoked by uid 97); 3 Apr 2003 04:16:30 -0000 Delivered-To: qmlist-jakarta-archive-lucene-user@nagoya.betaversion.org Received: (qmail 9663 invoked from network); 3 Apr 2003 04:16:29 -0000 Received: from daedalus.apache.org (HELO apache.org) (208.185.179.12) by nagoya.betaversion.org with SMTP; 3 Apr 2003 04:16:29 -0000 Received: (qmail 98338 invoked by uid 500); 3 Apr 2003 04:14:29 -0000 Mailing-List: contact lucene-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Lucene Users List" Reply-To: "Lucene Users List" Delivered-To: mailing list lucene-user@jakarta.apache.org Received: (qmail 98326 invoked from network); 3 Apr 2003 04:14:28 -0000 Received: from web12707.mail.yahoo.com (216.136.173.244) by daedalus.apache.org with SMTP; 3 Apr 2003 04:14:28 -0000 Message-ID: <20030403041438.4753.qmail@web12707.mail.yahoo.com> Received: from [24.90.65.225] by web12707.mail.yahoo.com via HTTP; Wed, 02 Apr 2003 20:14:38 PST Date: Wed, 2 Apr 2003 20:14:38 -0800 (PST) From: Otis Gospodnetic Subject: Re: about increment update To: Lucene Users List In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N Maybe this is missing? http://jakarta.apache.org/lucene/docs/api/org/apache/lucene/index/IndexReader.html#close() Otis --- kerr wrote: > Hello everyone, > Here I try to increment update index file and follow the idea to > delete modified file first and re-add it. Here is the source. > But when I execute it, the index directory create a file(write.lock) > when execute the line > reader.delete(i);, > and caught a class java.io.IOException with message: Index locked > for write. > After that, when I execute the line > IndexWriter writer = new IndexWriter("index", new > StandardAnalyzer(), false); > caught a class java.io.IOException with message: Index locked for > write > if I delete the file(write.lock), the error will re-happen. > anyone can help and thanks. > Kerr. > > > import org.apache.lucene.analysis.standard.StandardAnalyzer; > import org.apache.lucene.index.IndexWriter; > import org.apache.lucene.document.Document; > import org.apache.lucene.document.Field; > import org.apache.lucene.store.Directory; > import org.apache.lucene.store.FSDirectory; > import org.apache.lucene.index.IndexReader; > import org.apache.lucene.index.Term; > > import java.io.File; > import java.util.Date; > > > public class UpdateIndexFiles { > public static void main(String[] args) { > try { > Date start = new Date(); > > Directory directory = FSDirectory.getDirectory("index", false); > IndexReader reader = IndexReader.open(directory); > System.out.println(reader.isLocked(directory)); > //reader.unlock(directory); > IndexWriter writer = new IndexWriter("index", new > StandardAnalyzer(), false); > > String base = ""; > if (args.length == 0){ > base = "D:\\Tomcat\\webapps\\ROOT\\test"; > } else { > base = args[0]; > } > removeModifiedFiles(reader); > updateIndexDocs(reader, writer, new File(base)); > > writer.optimize(); > writer.close(); > > Date end = new Date(); > > System.out.print(end.getTime() - start.getTime()); > System.out.println(" total milliseconds"); > > } catch (Exception e) { > System.out.println(" caught a " + e.getClass() + > "\n with message: " + e.getMessage()); > e.printStackTrace(); > } > } > > public static void removeModifiedFiles(IndexReader reader) throws > Exception { > Document adoc; > String path; > File aFile; > for (int i=0; i adoc = reader.document(i); > path = adoc.get("path"); > aFile = new File(path); > if (reader.lastModified(path) < aFile.lastModified()){ > System.out.println(reader.isLocked(path)); > reader.delete(i); > } > } > } > > public static void updateIndexDocs(IndexReader reader, IndexWriter > writer, File file) > throws Exception { > > if (file.isDirectory()) { > String[] files = file.list(); > for (int i = 0; i < files.length; i++) > updateIndexDocs(reader, writer, new File(file, files[i])); > } else { > if (!reader.indexExists(file)){ > System.out.println("adding " + file); > writer.addDocument(FileDocument.Document(file)); > } else {} > } > } > } __________________________________________________ Do you Yahoo!? Yahoo! Tax Center - File online, calculators, forms, and more http://tax.yahoo.com --------------------------------------------------------------------- To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: lucene-user-help@jakarta.apache.org