You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sh...@apache.org on 2011/01/27 21:07:44 UTC
svn commit: r1064285 - in /lucene/dev/trunk/lucene: ./
src/java/org/apache/lucene/index/ src/test/org/apache/lucene/index/
Author: shaie
Date: Thu Jan 27 20:07:43 2011
New Revision: 1064285
URL: http://svn.apache.org/viewvc?rev=1064285&view=rev
Log:
LUCENE-2891: merge to trunk
Modified:
lucene/dev/trunk/lucene/CHANGES.txt
lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexReader.java
lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexWriterConfig.java
lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriterConfig.java
lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriterReader.java
Modified: lucene/dev/trunk/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/CHANGES.txt?rev=1064285&r1=1064284&r2=1064285&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/CHANGES.txt (original)
+++ lucene/dev/trunk/lucene/CHANGES.txt Thu Jan 27 20:07:43 2011
@@ -701,6 +701,9 @@ Bug fixes
* 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
Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexReader.java?rev=1064285&r1=1064284&r2=1064285&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexReader.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexReader.java Thu Jan 27 20:07:43 2011
@@ -415,7 +415,10 @@ public abstract class IndexReader implem
* 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
*/
Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexWriterConfig.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexWriterConfig.java?rev=1064285&r1=1064284&r2=1064285&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexWriterConfig.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexWriterConfig.java Thu Jan 27 20:07:43 2011
@@ -552,10 +552,13 @@ public final class IndexWriterConfig imp
/** Sets the termsIndexDivisor passed to any readers that
* IndexWriter opens, for example when applying 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;
Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriterConfig.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriterConfig.java?rev=1064285&r1=1064284&r2=1064285&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriterConfig.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriterConfig.java Thu Jan 27 20:07:43 2011
@@ -222,6 +222,23 @@ public class TestIndexWriterConfig exten
// 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());
Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriterReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriterReader.java?rev=1064285&r1=1064284&r2=1064285&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriterReader.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriterReader.java Thu Jan 27 20:07:43 2011
@@ -20,6 +20,7 @@ import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -30,6 +31,7 @@ import org.apache.lucene.document.Field;
import org.apache.lucene.document.Field.Index;
import org.apache.lucene.document.Field.Store;
import org.apache.lucene.document.Field.TermVector;
+import org.apache.lucene.index.codecs.CodecProvider;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
@@ -990,4 +992,37 @@ public class TestIndexWriterReader exten
dir.close();
assertTrue(didWarm.get());
}
+
+ public void testNoTermsIndex() throws Exception {
+ // Some Codecs don't honor the ReaderTermsIndexDiviso, so skip the test if
+ // they're picked.
+ HashSet<String> illegalCodecs = new HashSet<String>();
+ illegalCodecs.add("PreFlex");
+ illegalCodecs.add("MockRandom");
+ illegalCodecs.add("SimpleText");
+
+ IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT,
+ new MockAnalyzer()).setReaderTermsIndexDivisor(-1);
+
+ // Don't proceed if picked Codec is in the list of illegal ones.
+ if (illegalCodecs.contains(conf.getCodecProvider().getFieldCodec("f"))) return;
+
+ Directory dir = newDirectory();
+ IndexWriter w = new IndexWriter(dir, conf);
+ Document doc = new Document();
+ doc.add(new Field("f", "val", Store.NO, Index.ANALYZED));
+ w.addDocument(doc);
+ IndexReader r = IndexReader.open(w).getSequentialSubReaders()[0];
+ try {
+ r.termDocsEnum(null, "f", new BytesRef("val"));
+ fail("should have failed to seek since terms index was not loaded. Codec used " + conf.getCodecProvider().getFieldCodec("f"));
+ } catch (IllegalStateException e) {
+ // expected - we didn't load the term index
+ } finally {
+ r.close();
+ w.close();
+ dir.close();
+ }
+ }
+
}