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.

Reply via email to