package org.apache.lucene.store.instantiated;

import junit.framework.TestCase;

import java.io.IOException;

import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.store.Directory;
import org.apache.lucene.analysis.WhitespaceAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;

/**
 * @author kalle
 * @since 2009-mar-30 13:15:49
 */
public class TestUnoptimizedReaderOnConstructor extends TestCase {

  public void test() throws Exception {
    Directory dir = new RAMDirectory();
    IndexWriter iw = new IndexWriter(dir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.UNLIMITED);
    addDocument(iw, "Hello, world!");
    addDocument(iw, "All work and no play makes jack a dull boy");
    iw.commit("a");
    iw.close();

    iw = new IndexWriter(dir, new WhitespaceAnalyzer(), false, IndexWriter.MaxFieldLength.UNLIMITED);
    addDocument(iw, "Hello, tellus!");
    addDocument(iw, "All work and no play makes danny a dull boy");
    iw.commit("b");
    iw.close();

    iw = new IndexWriter(dir, new WhitespaceAnalyzer(), false, IndexWriter.MaxFieldLength.UNLIMITED);
    addDocument(iw, "Hello, earth!");
    addDocument(iw, "All work and no play makes wendy a dull girl");
    iw.commit("c");
    iw.close();

    IndexReader unoptimizedReader = IndexReader.open(dir);
    unoptimizedReader.deleteDocument(2);

    InstantiatedIndex ii = new InstantiatedIndex(unoptimizedReader);

  }

  private void addDocument(IndexWriter iw, String text) throws IOException {
    Document doc = new Document();
    doc.add(new Field("field", text, Field.Store.NO, Field.Index.ANALYZED));
    iw.addDocument(doc);
  }
}

@@ -40,16 +40,591 @@
 iated;%0A%0A
+/*%0A *  Licensed under the Apache License, Version 2.0 (the %22License%22);%0A *  you may not use this file except in compliance with the License.%0A *  You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A *  Unless required by applicable law or agreed to in writing, software%0A *  distributed under the License is distributed on an %22AS IS%22 BASIS,%0A *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A *  See the License for the specific language governing permissions and%0A *  limitations under the License.%0A *%0A */%0A%0A
 import j
@@ -676,16 +676,38 @@
 ception;
+%0Aimport java.util.Map;
 %0A%0Aimport
@@ -1023,25 +1023,8 @@
 /**%0A
- * @author kalle%0A
  * @
@@ -1424,28 +1424,8 @@
 %22);%0A
-    iw.commit(%22a%22);%0A
     
@@ -1650,28 +1650,8 @@
 %22);%0A
-    iw.commit(%22b%22);%0A
     
@@ -1876,28 +1876,8 @@
 %22);%0A
-    iw.commit(%22c%22);%0A
     
@@ -2012,16 +2012,35 @@
 edIndex 
+ii;%0A    try %7B%0A     
 ii = new
@@ -2077,16 +2077,147 @@
 Reader);
+%0A    %7D catch (Exception e) %7B%0A      fail(%22No exceptions when loading an unoptimized reader!%22);%0A    %7D%0A%0A    // todo some assertations.
 %0A%0A  %7D%0A%0A 

Support for loading unoptimized readers to the constructor of InstantiatedIndex. (Karl Wettin)