001: package org.apache.lucene.index;
002:
003: /**
004: * Licensed to the Apache Software Foundation (ASF) under one or more
005: * contributor license agreements. See the NOTICE file distributed with
006: * this work for additional information regarding copyright ownership.
007: * The ASF licenses this file to You under the Apache License, Version 2.0
008: * (the "License"); you may not use this file except in compliance with
009: * the License. You may obtain a copy of the License at
010: *
011: * http://www.apache.org/licenses/LICENSE-2.0
012: *
013: * Unless required by applicable law or agreed to in writing, software
014: * distributed under the License is distributed on an "AS IS" BASIS,
015: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: * See the License for the specific language governing permissions and
017: * limitations under the License.
018: */
019:
020: import java.io.IOException;
021:
022: import org.apache.lucene.util.LuceneTestCase;
023:
024: import org.apache.lucene.analysis.SimpleAnalyzer;
025: import org.apache.lucene.document.Document;
026: import org.apache.lucene.document.Field;
027: import org.apache.lucene.document.Field.Index;
028: import org.apache.lucene.document.Field.Store;
029: import org.apache.lucene.store.RAMDirectory;
030:
031: public class TestParallelTermEnum extends LuceneTestCase {
032: private IndexReader ir1;
033: private IndexReader ir2;
034:
035: protected void setUp() throws Exception {
036: super .setUp();
037: super .setUp();
038: Document doc;
039:
040: RAMDirectory rd1 = new RAMDirectory();
041: IndexWriter iw1 = new IndexWriter(rd1, new SimpleAnalyzer(),
042: true);
043:
044: doc = new Document();
045: doc.add(new Field("field1", "the quick brown fox jumps",
046: Store.YES, Index.TOKENIZED));
047: doc.add(new Field("field2", "the quick brown fox jumps",
048: Store.YES, Index.TOKENIZED));
049: doc.add(new Field("field4", "", Store.NO, Index.TOKENIZED));
050: iw1.addDocument(doc);
051:
052: iw1.close();
053: RAMDirectory rd2 = new RAMDirectory();
054: IndexWriter iw2 = new IndexWriter(rd2, new SimpleAnalyzer(),
055: true);
056:
057: doc = new Document();
058: doc.add(new Field("field0", "", Store.NO, Index.TOKENIZED));
059: doc.add(new Field("field1", "the fox jumps over the lazy dog",
060: Store.YES, Index.TOKENIZED));
061: doc.add(new Field("field3", "the fox jumps over the lazy dog",
062: Store.YES, Index.TOKENIZED));
063: iw2.addDocument(doc);
064:
065: iw2.close();
066:
067: this .ir1 = IndexReader.open(rd1);
068: this .ir2 = IndexReader.open(rd2);
069: }
070:
071: protected void tearDown() throws Exception {
072: super .tearDown();
073: super .tearDown();
074:
075: ir1.close();
076: ir2.close();
077: }
078:
079: public void test1() throws IOException {
080: ParallelReader pr = new ParallelReader();
081: pr.add(ir1);
082: pr.add(ir2);
083:
084: TermDocs td = pr.termDocs();
085:
086: TermEnum te = pr.terms();
087: assertTrue(te.next());
088: assertEquals("field1:brown", te.term().toString());
089: td.seek(te.term());
090: assertTrue(td.next());
091: assertEquals(0, td.doc());
092: assertFalse(td.next());
093: assertTrue(te.next());
094: assertEquals("field1:fox", te.term().toString());
095: td.seek(te.term());
096: assertTrue(td.next());
097: assertEquals(0, td.doc());
098: assertFalse(td.next());
099: assertTrue(te.next());
100: assertEquals("field1:jumps", te.term().toString());
101: td.seek(te.term());
102: assertTrue(td.next());
103: assertEquals(0, td.doc());
104: assertFalse(td.next());
105: assertTrue(te.next());
106: assertEquals("field1:quick", te.term().toString());
107: td.seek(te.term());
108: assertTrue(td.next());
109: assertEquals(0, td.doc());
110: assertFalse(td.next());
111: assertTrue(te.next());
112: assertEquals("field1:the", te.term().toString());
113: td.seek(te.term());
114: assertTrue(td.next());
115: assertEquals(0, td.doc());
116: assertFalse(td.next());
117: assertTrue(te.next());
118: assertEquals("field2:brown", te.term().toString());
119: td.seek(te.term());
120: assertTrue(td.next());
121: assertEquals(0, td.doc());
122: assertFalse(td.next());
123: assertTrue(te.next());
124: assertEquals("field2:fox", te.term().toString());
125: td.seek(te.term());
126: assertTrue(td.next());
127: assertEquals(0, td.doc());
128: assertFalse(td.next());
129: assertTrue(te.next());
130: assertEquals("field2:jumps", te.term().toString());
131: td.seek(te.term());
132: assertTrue(td.next());
133: assertEquals(0, td.doc());
134: assertFalse(td.next());
135: assertTrue(te.next());
136: assertEquals("field2:quick", te.term().toString());
137: td.seek(te.term());
138: assertTrue(td.next());
139: assertEquals(0, td.doc());
140: assertFalse(td.next());
141: assertTrue(te.next());
142: assertEquals("field2:the", te.term().toString());
143: td.seek(te.term());
144: assertTrue(td.next());
145: assertEquals(0, td.doc());
146: assertFalse(td.next());
147: assertTrue(te.next());
148: assertEquals("field3:dog", te.term().toString());
149: td.seek(te.term());
150: assertTrue(td.next());
151: assertEquals(0, td.doc());
152: assertFalse(td.next());
153: assertTrue(te.next());
154: assertEquals("field3:fox", te.term().toString());
155: td.seek(te.term());
156: assertTrue(td.next());
157: assertEquals(0, td.doc());
158: assertFalse(td.next());
159: assertTrue(te.next());
160: assertEquals("field3:jumps", te.term().toString());
161: td.seek(te.term());
162: assertTrue(td.next());
163: assertEquals(0, td.doc());
164: assertFalse(td.next());
165: assertTrue(te.next());
166: assertEquals("field3:lazy", te.term().toString());
167: td.seek(te.term());
168: assertTrue(td.next());
169: assertEquals(0, td.doc());
170: assertFalse(td.next());
171: assertTrue(te.next());
172: assertEquals("field3:over", te.term().toString());
173: td.seek(te.term());
174: assertTrue(td.next());
175: assertEquals(0, td.doc());
176: assertFalse(td.next());
177: assertTrue(te.next());
178: assertEquals("field3:the", te.term().toString());
179: td.seek(te.term());
180: assertTrue(td.next());
181: assertEquals(0, td.doc());
182: assertFalse(td.next());
183: assertFalse(te.next());
184: }
185: }
|