pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / contrib / instantiated / src / test / org / apache / lucene / store / instantiated / TestMultiSegmentReaderOnConstructor.java
1 package org.apache.lucene.store.instantiated;
2
3 /*
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  *
16  */
17
18 import java.io.IOException;
19
20 import org.apache.lucene.analysis.MockAnalyzer;
21 import org.apache.lucene.document.Document;
22 import org.apache.lucene.document.Field;
23 import org.apache.lucene.index.IndexReader;
24 import org.apache.lucene.index.IndexWriter;
25 import org.apache.lucene.index.IndexWriterConfig.OpenMode;
26 import org.apache.lucene.index.IndexWriterConfig;
27 import org.apache.lucene.store.Directory;
28 import org.apache.lucene.util.LuceneTestCase;
29
30 /**
31  * @since 2009-mar-30 13:15:49
32  */
33 public class TestMultiSegmentReaderOnConstructor extends LuceneTestCase {
34
35   public void test() throws Exception {
36     Directory dir = newDirectory();
37     IndexWriter iw = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)));
38     addDocument(iw, "Hello, world!");
39     addDocument(iw, "All work and no play makes jack a dull boy");
40     iw.close();
41
42     iw = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)).setOpenMode(OpenMode.APPEND));
43     addDocument(iw, "Hello, tellus!");
44     addDocument(iw, "All work and no play makes danny a dull boy");
45     iw.close();
46
47     iw = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)).setOpenMode(OpenMode.APPEND));
48     addDocument(iw, "Hello, earth!");
49     addDocument(iw, "All work and no play makes wendy a dull girl");
50     iw.close();
51
52     IndexReader multiSegReader = IndexReader.open(dir, false);
53     multiSegReader.deleteDocument(2);
54
55     try {
56       new InstantiatedIndex(multiSegReader);
57     } catch (Exception e) {
58       e.printStackTrace(System.out);
59       fail("No exceptions when loading a multi-seg reader!");
60     }
61
62     // todo some assertations.
63     multiSegReader.close();
64     dir.close();
65   }
66
67   private void addDocument(IndexWriter iw, String text) throws IOException {
68     Document doc = new Document();
69     doc.add(new Field("field", text, Field.Store.NO, Field.Index.ANALYZED));
70     iw.addDocument(doc);
71   }
72 }