Hi, this isn't a bug, its a documented change in behavior in the 3.1 CHANGES.txt notes:
* LUCENE-2386: IndexWriter no longer performs an empty commit upon new index creation. Previously, if you passed an empty Directory and set OpenMode to CREATE*, IndexWriter would make a first empty commit. If you need that behavior you can call writer.commit()/close() immediately after you create it. http://svn.apache.org/repos/asf/lucene/dev/tags/lucene_solr_3_1/lucene/CHANGES.txt On Thu, Jul 7, 2011 at 11:04 PM, Rob Bygrave <robin.bygr...@gmail.com> wrote: > This looks like a Bug in v3.3.0. > > The code below works in 3.0.1 without calling the writer.commit() before > IndexReader.open(directory). > > In v3.3.0 when the index does not yet exist I need to add the > writer.commit() and I believe that creates the segments. If I don't add the > writer.commit() then I get the IndexNotFoundException: no segments* file > found exception below. > > > IndexWriterConfig config = new > IndexWriterConfig(Version.LUCENE_33, analyzer); > config.setOpenMode(OpenMode.CREATE_OR_APPEND); > config.setIndexDeletionPolicy(commitDeletionPolicy); > IndexWriter writer = new IndexWriter(directory, config); > > // ----------------- > // Need to add this w.commit() when the index is does not exist > writer.commit(); > // ----------------- > > // without the commit above this fails with > a IndexNotFoundException when the index does not exist > IndexReader reader = IndexReader.open(directory); > > > > The exception when writer.commit() is not there and the index does not exist > is: > > Caused by: org.apache.lucene.index.IndexNotFoundException: no segments* file > found in > org.apache.lucene.store.SimpleFSDirectory@C:\dev\workspace-sts\uoa-tmp-copydb\lucene\dst\model.indexdefn.OrgUnitIndexDefn > lockFactory=org.apache.lucene.store.NativeFSLockFactory@3bc257: files: > [write.lock] > at > org.apache.lucene.index.SegmentInfos$FindSegmentsFile.run(SegmentInfos.java:708) > at org.apache.lucene.index.DirectoryReader.open(DirectoryReader.java:75) > at org.apache.lucene.index.IndexReader.open(IndexReader.java:428) > at org.apache.lucene.index.IndexReader.open(IndexReader.java:274) > > > The workaround is to add the writer.commit() and that seems pretty > reasonable to me. > > Thanks, Rob. > --------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org For additional commands, e-mail: java-user-h...@lucene.apache.org