Index: lucene/CHANGES.txt =================================================================== --- lucene/CHANGES.txt (revision 1064132) +++ lucene/CHANGES.txt (working copy) @@ -371,6 +371,9 @@ * LUCENE-1846: DateTools now uses the US locale everywhere, so DateTools.round() is safe also in strange locales. (Uwe Schindler) +* LUCENE-2891: IndexWriterConfig did not accept -1 in setReaderTermIndexDivisor, + which can be used to prevent loading the terms index into memory. (Shai Erera) + New features * LUCENE-2128: Parallelized fetching document frequencies during weight Index: lucene/src/test/org/apache/lucene/index/TestIndexWriterConfig.java =================================================================== --- lucene/src/test/org/apache/lucene/index/TestIndexWriterConfig.java (revision 1064132) +++ lucene/src/test/org/apache/lucene/index/TestIndexWriterConfig.java (working copy) @@ -230,6 +230,23 @@ // this is expected } + // Test setReaderTermsIndexDivisor + try { + conf.setReaderTermsIndexDivisor(0); + fail("should not have succeeded to set termsIndexDivisor to 0"); + } catch (IllegalArgumentException e) { + // this is expected + } + + // Setting to -1 is ok + conf.setReaderTermsIndexDivisor(-1); + try { + conf.setReaderTermsIndexDivisor(-2); + fail("should not have succeeded to set termsIndexDivisor to < -1"); + } catch (IllegalArgumentException e) { + // this is expected + } + assertEquals(IndexWriterConfig.DEFAULT_MAX_THREAD_STATES, conf.getMaxThreadStates()); conf.setMaxThreadStates(5); assertEquals(5, conf.getMaxThreadStates()); Index: lucene/src/test/org/apache/lucene/index/TestIndexWriterReader.java =================================================================== --- lucene/src/test/org/apache/lucene/index/TestIndexWriterReader.java (revision 1064132) +++ lucene/src/test/org/apache/lucene/index/TestIndexWriterReader.java (working copy) @@ -970,4 +970,26 @@ dir.close(); assertTrue(didWarm.get()); } + + public void testNoTermsIndex() throws Exception { + Directory dir = newDirectory(); + IndexWriter w = new IndexWriter(dir, newIndexWriterConfig( + TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)) + .setReaderTermsIndexDivisor(-1)); + Document doc = new Document(); + doc.add(new Field("f", "val", Store.NO, Index.ANALYZED)); + w.addDocument(doc); + IndexReader r = IndexReader.open(w); + try { + r.termDocs(new Term("f", "val")); + fail("should have failed to seek by term, since term index was not loaded"); + } catch (IllegalStateException e) { + // expected - we didn't load the term index + } finally { + r.close(); + w.close(); + dir.close(); + } + } + } Index: lucene/src/java/org/apache/lucene/index/IndexReader.java =================================================================== --- lucene/src/java/org/apache/lucene/index/IndexReader.java (revision 1064132) +++ lucene/src/java/org/apache/lucene/index/IndexReader.java (working copy) @@ -405,7 +405,10 @@ * memory. By setting this to a value > 1 you can reduce * memory usage, at the expense of higher latency when * loading a TermInfo. The default value is 1. Set this - * to -1 to skip loading the terms index entirely. + * to -1 to skip loading the terms index entirely. This is only useful in + * advanced situations when you will only .next() through all terms; + * attempts to seek will hit an exception. + * * @throws CorruptIndexException if the index is corrupt * @throws IOException if there is a low-level IO error */ Index: lucene/src/java/org/apache/lucene/index/IndexWriterConfig.java =================================================================== --- lucene/src/java/org/apache/lucene/index/IndexWriterConfig.java (revision 1064132) +++ lucene/src/java/org/apache/lucene/index/IndexWriterConfig.java (working copy) @@ -539,10 +539,13 @@ /** Sets the term index divisor passed to any readers that * IndexWriter opens, for example when apply deletes or * creating a near-real-time reader in {@link - * IndexWriter#getReader}. */ + * IndexWriter#getReader}. If you pass -1, the terms index + * won't be loaded by the readers. This is only useful in + * advanced situations when you will only .next() through + * all terms; attempts to seek will hit an exception . */ public IndexWriterConfig setReaderTermsIndexDivisor(int divisor) { - if (divisor <= 0) { - throw new IllegalArgumentException("divisor must be >= 1 (got " + divisor + ")"); + if (divisor <= 0 && divisor != -1) { + throw new IllegalArgumentException("divisor must be >= 1, or -1 (got " + divisor + ")"); } readerTermsIndexDivisor = divisor; return this;