1 package org.apache.lucene.index;
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 import java.io.IOException;
22 import org.apache.lucene.analysis.MockAnalyzer;
23 import org.apache.lucene.analysis.TokenStream;
24 import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
25 import org.apache.lucene.document.Document;
26 import org.apache.lucene.document.Field;
27 import org.apache.lucene.index.FieldInfo.IndexOptions;
28 import org.apache.lucene.store.MockDirectoryWrapper;
29 import org.apache.lucene.util.LuceneTestCase;
30 import org.apache.lucene.util._TestUtil;
33 * Test indexes ~82M docs with 26 terms each, so you get > Integer.MAX_VALUE terms/docs pairs
34 * @lucene.experimental
36 public class Test2BPostings extends LuceneTestCase {
39 public void test() throws Exception {
41 MockDirectoryWrapper dir = newFSDirectory(_TestUtil.getTempDir("2BPostings"));
42 dir.setThrottling(MockDirectoryWrapper.Throttling.NEVER);
43 dir.setCheckIndexOnClose(false); // don't double-checkindex
45 IndexWriter w = new IndexWriter(dir,
46 new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random))
47 .setMaxBufferedDocs(IndexWriterConfig.DISABLE_AUTO_FLUSH)
48 .setRAMBufferSizeMB(256.0)
49 .setMergeScheduler(new ConcurrentMergeScheduler())
50 .setMergePolicy(newLogMergePolicy(false, 10))
51 .setOpenMode(IndexWriterConfig.OpenMode.CREATE));
53 MergePolicy mp = w.getConfig().getMergePolicy();
54 if (mp instanceof LogByteSizeMergePolicy) {
56 ((LogByteSizeMergePolicy) mp).setMaxMergeMB(1024*1024*1024);
59 Document doc = new Document();
60 Field field = new Field("field", new MyTokenStream());
61 field.setIndexOptions(IndexOptions.DOCS_ONLY);
62 field.setOmitNorms(true);
65 final int numDocs = (Integer.MAX_VALUE / 26) + 1;
66 for (int i = 0; i < numDocs; i++) {
68 if (VERBOSE && i % 100000 == 0) {
69 System.out.println(i + " of " + numDocs + "...");
74 CheckIndex ci = new CheckIndex(dir);
76 ci.setInfoStream(System.out);
82 public static final class MyTokenStream extends TokenStream {
83 private final CharTermAttribute termAtt = addAttribute(CharTermAttribute.class);
84 private final char buffer[];
87 public MyTokenStream() {
89 buffer = termAtt.buffer();
93 public boolean incrementToken() throws IOException {
95 buffer[0] = (char) index++;
102 public void reset() throws IOException {