You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@lucene.apache.org by mi...@apache.org on 2010/03/18 01:05:27 UTC
svn commit: r924563 [3/9] - in /lucene/java/branches/flex_1458: ./ contrib/
contrib/analyzers/common/src/test/org/apache/lucene/analysis/query/
contrib/analyzers/common/src/test/org/apache/lucene/analysis/shingle/
contrib/ant/src/java/org/apache/lucene...
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/IndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/IndexWriter.java?rev=924563&r1=924562&r2=924563&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/IndexWriter.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/IndexWriter.java Thu Mar 18 00:05:22 2010
@@ -19,7 +19,7 @@ package org.apache.lucene.index;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.document.Document;
-import org.apache.lucene.index.DocumentsWriter.IndexingChain;
+import org.apache.lucene.index.IndexWriterConfig.OpenMode;
import org.apache.lucene.search.Similarity;
import org.apache.lucene.search.Query;
import org.apache.lucene.store.Directory;
@@ -30,6 +30,7 @@ import org.apache.lucene.store.BufferedI
import org.apache.lucene.util.Constants;
import org.apache.lucene.index.codecs.CodecProvider;
import org.apache.lucene.util.ThreadInterruptedException;
+import org.apache.lucene.util.Version;
import java.io.IOException;
import java.io.Closeable;
@@ -180,10 +181,11 @@ public class IndexWriter implements Clos
/**
* Default value for the write lock timeout (1,000).
* @see #setDefaultWriteLockTimeout
+ * @deprecated use {@link IndexWriterConfig#WRITE_LOCK_TIMEOUT} instead
*/
- public static long WRITE_LOCK_TIMEOUT = 1000;
+ public static long WRITE_LOCK_TIMEOUT = IndexWriterConfig.WRITE_LOCK_TIMEOUT;
- private long writeLockTimeout = WRITE_LOCK_TIMEOUT;
+ private long writeLockTimeout;
/**
* Name of the write lock in the index.
@@ -192,36 +194,43 @@ public class IndexWriter implements Clos
/**
* Value to denote a flush trigger is disabled
+ * @deprecated use {@link IndexWriterConfig#DISABLE_AUTO_FLUSH} instead
*/
- public final static int DISABLE_AUTO_FLUSH = -1;
+ public final static int DISABLE_AUTO_FLUSH = IndexWriterConfig.DISABLE_AUTO_FLUSH;
/**
* Disabled by default (because IndexWriter flushes by RAM usage
* by default). Change using {@link #setMaxBufferedDocs(int)}.
+ * @deprecated use {@link IndexWriterConfig#DEFAULT_MAX_BUFFERED_DOCS} instead.
*/
- public final static int DEFAULT_MAX_BUFFERED_DOCS = DISABLE_AUTO_FLUSH;
+ public final static int DEFAULT_MAX_BUFFERED_DOCS = IndexWriterConfig.DEFAULT_MAX_BUFFERED_DOCS;
/**
* Default value is 16 MB (which means flush when buffered
* docs consume 16 MB RAM). Change using {@link #setRAMBufferSizeMB}.
+ * @deprecated use {@link IndexWriterConfig#DEFAULT_RAM_BUFFER_SIZE_MB} instead.
*/
- public final static double DEFAULT_RAM_BUFFER_SIZE_MB = 16.0;
+ public final static double DEFAULT_RAM_BUFFER_SIZE_MB = IndexWriterConfig.DEFAULT_RAM_BUFFER_SIZE_MB;
/**
* Disabled by default (because IndexWriter flushes by RAM usage
* by default). Change using {@link #setMaxBufferedDeleteTerms(int)}.
+ * @deprecated use {@link IndexWriterConfig#DEFAULT_MAX_BUFFERED_DELETE_TERMS} instead
*/
- public final static int DEFAULT_MAX_BUFFERED_DELETE_TERMS = DISABLE_AUTO_FLUSH;
+ public final static int DEFAULT_MAX_BUFFERED_DELETE_TERMS = IndexWriterConfig.DEFAULT_MAX_BUFFERED_DELETE_TERMS;
/**
* Default value is 10,000. Change using {@link #setMaxFieldLength(int)}.
+ *
+ * @deprecated see {@link IndexWriterConfig}
*/
public final static int DEFAULT_MAX_FIELD_LENGTH = 10000;
/**
* Default value is 128. Change using {@link #setTermIndexInterval(int)}.
+ * @deprecated use {@link IndexWriterConfig#DEFAULT_TERM_INDEX_INTERVAL} instead.
*/
- public final static int DEFAULT_TERM_INDEX_INTERVAL = 128;
+ public final static int DEFAULT_TERM_INDEX_INTERVAL = IndexWriterConfig.DEFAULT_TERM_INDEX_INTERVAL;
/**
* Absolute hard maximum length for a term, in bytes once
@@ -246,10 +255,11 @@ public class IndexWriter implements Clos
private int messageID = -1;
volatile private boolean hitOOM;
- private Directory directory; // where this index resides
- private Analyzer analyzer; // how to analyze text
+ private final Directory directory; // where this index resides
+ private final Analyzer analyzer; // how to analyze text
- private Similarity similarity = Similarity.getDefault(); // how to normalize
+ // TODO 4.0: this should be made final once the setter is out
+ private /*final*/Similarity similarity = Similarity.getDefault(); // how to normalize
private volatile long changeCount; // increments every time a change is completed
private long lastCommitChangeCount; // last changeCount that was committed
@@ -272,7 +282,8 @@ public class IndexWriter implements Clos
private Lock writeLock;
- private int termIndexInterval = DEFAULT_TERM_INDEX_INTERVAL;
+ // TODO 4.0: this should be made final once the setter is out
+ private /*final*/int termIndexInterval;
private boolean closed;
private boolean closing;
@@ -282,7 +293,8 @@ public class IndexWriter implements Clos
private HashSet<SegmentInfo> mergingSegments = new HashSet<SegmentInfo>();
private MergePolicy mergePolicy = new LogByteSizeMergePolicy(this);
- private MergeScheduler mergeScheduler = new ConcurrentMergeScheduler();
+ // TODO 4.0: this should be made final once the setter is removed
+ private /*final*/MergeScheduler mergeScheduler;
private LinkedList<MergePolicy.OneMerge> pendingMerges = new LinkedList<MergePolicy.OneMerge>();
private Set<MergePolicy.OneMerge> runningMerges = new HashSet<MergePolicy.OneMerge>();
private List<MergePolicy.OneMerge> mergeExceptions = new ArrayList<MergePolicy.OneMerge>();
@@ -309,7 +321,11 @@ public class IndexWriter implements Clos
// deletes, doing merges, and reopening near real-time
// readers.
private volatile boolean poolReaders;
-
+
+ // The instance that was passed to the constructor. It is saved only in order
+ // to allow users to query an IndexWriter settings.
+ private final IndexWriterConfig config;
+
/**
* Expert: returns a readonly reader, covering all
* committed as well as un-committed changes to the index.
@@ -779,19 +795,29 @@ public class IndexWriter implements Clos
* Otherwise an IllegalArgumentException is thrown.</p>
*
* @see #setUseCompoundFile(boolean)
+ * @deprecated use {@link LogMergePolicy#getUseCompoundDocStore()} and
+ * {@link LogMergePolicy#getUseCompoundFile()} directly.
*/
public boolean getUseCompoundFile() {
return getLogMergePolicy().getUseCompoundFile();
}
- /** <p>Setting to turn on usage of a compound file. When on,
- * multiple files for each segment are merged into a
- * single file when a new segment is flushed.</p>
- *
- * <p>Note that this method is a convenience method: it
- * just calls mergePolicy.setUseCompoundFile as long as
- * mergePolicy is an instance of {@link LogMergePolicy}.
- * Otherwise an IllegalArgumentException is thrown.</p>
+ /**
+ * <p>
+ * Setting to turn on usage of a compound file. When on, multiple files for
+ * each segment are merged into a single file when a new segment is flushed.
+ * </p>
+ *
+ * <p>
+ * Note that this method is a convenience method: it just calls
+ * mergePolicy.setUseCompoundFile as long as mergePolicy is an instance of
+ * {@link LogMergePolicy}. Otherwise an IllegalArgumentException is thrown.
+ * </p>
+ *
+ * @deprecated use {@link LogMergePolicy#setUseCompoundDocStore(boolean)} and
+ * {@link LogMergePolicy#setUseCompoundFile(boolean)} directly.
+ * Note that this method set the given value on both, therefore
+ * you should consider doing the same.
*/
public void setUseCompoundFile(boolean value) {
getLogMergePolicy().setUseCompoundFile(value);
@@ -801,20 +827,25 @@ public class IndexWriter implements Clos
/** Expert: Set the Similarity implementation used by this IndexWriter.
*
* @see Similarity#setDefault(Similarity)
+ * @deprecated use {@link IndexWriterConfig#setSimilarity(Similarity)} instead
*/
public void setSimilarity(Similarity similarity) {
ensureOpen();
this.similarity = similarity;
docWriter.setSimilarity(similarity);
+ // Required so config.getSimilarity returns the right value. But this will
+ // go away together with the method in 4.0.
+ config.setSimilarity(similarity);
}
/** Expert: Return the Similarity implementation used by this IndexWriter.
*
* <p>This defaults to the current value of {@link Similarity#getDefault()}.
+ * @deprecated use {@link IndexWriterConfig#getSimilarity()} instead
*/
public Similarity getSimilarity() {
ensureOpen();
- return this.similarity;
+ return similarity;
}
/** Expert: Set the interval between indexed terms. Large values cause less
@@ -837,15 +868,20 @@ public class IndexWriter implements Clos
* must be scanned for each random term access.
*
* @see #DEFAULT_TERM_INDEX_INTERVAL
+ * @deprecated use {@link IndexWriterConfig#setTermIndexInterval(int)}
*/
public void setTermIndexInterval(int interval) {
ensureOpen();
this.termIndexInterval = interval;
+ // Required so config.getSimilarity returns the right value. But this will
+ // go away together with the method in 4.0.
+ config.setTermIndexInterval(interval);
}
/** Expert: Return the interval between indexed terms.
*
* @see #setTermIndexInterval(int)
+ * @deprecated use {@link IndexWriterConfig#getTermIndexInterval()}
*/
public int getTermIndexInterval() {
// We pass false because this method is called by SegmentMerger while we are in the process of closing
@@ -874,10 +910,13 @@ public class IndexWriter implements Clos
* if it does not exist and <code>create</code> is
* <code>false</code> or if there is any other low-level
* IO error
+ * @deprecated use {@link #IndexWriter(Directory, IndexWriterConfig)} instead
*/
public IndexWriter(Directory d, Analyzer a, boolean create, MaxFieldLength mfl)
throws CorruptIndexException, LockObtainFailedException, IOException {
- init(d, a, create, null, mfl.getLimit(), null, null, null);
+ this(d, new IndexWriterConfig(Version.LUCENE_31, a).setOpenMode(
+ create ? OpenMode.CREATE : OpenMode.APPEND).setMaxFieldLength(
+ mfl.getLimit()));
}
/**
@@ -897,10 +936,12 @@ public class IndexWriter implements Clos
* @throws IOException if the directory cannot be
* read/written to or if there is any other low-level
* IO error
+ * @deprecated use {@link #IndexWriter(Directory, IndexWriterConfig)} instead
*/
public IndexWriter(Directory d, Analyzer a, MaxFieldLength mfl)
throws CorruptIndexException, LockObtainFailedException, IOException {
- init(d, a, null, mfl.getLimit(), null, null);
+ this(d, new IndexWriterConfig(Version.LUCENE_31, a)
+ .setMaxFieldLength(mfl.getLimit()));
}
/**
@@ -920,10 +961,12 @@ public class IndexWriter implements Clos
* @throws IOException if the directory cannot be
* read/written to or if there is any other low-level
* IO error
+ * @deprecated use {@link #IndexWriter(Directory, IndexWriterConfig)} instead
*/
public IndexWriter(Directory d, Analyzer a, IndexDeletionPolicy deletionPolicy, MaxFieldLength mfl)
throws CorruptIndexException, LockObtainFailedException, IOException {
- init(d, a, deletionPolicy, mfl.getLimit(), null, null);
+ this(d, new IndexWriterConfig(Version.LUCENE_31, a).setMaxFieldLength(
+ mfl.getLimit()).setIndexDeletionPolicy(deletionPolicy));
}
/**
@@ -949,43 +992,13 @@ public class IndexWriter implements Clos
* if it does not exist and <code>create</code> is
* <code>false</code> or if there is any other low-level
* IO error
+ * @deprecated use {@link #IndexWriter(Directory, IndexWriterConfig)} instead
*/
public IndexWriter(Directory d, Analyzer a, boolean create, IndexDeletionPolicy deletionPolicy, MaxFieldLength mfl)
throws CorruptIndexException, LockObtainFailedException, IOException {
- init(d, a, create, deletionPolicy, mfl.getLimit(), null, null, null);
- }
-
- /**
- * Expert: constructs an IndexWriter with a custom {@link
- * IndexDeletionPolicy} and {@link IndexingChain},
- * for the index in <code>d</code>.
- * Text will be analyzed with <code>a</code>. If
- * <code>create</code> is true, then a new, empty index
- * will be created in <code>d</code>, replacing the index
- * already there, if any.
- *
- * @param d the index directory
- * @param a the analyzer to use
- * @param create <code>true</code> to create the index or overwrite
- * the existing one; <code>false</code> to append to the existing
- * index
- * @param deletionPolicy see <a href="#deletionPolicy">above</a>
- * @param mfl whether or not to limit field lengths, value is in number of terms/tokens. See {@link org.apache.lucene.index.IndexWriter.MaxFieldLength}.
- * @param indexingChain the {@link DocConsumer} chain to be used to
- * process documents
- * @param commit which commit to open
- * @throws CorruptIndexException if the index is corrupt
- * @throws LockObtainFailedException if another writer
- * has this index open (<code>write.lock</code> could not
- * be obtained)
- * @throws IOException if the directory cannot be read/written to, or
- * if it does not exist and <code>create</code> is
- * <code>false</code> or if there is any other low-level
- * IO error
- */
- public IndexWriter(Directory d, Analyzer a, boolean create, IndexDeletionPolicy deletionPolicy, MaxFieldLength mfl, IndexingChain indexingChain, IndexCommit commit, CodecProvider codecs)
- throws CorruptIndexException, LockObtainFailedException, IOException {
- init(d, a, create, deletionPolicy, mfl.getLimit(), indexingChain, commit, codecs);
+ this(d, new IndexWriterConfig(Version.LUCENE_31, a).setOpenMode(
+ create ? OpenMode.CREATE : OpenMode.APPEND).setMaxFieldLength(
+ mfl.getLimit()).setIndexDeletionPolicy(deletionPolicy));
}
/**
@@ -1019,52 +1032,78 @@ public class IndexWriter implements Clos
* if it does not exist and <code>create</code> is
* <code>false</code> or if there is any other low-level
* IO error
+ * @deprecated use {@link #IndexWriter(Directory, IndexWriterConfig)} instead
*/
public IndexWriter(Directory d, Analyzer a, IndexDeletionPolicy deletionPolicy, MaxFieldLength mfl, IndexCommit commit)
throws CorruptIndexException, LockObtainFailedException, IOException {
- init(d, a, false, deletionPolicy, mfl.getLimit(), null, commit, null);
+ this(d, new IndexWriterConfig(Version.LUCENE_31, a)
+ .setOpenMode(OpenMode.APPEND).setMaxFieldLength(mfl.getLimit())
+ .setIndexDeletionPolicy(deletionPolicy).setIndexCommit(commit));
}
CodecProvider codecs;
- private void init(Directory d, Analyzer a, IndexDeletionPolicy deletionPolicy,
- int maxFieldLength, IndexingChain indexingChain, IndexCommit commit)
- throws CorruptIndexException, LockObtainFailedException, IOException {
- if (IndexReader.indexExists(d)) {
- init(d, a, false, deletionPolicy, maxFieldLength, indexingChain, commit, null);
- } else {
- init(d, a, true, deletionPolicy, maxFieldLength, indexingChain, commit, null);
- }
- }
-
- private void init(Directory d, Analyzer a, final boolean create,
- IndexDeletionPolicy deletionPolicy, int maxFieldLength,
- IndexingChain indexingChain, IndexCommit commit, CodecProvider codecsIn)
- throws CorruptIndexException, LockObtainFailedException, IOException {
-
- if (codecsIn == null) {
- codecs = CodecProvider.getDefault();
- } else {
- codecs = codecsIn;
- }
-
+ /**
+ * Constructs a new IndexWriter per the settings given in <code>conf</code>.
+ * Note that the passed in {@link IndexWriterConfig} is cloned and thus making
+ * changes to it after IndexWriter has been instantiated will not affect
+ * IndexWriter. Additionally, calling {@link #getConfig()} and changing the
+ * parameters does not affect that IndexWriter instance.
+ * <p>
+ * <b>NOTE:</b> by default, {@link IndexWriterConfig#getMaxFieldLength()}
+ * returns {@link IndexWriterConfig#UNLIMITED_FIELD_LENGTH}. Pay attention to
+ * whether this setting fits your application.
+ *
+ * @param d
+ * the index directory. The index is either created or appended
+ * according <code>conf.getOpenMode()</code>.
+ * @param conf
+ * the configuration settings according to which IndexWriter should
+ * be initalized.
+ * @throws CorruptIndexException
+ * if the index is corrupt
+ * @throws LockObtainFailedException
+ * if another writer has this index open (<code>write.lock</code>
+ * could not be obtained)
+ * @throws IOException
+ * if the directory cannot be read/written to, or if it does not
+ * exist and <code>conf.getOpenMode()</code> is
+ * <code>OpenMode.APPEND</code> or if there is any other low-level
+ * IO error
+ */
+ public IndexWriter(Directory d, IndexWriterConfig conf)
+ throws CorruptIndexException, LockObtainFailedException, IOException {
+ config = (IndexWriterConfig) conf.clone();
directory = d;
- analyzer = a;
+ analyzer = conf.getAnalyzer();
setMessageID(defaultInfoStream);
- this.maxFieldLength = maxFieldLength;
-
- if (indexingChain == null)
- indexingChain = DocumentsWriter.DefaultIndexingChain;
+ maxFieldLength = conf.getMaxFieldLength();
+ termIndexInterval = conf.getTermIndexInterval();
+ writeLockTimeout = conf.getWriteLockTimeout();
+ similarity = conf.getSimilarity();
+ mergeScheduler = conf.getMergeScheduler();
+ mergedSegmentWarmer = conf.getMergedSegmentWarmer();
+ codecs = conf.getCodecProvider();
+
+ OpenMode mode = conf.getOpenMode();
+ boolean create;
+ if (mode == OpenMode.CREATE) {
+ create = true;
+ } else if (mode == OpenMode.APPEND) {
+ create = false;
+ } else {
+ // CREATE_OR_APPEND - create only if an index does not exist
+ create = !IndexReader.indexExists(directory);
+ }
if (create) {
// Clear the write lock in case it's leftover:
directory.clearLock(WRITE_LOCK_NAME);
}
- Lock writeLock = directory.makeLock(WRITE_LOCK_NAME);
+ writeLock = directory.makeLock(WRITE_LOCK_NAME);
if (!writeLock.obtain(writeLockTimeout)) // obtain write lock
throw new LockObtainFailedException("Index locked for write: " + writeLock);
- this.writeLock = writeLock; // save it
try {
if (create) {
@@ -1095,6 +1134,7 @@ public class IndexWriter implements Clos
} else {
segmentInfos.read(directory, codecs);
+ IndexCommit commit = conf.getIndexCommit();
if (commit != null) {
// Swap out all segments, but, keep metadata in
// SegmentInfos, like version & generation, to
@@ -1118,14 +1158,14 @@ public class IndexWriter implements Clos
setRollbackSegmentInfos(segmentInfos);
- docWriter = new DocumentsWriter(directory, this, indexingChain);
+ docWriter = new DocumentsWriter(directory, this, conf.getIndexingChain());
docWriter.setInfoStream(infoStream);
docWriter.setMaxFieldLength(maxFieldLength);
// Default deleter (for backwards compatibility) is
// KeepOnlyLastCommitDeleter:
deleter = new IndexFileDeleter(directory,
- deletionPolicy == null ? new KeepOnlyLastCommitDeletionPolicy() : deletionPolicy,
+ conf.getIndexDeletionPolicy(),
segmentInfos, infoStream, docWriter, this.codecs);
if (deleter.startingCommitDeleted)
@@ -1135,6 +1175,9 @@ public class IndexWriter implements Clos
// segments_N file.
changeCount++;
+ docWriter.setMaxBufferedDeleteTerms(conf.getMaxBufferedDeleteTerms());
+ docWriter.setRAMBufferSizeMB(conf.getRAMBufferSizeMB());
+ docWriter.setMaxBufferedDocs(conf.getMaxBufferedDocs());
pushMaxBufferedDocs();
if (infoStream != null) {
@@ -1143,12 +1186,12 @@ public class IndexWriter implements Clos
}
} catch (IOException e) {
- this.writeLock.release();
- this.writeLock = null;
+ writeLock.release();
+ writeLock = null;
throw e;
}
}
-
+
private synchronized void setRollbackSegmentInfos(SegmentInfos infos) {
rollbackSegmentInfos = (SegmentInfos) infos.clone();
assert !rollbackSegmentInfos.hasExternalSegments(directory);
@@ -1159,6 +1202,19 @@ public class IndexWriter implements Clos
}
/**
+ * Returns the {@link IndexWriterConfig} that was passed to
+ * {@link #IndexWriter(Directory, IndexWriterConfig)}. This allows querying
+ * IndexWriter's settings.
+ * <p>
+ * <b>NOTE:</b> setting any parameter on the returned instance has not effect
+ * on the IndexWriter instance. If you need to change those settings after
+ * IndexWriter has been created, you need to instantiate a new IndexWriter.
+ */
+ public IndexWriterConfig getConfig() {
+ return config;
+ }
+
+ /**
* Expert: set the merge policy used by this writer.
*/
public void setMergePolicy(MergePolicy mp) {
@@ -1185,6 +1241,7 @@ public class IndexWriter implements Clos
/**
* Expert: set the merge scheduler used by this writer.
+ * @deprecated use {@link IndexWriterConfig#setMergeScheduler(MergeScheduler)} instead
*/
synchronized public void setMergeScheduler(MergeScheduler mergeScheduler) throws CorruptIndexException, IOException {
ensureOpen();
@@ -1198,12 +1255,16 @@ public class IndexWriter implements Clos
this.mergeScheduler = mergeScheduler;
if (infoStream != null)
message("setMergeScheduler " + mergeScheduler);
+ // Required so config.getSimilarity returns the right value. But this will
+ // go away together with the method in 4.0.
+ config.setMergeScheduler(mergeScheduler);
}
/**
- * Expert: returns the current MergePolicy in use by this
+ * Expert: returns the current MergeScheduler in use by this
* writer.
- * @see #setMergePolicy
+ * @see #setMergeScheduler(MergeScheduler)
+ * @deprecated use {@link IndexWriterConfig#getMergeScheduler()} instead
*/
public MergeScheduler getMergeScheduler() {
ensureOpen();
@@ -1229,6 +1290,7 @@ public class IndexWriter implements Clos
* LogByteSizeMergePolicy}) also allows you to set this
* limit by net size (in MB) of the segment, using {@link
* LogByteSizeMergePolicy#setMaxMergeMB}.</p>
+ * @deprecated use {@link LogMergePolicy#setMaxMergeDocs(int)} directly.
*/
public void setMaxMergeDocs(int maxMergeDocs) {
getLogMergePolicy().setMaxMergeDocs(maxMergeDocs);
@@ -1244,6 +1306,7 @@ public class IndexWriter implements Clos
* Otherwise an IllegalArgumentException is thrown.</p>
*
* @see #setMaxMergeDocs
+ * @deprecated use {@link LogMergePolicy#getMaxMergeDocs()} directly.
*/
public int getMaxMergeDocs() {
return getLogMergePolicy().getMaxMergeDocs();
@@ -1262,6 +1325,7 @@ public class IndexWriter implements Clos
* is your memory, but you should anticipate an OutOfMemoryError.<p/>
* By default, no more than {@link #DEFAULT_MAX_FIELD_LENGTH} terms
* will be indexed for a field.
+ * @deprecated use {@link IndexWriterConfig#setMaxFieldLength(int)} instead
*/
public void setMaxFieldLength(int maxFieldLength) {
ensureOpen();
@@ -1269,12 +1333,16 @@ public class IndexWriter implements Clos
docWriter.setMaxFieldLength(maxFieldLength);
if (infoStream != null)
message("setMaxFieldLength " + maxFieldLength);
+ // Required so config.getSimilarity returns the right value. But this will
+ // go away together with the method in 4.0.
+ config.setMaxFieldLength(maxFieldLength);
}
/**
* Returns the maximum number of terms that will be
* indexed for a single field in a document.
* @see #setMaxFieldLength
+ * @deprecated use {@link IndexWriterConfig#getMaxFieldLength()} instead
*/
public int getMaxFieldLength() {
ensureOpen();
@@ -1299,6 +1367,7 @@ public class IndexWriter implements Clos
* enabled but smaller than 2, or it disables maxBufferedDocs
* when ramBufferSize is already disabled
* @see #setRAMBufferSizeMB
+ * @deprecated use {@link IndexWriterConfig#setMaxBufferedDocs(int)} instead.
*/
public void setMaxBufferedDocs(int maxBufferedDocs) {
ensureOpen();
@@ -1313,6 +1382,9 @@ public class IndexWriter implements Clos
pushMaxBufferedDocs();
if (infoStream != null)
message("setMaxBufferedDocs " + maxBufferedDocs);
+ // Required so config.getSimilarity returns the right value. But this will
+ // go away together with the method in 4.0.
+ config.setMaxBufferedDocs(maxBufferedDocs);
}
/**
@@ -1339,6 +1411,7 @@ public class IndexWriter implements Clos
* Returns the number of buffered added documents that will
* trigger a flush if enabled.
* @see #setMaxBufferedDocs
+ * @deprecated use {@link IndexWriterConfig#getMaxBufferedDocs()} instead.
*/
public int getMaxBufferedDocs() {
ensureOpen();
@@ -1382,6 +1455,7 @@ public class IndexWriter implements Clos
* @throws IllegalArgumentException if ramBufferSize is
* enabled but non-positive, or it disables ramBufferSize
* when maxBufferedDocs is already disabled
+ * @deprecated use {@link IndexWriterConfig#setRAMBufferSizeMB(double)} instead.
*/
public void setRAMBufferSizeMB(double mb) {
if (mb > 2048.0) {
@@ -1396,10 +1470,14 @@ public class IndexWriter implements Clos
docWriter.setRAMBufferSizeMB(mb);
if (infoStream != null)
message("setRAMBufferSizeMB " + mb);
+ // Required so config.getSimilarity returns the right value. But this will
+ // go away together with the method in 4.0.
+ config.setRAMBufferSizeMB(mb);
}
/**
* Returns the value set by {@link #setRAMBufferSizeMB} if enabled.
+ * @deprecated use {@link IndexWriterConfig#getRAMBufferSizeMB()} instead.
*/
public double getRAMBufferSizeMB() {
return docWriter.getRAMBufferSizeMB();
@@ -1416,6 +1494,7 @@ public class IndexWriter implements Clos
* @throws IllegalArgumentException if maxBufferedDeleteTerms
* is enabled but smaller than 1
* @see #setRAMBufferSizeMB
+ * @deprecated use {@link IndexWriterConfig#setMaxBufferedDeleteTerms(int)} instead.
*/
public void setMaxBufferedDeleteTerms(int maxBufferedDeleteTerms) {
ensureOpen();
@@ -1426,12 +1505,16 @@ public class IndexWriter implements Clos
docWriter.setMaxBufferedDeleteTerms(maxBufferedDeleteTerms);
if (infoStream != null)
message("setMaxBufferedDeleteTerms " + maxBufferedDeleteTerms);
+ // Required so config.getSimilarity returns the right value. But this will
+ // go away together with the method in 4.0.
+ config.setMaxBufferedDeleteTerms(maxBufferedDeleteTerms);
}
/**
* Returns the number of buffered deleted terms that will
* trigger a flush if enabled.
* @see #setMaxBufferedDeleteTerms
+ * @deprecated use {@link IndexWriterConfig#getMaxBufferedDeleteTerms()} instead
*/
public int getMaxBufferedDeleteTerms() {
ensureOpen();
@@ -1452,6 +1535,7 @@ public class IndexWriter implements Clos
* Otherwise an IllegalArgumentException is thrown.</p>
*
* <p>This must never be less than 2. The default value is 10.
+ * @deprecated use {@link LogMergePolicy#setMergeFactor(int)} directly.
*/
public void setMergeFactor(int mergeFactor) {
getLogMergePolicy().setMergeFactor(mergeFactor);
@@ -1468,6 +1552,7 @@ public class IndexWriter implements Clos
* Otherwise an IllegalArgumentException is thrown.</p>
*
* @see #setMergeFactor
+ * @deprecated use {@link LogMergePolicy#getMergeFactor()} directly.
*/
public int getMergeFactor() {
return getLogMergePolicy().getMergeFactor();
@@ -1504,15 +1589,11 @@ public class IndexWriter implements Clos
}
private void messageState() {
- message("setInfoStream: dir=" + directory +
- " mergePolicy=" + mergePolicy +
- " mergeScheduler=" + mergeScheduler +
- " ramBufferSizeMB=" + docWriter.getRAMBufferSizeMB() +
- " maxBufferedDocs=" + docWriter.getMaxBufferedDocs() +
- " maxBuffereDeleteTerms=" + docWriter.getMaxBufferedDeleteTerms() +
- " maxFieldLength=" + maxFieldLength +
- " index=" + segString() +
- " version=" + Constants.LUCENE_VERSION);
+ message("\ndir=" + directory + "\n" +
+ "mergePolicy=" + mergePolicy + "\n" +
+ "index=" + segString() + "\n" +
+ "version=" + Constants.LUCENE_VERSION + "\n" +
+ config.toString());
}
/**
@@ -1532,15 +1613,20 @@ public class IndexWriter implements Clos
/**
* Sets the maximum time to wait for a write lock (in milliseconds) for this instance of IndexWriter. @see
* @see #setDefaultWriteLockTimeout to change the default value for all instances of IndexWriter.
+ * @deprecated use {@link IndexWriterConfig#setWriteLockTimeout(long)} instead
*/
public void setWriteLockTimeout(long writeLockTimeout) {
ensureOpen();
this.writeLockTimeout = writeLockTimeout;
+ // Required so config.getSimilarity returns the right value. But this will
+ // go away together with the method in 4.0.
+ config.setWriteLockTimeout(writeLockTimeout);
}
/**
* Returns allowed timeout when acquiring the write lock.
* @see #setWriteLockTimeout
+ * @deprecated use {@link IndexWriterConfig#getWriteLockTimeout()}
*/
public long getWriteLockTimeout() {
ensureOpen();
@@ -1550,18 +1636,20 @@ public class IndexWriter implements Clos
/**
* Sets the default (for any instance of IndexWriter) maximum time to wait for a write lock (in
* milliseconds).
+ * @deprecated use {@link IndexWriterConfig#setDefaultWriteLockTimeout(long)} instead
*/
public static void setDefaultWriteLockTimeout(long writeLockTimeout) {
- IndexWriter.WRITE_LOCK_TIMEOUT = writeLockTimeout;
+ IndexWriterConfig.setDefaultWriteLockTimeout(writeLockTimeout);
}
/**
* Returns default write lock timeout for newly
* instantiated IndexWriters.
* @see #setDefaultWriteLockTimeout
+ * @deprecated use {@link IndexWriterConfig#getDefaultWriteLockTimeout()} instead
*/
public static long getDefaultWriteLockTimeout() {
- return IndexWriter.WRITE_LOCK_TIMEOUT;
+ return IndexWriterConfig.getDefaultWriteLockTimeout();
}
/**
@@ -4808,9 +4896,13 @@ public class IndexWriter implements Clos
}
/**
- * Specifies maximum field length (in number of tokens/terms) in {@link IndexWriter} constructors.
- * {@link #setMaxFieldLength(int)} overrides the value set by
- * the constructor.
+ * Specifies maximum field length (in number of tokens/terms) in
+ * {@link IndexWriter} constructors. {@link #setMaxFieldLength(int)} overrides
+ * the value set by the constructor.
+ *
+ * @deprecated use {@link IndexWriterConfig} and pass
+ * {@link IndexWriterConfig#UNLIMITED_FIELD_LENGTH} or your own
+ * value.
*/
public static final class MaxFieldLength {
@@ -4886,10 +4978,16 @@ public class IndexWriter implements Clos
*/
public void setMergedSegmentWarmer(IndexReaderWarmer warmer) {
mergedSegmentWarmer = warmer;
+ // Required so config.getSimilarity returns the right value. But this will
+ // go away together with the method in 4.0.
+ config.setMergedSegmentWarmer(mergedSegmentWarmer);
}
- /** Returns the current merged segment warmer. See {@link
- * IndexReaderWarmer}. */
+ /**
+ * Returns the current merged segment warmer. See {@link IndexReaderWarmer}.
+ *
+ * @deprecated use {@link IndexWriterConfig#getMergedSegmentWarmer()} instead.
+ */
public IndexReaderWarmer getMergedSegmentWarmer() {
return mergedSegmentWarmer;
}
Copied: lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/IndexWriterConfig.java (from r922583, lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriterConfig.java)
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/IndexWriterConfig.java?p2=lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/IndexWriterConfig.java&p1=lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriterConfig.java&r1=922583&r2=924563&rev=924563&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriterConfig.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/IndexWriterConfig.java Thu Mar 18 00:05:22 2010
@@ -20,6 +20,7 @@ package org.apache.lucene.index;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.index.DocumentsWriter.IndexingChain;
import org.apache.lucene.index.IndexWriter.IndexReaderWarmer;
+import org.apache.lucene.index.codecs.CodecProvider;
import org.apache.lucene.search.Similarity;
import org.apache.lucene.util.Version;
@@ -78,6 +79,9 @@ public final class IndexWriterConfig imp
*/
public static long WRITE_LOCK_TIMEOUT = 1000;
+ /** Default {@link CodecProvider}. */
+ public final static CodecProvider DEFAULT_CODEC_PROVIDER = CodecProvider.getDefault();
+
/**
* Sets the default (for any instance) maximum time to wait for a write lock
* (in milliseconds).
@@ -110,6 +114,7 @@ public final class IndexWriterConfig imp
private int maxBufferedDocs;
private IndexingChain indexingChain;
private IndexReaderWarmer mergedSegmentWarmer;
+ private CodecProvider codecProvider;
// required for clone
private Version matchVersion;
@@ -137,6 +142,7 @@ public final class IndexWriterConfig imp
maxBufferedDocs = DEFAULT_MAX_BUFFERED_DOCS;
indexingChain = DocumentsWriter.defaultIndexingChain;
mergedSegmentWarmer = null;
+ codecProvider = DEFAULT_CODEC_PROVIDER;
}
@Override
@@ -483,6 +489,16 @@ public final class IndexWriterConfig imp
return mergedSegmentWarmer;
}
+ /** Set the CodecProvider. See {@link CodecProvider}. */
+ public IndexWriterConfig setCodecProvider(CodecProvider codecProvider) {
+ this.codecProvider = codecProvider;
+ return this;
+ }
+
+ /** Returns the current merged segment warmer. See {@link IndexReaderWarmer}. */
+ public CodecProvider getCodecProvider() {
+ return codecProvider;
+ }
/** Expert: sets the {@link DocConsumer} chain to be used to process documents. */
IndexWriterConfig setIndexingChain(IndexingChain indexingChain) {
@@ -513,6 +529,7 @@ public final class IndexWriterConfig imp
sb.append("ramBufferSizeMB=").append(ramBufferSizeMB).append("\n");
sb.append("maxBufferedDocs=").append(maxBufferedDocs).append("\n");
sb.append("mergedSegmentWarmer=").append(mergedSegmentWarmer).append("\n");
+ sb.append("codecProvider=").append(codecProvider).append("\n");
return sb.toString();
}
}
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/SegmentMerger.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/SegmentMerger.java?rev=924563&r1=924562&r2=924563&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/SegmentMerger.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/SegmentMerger.java Thu Mar 18 00:05:22 2010
@@ -56,7 +56,7 @@ final class SegmentMerger {
private Directory directory;
private String segment;
- private int termIndexInterval = IndexWriter.DEFAULT_TERM_INDEX_INTERVAL;
+ private int termIndexInterval = IndexWriterConfig.DEFAULT_TERM_INDEX_INTERVAL;
private List<IndexReader> readers = new ArrayList<IndexReader>();
private FieldInfos fieldInfos;
Propchange: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Mar 18 00:05:22 2010
@@ -1,2 +1,2 @@
/lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java:909334
-/lucene/java/trunk/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java:916596,916685,916755,916769,917019,917148,917154,917161,917203-917204,919060,919119,919718,919731,919869,920237-920499,922013,922277,922525,922528,922602,922624,922797,922799,922886-922887,923112,924151,924207,924286
+/lucene/java/trunk/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java:916596,916685,916755,916769,917019,917148,917154,917161,917203-917204,919060,919119,919718,919731,919869,920237-920499,922013,922277,922525,922528,922583,922593,922602,922624,922797,922799,922886-922887,923112,924151,924207,924286
Modified: lucene/java/branches/flex_1458/src/test/org/apache/lucene/TestDemo.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/test/org/apache/lucene/TestDemo.java?rev=924563&r1=924562&r2=924563&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/test/org/apache/lucene/TestDemo.java (original)
+++ lucene/java/branches/flex_1458/src/test/org/apache/lucene/TestDemo.java Thu Mar 18 00:05:22 2010
@@ -25,6 +25,7 @@ import org.apache.lucene.document.Docume
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.Term;
+import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.IndexSearcher;
@@ -51,8 +52,9 @@ public class TestDemo extends LuceneTest
Directory directory = new RAMDirectory();
// To store an index on disk, use this instead:
//Directory directory = FSDirectory.open("/tmp/testindex");
- IndexWriter iwriter = new IndexWriter(directory, analyzer, true,
- new IndexWriter.MaxFieldLength(25000));
+ IndexWriter iwriter = new IndexWriter(directory, new IndexWriterConfig(
+ TEST_VERSION_CURRENT, analyzer).setMaxFieldLength(25000));
+
Document doc = new Document();
String longTerm = "longtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongterm";
String text = "This is the text to be indexed. " + longTerm;
Modified: lucene/java/branches/flex_1458/src/test/org/apache/lucene/TestExternalCodecs.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/test/org/apache/lucene/TestExternalCodecs.java?rev=924563&r1=924562&r2=924563&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/test/org/apache/lucene/TestExternalCodecs.java (original)
+++ lucene/java/branches/flex_1458/src/test/org/apache/lucene/TestExternalCodecs.java Thu Mar 18 00:05:22 2010
@@ -805,8 +805,8 @@ public class TestExternalCodecs extends
final int NUM_DOCS = 173;
Directory dir = new MockRAMDirectory();
- IndexWriter w = new IndexWriter(dir, new WhitespaceAnalyzer(), true, null, IndexWriter.MaxFieldLength.UNLIMITED,
- null, null, new MyCodecs());
+ IndexWriter w = new IndexWriter(dir,
+ new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer()).setCodecProvider(new MyCodecs()));
w.setMergeFactor(3);
Document doc = new Document();
Modified: lucene/java/branches/flex_1458/src/test/org/apache/lucene/TestMergeSchedulerExternal.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/test/org/apache/lucene/TestMergeSchedulerExternal.java?rev=924563&r1=924562&r2=924563&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/test/org/apache/lucene/TestMergeSchedulerExternal.java (original)
+++ lucene/java/branches/flex_1458/src/test/org/apache/lucene/TestMergeSchedulerExternal.java Thu Mar 18 00:05:22 2010
@@ -18,11 +18,12 @@ package org.apache.lucene;
*/
import java.io.IOException;
import org.apache.lucene.util.LuceneTestCase;
-import org.apache.lucene.analysis.WhitespaceAnalyzer;
import org.apache.lucene.store.MockRAMDirectory;
import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.MergePolicy;
import org.apache.lucene.index.ConcurrentMergeScheduler;
+import org.apache.lucene.analysis.WhitespaceAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
@@ -86,15 +87,14 @@ public class TestMergeSchedulerExternal
Field idField = new Field("id", "", Field.Store.YES, Field.Index.NOT_ANALYZED);
doc.add(idField);
- IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(TEST_VERSION_CURRENT), true, IndexWriter.MaxFieldLength.LIMITED);
- MyMergeScheduler ms = new MyMergeScheduler();
- writer.setMergeScheduler(ms);
- writer.setMaxBufferedDocs(2);
- writer.setRAMBufferSizeMB(IndexWriter.DISABLE_AUTO_FLUSH);
+ IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(
+ TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setMergeScheduler(new MyMergeScheduler())
+ .setMaxBufferedDocs(2).setRAMBufferSizeMB(
+ IndexWriterConfig.DISABLE_AUTO_FLUSH));
for(int i=0;i<20;i++)
writer.addDocument(doc);
- ms.sync();
+ ((MyMergeScheduler) writer.getConfig().getMergeScheduler()).sync();
writer.close();
assertTrue(mergeThreadCreated);
Modified: lucene/java/branches/flex_1458/src/test/org/apache/lucene/TestSearch.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/test/org/apache/lucene/TestSearch.java?rev=924563&r1=924562&r2=924563&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/test/org/apache/lucene/TestSearch.java (original)
+++ lucene/java/branches/flex_1458/src/test/org/apache/lucene/TestSearch.java Thu Mar 18 00:05:22 2010
@@ -70,14 +70,14 @@ public class TestSearch extends LuceneTe
private void doTestSearch(PrintWriter out, boolean useCompoundFile)
- throws Exception
- {
+ throws Exception {
Directory directory = new RAMDirectory();
Analyzer analyzer = new SimpleAnalyzer(TEST_VERSION_CURRENT);
- IndexWriter writer = new IndexWriter(directory, analyzer, true,
- IndexWriter.MaxFieldLength.LIMITED);
-
- writer.setUseCompoundFile(useCompoundFile);
+ IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(
+ TEST_VERSION_CURRENT, analyzer));
+ LogMergePolicy lmp = (LogMergePolicy) writer.getMergePolicy();
+ lmp.setUseCompoundFile(useCompoundFile);
+ lmp.setUseCompoundDocStore(useCompoundFile);
String[] docs = {
"a b c d e",
Modified: lucene/java/branches/flex_1458/src/test/org/apache/lucene/TestSearchForDuplicates.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/test/org/apache/lucene/TestSearchForDuplicates.java?rev=924563&r1=924562&r2=924563&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/test/org/apache/lucene/TestSearchForDuplicates.java (original)
+++ lucene/java/branches/flex_1458/src/test/org/apache/lucene/TestSearchForDuplicates.java Thu Mar 18 00:05:22 2010
@@ -78,10 +78,11 @@ public class TestSearchForDuplicates ext
private void doTest(PrintWriter out, boolean useCompoundFiles) throws Exception {
Directory directory = new RAMDirectory();
Analyzer analyzer = new SimpleAnalyzer(TEST_VERSION_CURRENT);
- IndexWriter writer = new IndexWriter(directory, analyzer, true,
- IndexWriter.MaxFieldLength.LIMITED);
-
- writer.setUseCompoundFile(useCompoundFiles);
+ IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(
+ TEST_VERSION_CURRENT, analyzer));
+ LogMergePolicy lmp = (LogMergePolicy) writer.getMergePolicy();
+ lmp.setUseCompoundFile(useCompoundFiles);
+ lmp.setUseCompoundDocStore(useCompoundFiles);
final int MAX_DOCS = 225;
Modified: lucene/java/branches/flex_1458/src/test/org/apache/lucene/TestSnapshotDeletionPolicy.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/test/org/apache/lucene/TestSnapshotDeletionPolicy.java?rev=924563&r1=924562&r2=924563&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/test/org/apache/lucene/TestSnapshotDeletionPolicy.java (original)
+++ lucene/java/branches/flex_1458/src/test/org/apache/lucene/TestSnapshotDeletionPolicy.java Thu Mar 18 00:05:22 2010
@@ -31,6 +31,7 @@ import org.apache.lucene.store.IndexInpu
import org.apache.lucene.store.MockRAMDirectory;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.index.IndexCommit;
+import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.KeepOnlyLastCommitDeletionPolicy;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.TestIndexWriter;
@@ -67,9 +68,10 @@ public class TestSnapshotDeletionPolicy
Directory dir = new MockRAMDirectory();
SnapshotDeletionPolicy dp = new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy());
- IndexWriter writer = new IndexWriter(dir, new StandardAnalyzer(TEST_VERSION_CURRENT), dp, IndexWriter.MaxFieldLength.UNLIMITED);
- // Force frequent flushes
- writer.setMaxBufferedDocs(2);
+ IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(
+ TEST_VERSION_CURRENT,
+ new StandardAnalyzer(TEST_VERSION_CURRENT)).setIndexDeletionPolicy(dp)
+ .setMaxBufferedDocs(2));
Document doc = new Document();
doc.add(new Field("content", "aaa", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
for(int i=0;i<7;i++) {
@@ -83,7 +85,8 @@ public class TestSnapshotDeletionPolicy
writer.close();
copyFiles(dir, cp);
- writer = new IndexWriter(dir, new StandardAnalyzer(TEST_VERSION_CURRENT), dp, IndexWriter.MaxFieldLength.UNLIMITED);
+ writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT,
+ new StandardAnalyzer(TEST_VERSION_CURRENT)).setIndexDeletionPolicy(dp));
copyFiles(dir, cp);
for(int i=0;i<7;i++) {
writer.addDocument(doc);
@@ -95,7 +98,8 @@ public class TestSnapshotDeletionPolicy
writer.close();
copyFiles(dir, cp);
dp.release();
- writer = new IndexWriter(dir, new StandardAnalyzer(TEST_VERSION_CURRENT), dp, IndexWriter.MaxFieldLength.UNLIMITED);
+ writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT,
+ new StandardAnalyzer(TEST_VERSION_CURRENT)).setIndexDeletionPolicy(dp));
writer.close();
try {
copyFiles(dir, cp);
@@ -111,10 +115,10 @@ public class TestSnapshotDeletionPolicy
final long stopTime = System.currentTimeMillis() + 1000;
SnapshotDeletionPolicy dp = new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy());
- final IndexWriter writer = new IndexWriter(dir, new StandardAnalyzer(TEST_VERSION_CURRENT), dp, IndexWriter.MaxFieldLength.UNLIMITED);
-
- // Force frequent flushes
- writer.setMaxBufferedDocs(2);
+ final IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(
+ TEST_VERSION_CURRENT,
+ new StandardAnalyzer(TEST_VERSION_CURRENT)).setIndexDeletionPolicy(dp)
+ .setMaxBufferedDocs(2));
final Thread t = new Thread() {
@Override
Modified: lucene/java/branches/flex_1458/src/test/org/apache/lucene/analysis/TestCachingTokenFilter.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/test/org/apache/lucene/analysis/TestCachingTokenFilter.java?rev=924563&r1=924562&r2=924563&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/test/org/apache/lucene/analysis/TestCachingTokenFilter.java (original)
+++ lucene/java/branches/flex_1458/src/test/org/apache/lucene/analysis/TestCachingTokenFilter.java Thu Mar 18 00:05:22 2010
@@ -27,6 +27,7 @@ import org.apache.lucene.document.Field;
import org.apache.lucene.document.Field.TermVector;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.TermPositions;
import org.apache.lucene.store.Directory;
@@ -37,7 +38,8 @@ public class TestCachingTokenFilter exte
public void testCaching() throws IOException {
Directory dir = new RAMDirectory();
- IndexWriter writer = new IndexWriter(dir, new SimpleAnalyzer(TEST_VERSION_CURRENT), IndexWriter.MaxFieldLength.LIMITED);
+ IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(
+ TEST_VERSION_CURRENT, new SimpleAnalyzer(TEST_VERSION_CURRENT)));
Document doc = new Document();
TokenStream stream = new TokenStream() {
private int index = 0;
Propchange: lucene/java/branches/flex_1458/src/test/org/apache/lucene/analysis/TestISOLatin1AccentFilter.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Mar 18 00:05:22 2010
@@ -1,4 +1,4 @@
/lucene/java/branches/lucene_2_4/src/test/org/apache/lucene/analysis/TestISOLatin1AccentFilter.java:748824
/lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/analysis/TestISOLatin1AccentFilter.java:829134,829881,831036,896850,909334
/lucene/java/branches/lucene_3_0/src/test/org/apache/lucene/analysis/TestISOLatin1AccentFilter.java:880793,896906
-/lucene/java/trunk/src/test/org/apache/lucene/analysis/TestISOLatin1AccentFilter.java:824912-825292,826213-833960,880727-886190,889185,889614-916543,916596,916685,916755,916769,917019,917148,917154,917161,917203-917204,919060,919119,919718,919731,919869,920237-920499,922013,922277,922525,922528,922602,922624,922797,922799,922886-922887,923112,924151,924207,924286
+/lucene/java/trunk/src/test/org/apache/lucene/analysis/TestISOLatin1AccentFilter.java:824912-825292,826213-833960,880727-886190,889185,889614-916543,916596,916685,916755,916769,917019,917148,917154,917161,917203-917204,919060,919119,919718,919731,919869,920237-920499,922013,922277,922525,922528,922583,922593,922602,922624,922797,922799,922886-922887,923112,924151,924207,924286
Modified: lucene/java/branches/flex_1458/src/test/org/apache/lucene/analysis/TestKeywordAnalyzer.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/test/org/apache/lucene/analysis/TestKeywordAnalyzer.java?rev=924563&r1=924562&r2=924563&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/test/org/apache/lucene/analysis/TestKeywordAnalyzer.java (original)
+++ lucene/java/branches/flex_1458/src/test/org/apache/lucene/analysis/TestKeywordAnalyzer.java Thu Mar 18 00:05:22 2010
@@ -24,6 +24,7 @@ import org.apache.lucene.document.Docume
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.TermDocs;
import org.apache.lucene.queryParser.QueryParser;
@@ -41,9 +42,9 @@ public class TestKeywordAnalyzer extends
protected void setUp() throws Exception {
super.setUp();
directory = new RAMDirectory();
- IndexWriter writer = new IndexWriter(directory,
- new SimpleAnalyzer(TEST_VERSION_CURRENT),
- true, IndexWriter.MaxFieldLength.LIMITED);
+ IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(
+ TEST_VERSION_CURRENT, new SimpleAnalyzer(
+ TEST_VERSION_CURRENT)));
Document doc = new Document();
doc.add(new Field("partnum", "Q36", Field.Store.YES, Field.Index.NOT_ANALYZED));
@@ -70,7 +71,7 @@ public class TestKeywordAnalyzer extends
public void testMutipleDocument() throws Exception {
RAMDirectory dir = new RAMDirectory();
- IndexWriter writer = new IndexWriter(dir,new KeywordAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
+ IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new KeywordAnalyzer()));
Document doc = new Document();
doc.add(new Field("partnum", "Q36", Field.Store.YES, Field.Index.ANALYZED));
writer.addDocument(doc);
Modified: lucene/java/branches/flex_1458/src/test/org/apache/lucene/collation/CollationTestBase.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/test/org/apache/lucene/collation/CollationTestBase.java?rev=924563&r1=924562&r2=924563&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/test/org/apache/lucene/collation/CollationTestBase.java (original)
+++ lucene/java/branches/flex_1458/src/test/org/apache/lucene/collation/CollationTestBase.java Thu Mar 18 00:05:22 2010
@@ -23,6 +23,7 @@ import org.apache.lucene.analysis.PerFie
import org.apache.lucene.analysis.WhitespaceAnalyzer;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.IndexSearcher;
@@ -69,8 +70,8 @@ public class CollationTestBase extends L
String firstEnd, String secondBeg,
String secondEnd) throws Exception {
RAMDirectory ramDir = new RAMDirectory();
- IndexWriter writer = new IndexWriter
- (ramDir, analyzer, true, IndexWriter.MaxFieldLength.LIMITED);
+ IndexWriter writer = new IndexWriter(ramDir, new IndexWriterConfig(
+ TEST_VERSION_CURRENT, analyzer));
Document doc = new Document();
doc.add(new Field("content", "\u0633\u0627\u0628",
Field.Store.YES, Field.Index.ANALYZED));
@@ -101,8 +102,8 @@ public class CollationTestBase extends L
String firstEnd, String secondBeg,
String secondEnd) throws Exception {
RAMDirectory ramDir = new RAMDirectory();
- IndexWriter writer = new IndexWriter
- (ramDir, analyzer, true, IndexWriter.MaxFieldLength.LIMITED);
+ IndexWriter writer = new IndexWriter(ramDir, new IndexWriterConfig(
+ TEST_VERSION_CURRENT, analyzer));
Document doc = new Document();
// Unicode order would include U+0633 in [ U+062F - U+0698 ], but Farsi
@@ -125,13 +126,12 @@ public class CollationTestBase extends L
searcher.close();
}
- public void testFarsiTermRangeQuery
- (Analyzer analyzer, String firstBeg, String firstEnd,
- String secondBeg, String secondEnd) throws Exception {
+ public void testFarsiTermRangeQuery(Analyzer analyzer, String firstBeg,
+ String firstEnd, String secondBeg, String secondEnd) throws Exception {
RAMDirectory farsiIndex = new RAMDirectory();
- IndexWriter writer = new IndexWriter
- (farsiIndex, analyzer, true, IndexWriter.MaxFieldLength.LIMITED);
+ IndexWriter writer = new IndexWriter(farsiIndex, new IndexWriterConfig(
+ TEST_VERSION_CURRENT, analyzer));
Document doc = new Document();
doc.add(new Field("content", "\u0633\u0627\u0628",
Field.Store.YES, Field.Index.ANALYZED));
@@ -178,8 +178,8 @@ public class CollationTestBase extends L
analyzer.addAnalyzer("France", franceAnalyzer);
analyzer.addAnalyzer("Sweden", swedenAnalyzer);
analyzer.addAnalyzer("Denmark", denmarkAnalyzer);
- IndexWriter writer = new IndexWriter
- (indexStore, analyzer, true, IndexWriter.MaxFieldLength.LIMITED);
+ IndexWriter writer = new IndexWriter(indexStore, new IndexWriterConfig(
+ TEST_VERSION_CURRENT, analyzer));
// document data:
// the tracer field is used to determine which document was hit
Modified: lucene/java/branches/flex_1458/src/test/org/apache/lucene/document/TestBinaryDocument.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/test/org/apache/lucene/document/TestBinaryDocument.java?rev=924563&r1=924562&r2=924563&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/test/org/apache/lucene/document/TestBinaryDocument.java (original)
+++ lucene/java/branches/flex_1458/src/test/org/apache/lucene/document/TestBinaryDocument.java Thu Mar 18 00:05:22 2010
@@ -5,6 +5,7 @@ import org.apache.lucene.util.LuceneTest
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.store.MockRAMDirectory;
/**
@@ -27,8 +28,7 @@ import org.apache.lucene.store.MockRAMDi
/**
* Tests {@link Document} class.
*/
-public class TestBinaryDocument extends LuceneTestCase
-{
+public class TestBinaryDocument extends LuceneTestCase {
String binaryValStored = "this text will be stored as a byte array in the index";
String binaryValCompressed = "this text will be also stored and compressed as a byte array in the index";
@@ -58,7 +58,8 @@ public class TestBinaryDocument extends
/** add the doc to a ram index */
MockRAMDirectory dir = new MockRAMDirectory();
- IndexWriter writer = new IndexWriter(dir, new StandardAnalyzer(TEST_VERSION_CURRENT), true, IndexWriter.MaxFieldLength.LIMITED);
+ IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(
+ TEST_VERSION_CURRENT, new StandardAnalyzer(TEST_VERSION_CURRENT)));
writer.addDocument(doc);
writer.close();
@@ -83,9 +84,7 @@ public class TestBinaryDocument extends
dir.close();
}
- public void testCompressionTools()
- throws Exception
- {
+ public void testCompressionTools() throws Exception {
Fieldable binaryFldCompressed = new Field("binaryCompressed", CompressionTools.compress(binaryValCompressed.getBytes()));
Fieldable stringFldCompressed = new Field("stringCompressed", CompressionTools.compressString(binaryValCompressed));
@@ -96,7 +95,8 @@ public class TestBinaryDocument extends
/** add the doc to a ram index */
MockRAMDirectory dir = new MockRAMDirectory();
- IndexWriter writer = new IndexWriter(dir, new StandardAnalyzer(TEST_VERSION_CURRENT), true, IndexWriter.MaxFieldLength.LIMITED);
+ IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(
+ TEST_VERSION_CURRENT, new StandardAnalyzer(TEST_VERSION_CURRENT)));
writer.addDocument(doc);
writer.close();
Propchange: lucene/java/branches/flex_1458/src/test/org/apache/lucene/document/TestDateTools.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Mar 18 00:05:22 2010
@@ -1,4 +1,4 @@
/lucene/java/branches/lucene_2_4/src/test/org/apache/lucene/document/TestDateTools.java:748824
/lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/document/TestDateTools.java:829134,829881,831036,896850,909334
/lucene/java/branches/lucene_3_0/src/test/org/apache/lucene/document/TestDateTools.java:880793,896906
-/lucene/java/trunk/src/test/org/apache/lucene/document/TestDateTools.java:824912-825292,826213-833960,880727-886190,889185,889614-916543,916596,916685,916755,916769,917019,917148,917154,917161,917203-917204,919060,919119,919718,919731,919869,920237-920499,922013,922277,922525,922528,922602,922624,922797,922799,922886-922887,923112,924151,924207,924286
+/lucene/java/trunk/src/test/org/apache/lucene/document/TestDateTools.java:824912-825292,826213-833960,880727-886190,889185,889614-916543,916596,916685,916755,916769,917019,917148,917154,917161,917203-917204,919060,919119,919718,919731,919869,920237-920499,922013,922277,922525,922528,922583,922593,922602,922624,922797,922799,922886-922887,923112,924151,924207,924286
Modified: lucene/java/branches/flex_1458/src/test/org/apache/lucene/document/TestDocument.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/test/org/apache/lucene/document/TestDocument.java?rev=924563&r1=924562&r2=924563&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/test/org/apache/lucene/document/TestDocument.java (original)
+++ lucene/java/branches/flex_1458/src/test/org/apache/lucene/document/TestDocument.java Thu Mar 18 00:05:22 2010
@@ -2,6 +2,7 @@ package org.apache.lucene.document;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
@@ -151,10 +152,11 @@ public class TestDocument extends Lucene
*
* @throws Exception on error
*/
- public void testGetValuesForIndexedDocument() throws Exception
- {
+ public void testGetValuesForIndexedDocument() throws Exception {
RAMDirectory dir = new RAMDirectory();
- IndexWriter writer = new IndexWriter(dir, new StandardAnalyzer(TEST_VERSION_CURRENT), true, IndexWriter.MaxFieldLength.LIMITED);
+ IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(
+ TEST_VERSION_CURRENT, new StandardAnalyzer(
+ TEST_VERSION_CURRENT)));
writer.addDocument(makeDocumentWithFields());
writer.close();
@@ -225,7 +227,9 @@ public class TestDocument extends Lucene
doc.add(new Field("keyword", "test", Field.Store.YES, Field.Index.NOT_ANALYZED));
RAMDirectory dir = new RAMDirectory();
- IndexWriter writer = new IndexWriter(dir, new StandardAnalyzer(TEST_VERSION_CURRENT), true, IndexWriter.MaxFieldLength.LIMITED);
+ IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(
+ TEST_VERSION_CURRENT, new StandardAnalyzer(
+ TEST_VERSION_CURRENT)));
writer.addDocument(doc);
field.setValue("id2");
writer.addDocument(doc);
Propchange: lucene/java/branches/flex_1458/src/test/org/apache/lucene/document/TestNumberTools.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Mar 18 00:05:22 2010
@@ -1,4 +1,4 @@
/lucene/java/branches/lucene_2_4/src/test/org/apache/lucene/document/TestNumberTools.java:748824
/lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/document/TestNumberTools.java:829134,829881,831036,896850,909334
/lucene/java/branches/lucene_3_0/src/test/org/apache/lucene/document/TestNumberTools.java:880793,896906
-/lucene/java/trunk/src/test/org/apache/lucene/document/TestNumberTools.java:824912-825292,826213-833960,880727-886190,889185,889614-916543,916596,916685,916755,916769,917019,917148,917154,917161,917203-917204,919060,919119,919718,919731,919869,920237-920499,922013,922277,922525,922528,922602,922624,922797,922799,922886-922887,923112,924151,924207,924286
+/lucene/java/trunk/src/test/org/apache/lucene/document/TestNumberTools.java:824912-825292,826213-833960,880727-886190,889185,889614-916543,916596,916685,916755,916769,917019,917148,917154,917161,917203-917204,919060,919119,919718,919731,919869,920237-920499,922013,922277,922525,922528,922583,922593,922602,922624,922797,922799,922886-922887,923112,924151,924207,924286
Modified: lucene/java/branches/flex_1458/src/test/org/apache/lucene/index/DocHelper.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/test/org/apache/lucene/index/DocHelper.java?rev=924563&r1=924562&r2=924563&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/test/org/apache/lucene/index/DocHelper.java (original)
+++ lucene/java/branches/flex_1458/src/test/org/apache/lucene/index/DocHelper.java Thu Mar 18 00:05:22 2010
@@ -232,10 +232,9 @@ class DocHelper {
* @param doc
* @throws IOException
*/
- public static SegmentInfo writeDoc(Directory dir, Analyzer analyzer, Similarity similarity, Document doc) throws IOException
- {
- IndexWriter writer = new IndexWriter(dir, analyzer, IndexWriter.MaxFieldLength.LIMITED);
- writer.setSimilarity(similarity);
+ public static SegmentInfo writeDoc(Directory dir, Analyzer analyzer, Similarity similarity, Document doc) throws IOException {
+ IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(
+ TEST_VERSION_CURRENT, analyzer).setSimilarity(similarity));
//writer.setUseCompoundFile(false);
writer.addDocument(doc);
writer.commit();
Modified: lucene/java/branches/flex_1458/src/test/org/apache/lucene/index/TestAddIndexesNoOptimize.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/test/org/apache/lucene/index/TestAddIndexesNoOptimize.java?rev=924563&r1=924562&r2=924563&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/test/org/apache/lucene/index/TestAddIndexesNoOptimize.java (original)
+++ lucene/java/branches/flex_1458/src/test/org/apache/lucene/index/TestAddIndexesNoOptimize.java Thu Mar 18 00:05:22 2010
@@ -23,6 +23,7 @@ import org.apache.lucene.util.LuceneTest
import org.apache.lucene.analysis.WhitespaceAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
+import org.apache.lucene.index.IndexWriterConfig.OpenMode;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.store.MockRAMDirectory;
@@ -40,28 +41,31 @@ public class TestAddIndexesNoOptimize ex
IndexWriter writer = null;
- writer = newWriter(dir, true);
+ writer = newWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT,
+ new WhitespaceAnalyzer(TEST_VERSION_CURRENT))
+ .setOpenMode(OpenMode.CREATE));
// add 100 documents
addDocs(writer, 100);
assertEquals(100, writer.maxDoc());
writer.close();
_TestUtil.checkIndex(dir);
- writer = newWriter(aux, true);
- writer.setUseCompoundFile(false); // use one without a compound file
+ writer = newWriter(aux, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.CREATE));
+ ((LogMergePolicy) writer.getMergePolicy()).setUseCompoundFile(false); // use one without a compound file
+ ((LogMergePolicy) writer.getMergePolicy()).setUseCompoundDocStore(false); // use one without a compound file
// add 40 documents in separate files
addDocs(writer, 40);
assertEquals(40, writer.maxDoc());
writer.close();
- writer = newWriter(aux2, true);
+ writer = newWriter(aux2, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.CREATE));
// add 40 documents in compound files
addDocs2(writer, 50);
assertEquals(50, writer.maxDoc());
writer.close();
// test doc count before segments are merged
- writer = newWriter(dir, false);
+ writer = newWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.APPEND));
assertEquals(100, writer.maxDoc());
writer.addIndexesNoOptimize(new Directory[] { aux, aux2 });
assertEquals(190, writer.maxDoc());
@@ -76,14 +80,14 @@ public class TestAddIndexesNoOptimize ex
// now add another set in.
Directory aux3 = new RAMDirectory();
- writer = newWriter(aux3, true);
+ writer = newWriter(aux3, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
// add 40 documents
addDocs(writer, 40);
assertEquals(40, writer.maxDoc());
writer.close();
// test doc count before segments are merged/index is optimized
- writer = newWriter(dir, false);
+ writer = newWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.APPEND));
assertEquals(190, writer.maxDoc());
writer.addIndexesNoOptimize(new Directory[] { aux3 });
assertEquals(230, writer.maxDoc());
@@ -97,7 +101,7 @@ public class TestAddIndexesNoOptimize ex
verifyTermDocs(dir, new Term("content", "bbb"), 50);
// now optimize it.
- writer = newWriter(dir, false);
+ writer = newWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.APPEND));
writer.optimize();
writer.close();
@@ -110,11 +114,11 @@ public class TestAddIndexesNoOptimize ex
// now add a single document
Directory aux4 = new RAMDirectory();
- writer = newWriter(aux4, true);
+ writer = newWriter(aux4, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
addDocs2(writer, 1);
writer.close();
- writer = newWriter(dir, false);
+ writer = newWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.APPEND));
assertEquals(230, writer.maxDoc());
writer.addIndexesNoOptimize(new Directory[] { aux4 });
assertEquals(231, writer.maxDoc());
@@ -132,7 +136,7 @@ public class TestAddIndexesNoOptimize ex
Directory aux = new MockRAMDirectory();
setUpDirs(dir, aux);
- IndexWriter writer = newWriter(dir, false);
+ IndexWriter writer = newWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.APPEND));
writer.addIndexesNoOptimize(new Directory[] {aux});
@@ -170,7 +174,7 @@ public class TestAddIndexesNoOptimize ex
Directory aux = new RAMDirectory();
setUpDirs(dir, aux);
- IndexWriter writer = newWriter(dir, false);
+ IndexWriter writer = newWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.APPEND));
// Adds 10 docs, then replaces them with another 10
// docs, so 10 pending deletes:
@@ -209,7 +213,7 @@ public class TestAddIndexesNoOptimize ex
Directory aux = new RAMDirectory();
setUpDirs(dir, aux);
- IndexWriter writer = newWriter(dir, false);
+ IndexWriter writer = newWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.APPEND));
// Adds 10 docs, then replaces them with another 10
// docs, so 10 pending deletes:
@@ -250,25 +254,25 @@ public class TestAddIndexesNoOptimize ex
IndexWriter writer = null;
- writer = newWriter(dir, true);
+ writer = newWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
// add 100 documents
addDocs(writer, 100);
assertEquals(100, writer.maxDoc());
writer.close();
- writer = newWriter(aux, true);
- writer.setUseCompoundFile(false); // use one without a compound file
- writer.setMaxBufferedDocs(1000);
+ writer = newWriter(aux, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.CREATE).setMaxBufferedDocs(1000));
+ ((LogMergePolicy) writer.getMergePolicy()).setUseCompoundFile(false); // use one without a compound file
+ ((LogMergePolicy) writer.getMergePolicy()).setUseCompoundDocStore(false); // use one without a compound file
// add 140 documents in separate files
addDocs(writer, 40);
writer.close();
- writer = newWriter(aux, true);
- writer.setUseCompoundFile(false); // use one without a compound file
- writer.setMaxBufferedDocs(1000);
+ writer = newWriter(aux, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.CREATE).setMaxBufferedDocs(1000));
+ ((LogMergePolicy) writer.getMergePolicy()).setUseCompoundFile(false); // use one without a compound file
+ ((LogMergePolicy) writer.getMergePolicy()).setUseCompoundDocStore(false); // use one without a compound file
addDocs(writer, 100);
writer.close();
- writer = newWriter(dir, false);
+ writer = newWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.APPEND));
try {
// cannot add self
writer.addIndexesNoOptimize(new Directory[] { aux, dir });
@@ -294,9 +298,10 @@ public class TestAddIndexesNoOptimize ex
setUpDirs(dir, aux);
- IndexWriter writer = newWriter(dir, false);
- writer.setMaxBufferedDocs(10);
- writer.setMergeFactor(4);
+ IndexWriter writer = newWriter(dir, new IndexWriterConfig(
+ TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT))
+ .setOpenMode(OpenMode.APPEND).setMaxBufferedDocs(10));
+ ((LogMergePolicy) writer.getMergePolicy()).setMergeFactor(4);
addDocs(writer, 10);
writer.addIndexesNoOptimize(new Directory[] { aux });
@@ -318,9 +323,8 @@ public class TestAddIndexesNoOptimize ex
setUpDirs(dir, aux);
- IndexWriter writer = newWriter(dir, false);
- writer.setMaxBufferedDocs(9);
- writer.setMergeFactor(4);
+ IndexWriter writer = newWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.APPEND).setMaxBufferedDocs(9));
+ ((LogMergePolicy) writer.getMergePolicy()).setMergeFactor(4);
addDocs(writer, 2);
writer.addIndexesNoOptimize(new Directory[] { aux });
@@ -342,9 +346,10 @@ public class TestAddIndexesNoOptimize ex
setUpDirs(dir, aux);
- IndexWriter writer = newWriter(dir, false);
- writer.setMaxBufferedDocs(10);
- writer.setMergeFactor(4);
+ IndexWriter writer = newWriter(dir, new IndexWriterConfig(
+ TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT))
+ .setOpenMode(OpenMode.APPEND).setMaxBufferedDocs(10));
+ ((LogMergePolicy) writer.getMergePolicy()).setMergeFactor(4);
writer.addIndexesNoOptimize(new Directory[] { aux, new RAMDirectory(aux) });
assertEquals(1060, writer.maxDoc());
@@ -371,9 +376,10 @@ public class TestAddIndexesNoOptimize ex
assertEquals(10, reader.numDocs());
reader.close();
- IndexWriter writer = newWriter(dir, false);
- writer.setMaxBufferedDocs(4);
- writer.setMergeFactor(4);
+ IndexWriter writer = newWriter(dir, new IndexWriterConfig(
+ TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT))
+ .setOpenMode(OpenMode.APPEND).setMaxBufferedDocs(4));
+ ((LogMergePolicy) writer.getMergePolicy()).setMergeFactor(4);
writer.addIndexesNoOptimize(new Directory[] { aux, new RAMDirectory(aux) });
assertEquals(1020, writer.maxDoc());
@@ -394,9 +400,10 @@ public class TestAddIndexesNoOptimize ex
setUpDirs(dir, aux);
- IndexWriter writer = newWriter(aux2, true);
- writer.setMaxBufferedDocs(100);
- writer.setMergeFactor(10);
+ IndexWriter writer = newWriter(aux2, new IndexWriterConfig(
+ TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT))
+ .setOpenMode(OpenMode.CREATE).setMaxBufferedDocs(100));
+ ((LogMergePolicy) writer.getMergePolicy()).setMergeFactor(10);
writer.addIndexesNoOptimize(new Directory[] { aux });
assertEquals(30, writer.maxDoc());
assertEquals(3, writer.getSegmentCount());
@@ -416,9 +423,9 @@ public class TestAddIndexesNoOptimize ex
assertEquals(22, reader.numDocs());
reader.close();
- writer = newWriter(dir, false);
- writer.setMaxBufferedDocs(6);
- writer.setMergeFactor(4);
+ writer = newWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT))
+ .setOpenMode(OpenMode.APPEND).setMaxBufferedDocs(6));
+ ((LogMergePolicy) writer.getMergePolicy()).setMergeFactor(4);
writer.addIndexesNoOptimize(new Directory[] { aux, aux2 });
assertEquals(1025, writer.maxDoc());
@@ -429,9 +436,9 @@ public class TestAddIndexesNoOptimize ex
verifyNumDocs(dir, 1025);
}
- private IndexWriter newWriter(Directory dir, boolean create)
+ private IndexWriter newWriter(Directory dir, IndexWriterConfig conf)
throws IOException {
- final IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(TEST_VERSION_CURRENT), create, IndexWriter.MaxFieldLength.UNLIMITED);
+ final IndexWriter writer = new IndexWriter(dir, conf);
writer.setMergePolicy(new LogDocMergePolicy(writer));
return writer;
}
@@ -475,26 +482,25 @@ public class TestAddIndexesNoOptimize ex
private void setUpDirs(Directory dir, Directory aux) throws IOException {
IndexWriter writer = null;
- writer = newWriter(dir, true);
- writer.setMaxBufferedDocs(1000);
+ writer = newWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.CREATE).setMaxBufferedDocs(1000));
// add 1000 documents in 1 segment
addDocs(writer, 1000);
assertEquals(1000, writer.maxDoc());
assertEquals(1, writer.getSegmentCount());
writer.close();
- writer = newWriter(aux, true);
- writer.setUseCompoundFile(false); // use one without a compound file
- writer.setMaxBufferedDocs(100);
- writer.setMergeFactor(10);
+ writer = newWriter(aux, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.CREATE).setMaxBufferedDocs(100));
+ ((LogMergePolicy) writer.getMergePolicy()).setUseCompoundFile(false); // use one without a compound file
+ ((LogMergePolicy) writer.getMergePolicy()).setUseCompoundDocStore(false); // use one without a compound file
+ ((LogMergePolicy) writer.getMergePolicy()).setMergeFactor(10);
// add 30 documents in 3 segments
for (int i = 0; i < 3; i++) {
addDocs(writer, 10);
writer.close();
- writer = newWriter(aux, false);
- writer.setUseCompoundFile(false); // use one without a compound file
- writer.setMaxBufferedDocs(100);
- writer.setMergeFactor(10);
+ writer = newWriter(aux, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.APPEND).setMaxBufferedDocs(100));
+ ((LogMergePolicy) writer.getMergePolicy()).setUseCompoundFile(false); // use one without a compound file
+ ((LogMergePolicy) writer.getMergePolicy()).setUseCompoundDocStore(false); // use one without a compound file
+ ((LogMergePolicy) writer.getMergePolicy()).setMergeFactor(10);
}
assertEquals(30, writer.maxDoc());
assertEquals(3, writer.getSegmentCount());
@@ -505,18 +511,19 @@ public class TestAddIndexesNoOptimize ex
public void testHangOnClose() throws IOException {
Directory dir = new MockRAMDirectory();
- IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(TEST_VERSION_CURRENT), true, IndexWriter.MaxFieldLength.LIMITED);
- writer.setMergePolicy(new LogByteSizeMergePolicy(writer));
- writer.setMaxBufferedDocs(5);
- writer.setUseCompoundFile(false);
- writer.setMergeFactor(100);
+ IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setMaxBufferedDocs(5));
+ LogByteSizeMergePolicy lmp = new LogByteSizeMergePolicy(writer);
+ lmp.setUseCompoundFile(false);
+ lmp.setUseCompoundDocStore(false);
+ lmp.setMergeFactor(100);
+ writer.setMergePolicy(lmp);
Document doc = new Document();
doc.add(new Field("content", "aaa bbb ccc ddd eee fff ggg hhh iii", Field.Store.YES,
Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
for(int i=0;i<60;i++)
writer.addDocument(doc);
- writer.setMaxBufferedDocs(200);
+
Document doc2 = new Document();
doc2.add(new Field("content", "aaa bbb ccc ddd eee fff ggg hhh iii", Field.Store.YES,
Field.Index.NO));
@@ -531,13 +538,13 @@ public class TestAddIndexesNoOptimize ex
writer.close();
Directory dir2 = new MockRAMDirectory();
- writer = new IndexWriter(dir2, new WhitespaceAnalyzer(TEST_VERSION_CURRENT), true, IndexWriter.MaxFieldLength.LIMITED);
- LogByteSizeMergePolicy lmp = new LogByteSizeMergePolicy(writer);
+ writer = new IndexWriter(dir2, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setMergeScheduler(new SerialMergeScheduler()));
+ lmp = new LogByteSizeMergePolicy(writer);
lmp.setMinMergeMB(0.0001);
+ lmp.setUseCompoundFile(false);
+ lmp.setUseCompoundDocStore(false);
+ lmp.setMergeFactor(4);
writer.setMergePolicy(lmp);
- writer.setMergeFactor(4);
- writer.setUseCompoundFile(false);
- writer.setMergeScheduler(new SerialMergeScheduler());
writer.addIndexesNoOptimize(new Directory[] {dir});
writer.close();
dir.close();
@@ -548,14 +555,16 @@ public class TestAddIndexesNoOptimize ex
// is respected when copying tail segments
public void testTargetCFS() throws IOException {
Directory dir = new RAMDirectory();
- IndexWriter writer = newWriter(dir, true);
- writer.setUseCompoundFile(false);
+ IndexWriter writer = newWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
+ ((LogMergePolicy) writer.getMergePolicy()).setUseCompoundFile(false);
+ ((LogMergePolicy) writer.getMergePolicy()).setUseCompoundDocStore(false);
addDocs(writer, 1);
writer.close();
Directory other = new RAMDirectory();
- writer = newWriter(other, true);
- writer.setUseCompoundFile(true);
+ writer = newWriter(other, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
+ ((LogMergePolicy) writer.getMergePolicy()).setUseCompoundFile(true);
+ ((LogMergePolicy) writer.getMergePolicy()).setUseCompoundDocStore(true);
writer.addIndexesNoOptimize(new Directory[] {dir});
assertTrue(writer.newestSegment().getUseCompoundFile());
writer.close();
Modified: lucene/java/branches/flex_1458/src/test/org/apache/lucene/index/TestAtomicUpdate.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/test/org/apache/lucene/index/TestAtomicUpdate.java?rev=924563&r1=924562&r2=924563&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/test/org/apache/lucene/index/TestAtomicUpdate.java (original)
+++ lucene/java/branches/flex_1458/src/test/org/apache/lucene/index/TestAtomicUpdate.java Thu Mar 18 00:05:22 2010
@@ -19,20 +19,20 @@ package org.apache.lucene.index;
import org.apache.lucene.util.*;
import org.apache.lucene.store.*;
import org.apache.lucene.document.*;
-import org.apache.lucene.analysis.*;
+import org.apache.lucene.analysis.SimpleAnalyzer;
import java.util.Random;
import java.io.File;
import java.io.IOException;
public class TestAtomicUpdate extends LuceneTestCase {
- private static final Analyzer ANALYZER = new SimpleAnalyzer(TEST_VERSION_CURRENT);
- private Random RANDOM;
+
+ private static final class MockIndexWriter extends IndexWriter {
- public class MockIndexWriter extends IndexWriter {
+ static Random RANDOM;
- public MockIndexWriter(Directory dir, Analyzer a, boolean create, IndexWriter.MaxFieldLength mfl) throws IOException {
- super(dir, a, create, mfl);
+ public MockIndexWriter(Directory dir, IndexWriterConfig conf) throws IOException {
+ super(dir, conf);
}
@Override
@@ -126,9 +126,10 @@ public class TestAtomicUpdate extends Lu
TimedThread[] threads = new TimedThread[4];
- IndexWriter writer = new MockIndexWriter(directory, ANALYZER, true, IndexWriter.MaxFieldLength.UNLIMITED);
- writer.setMaxBufferedDocs(4);
- writer.setMergeFactor(2);
+ IndexWriter writer = new MockIndexWriter(directory, new IndexWriterConfig(
+ TEST_VERSION_CURRENT, new SimpleAnalyzer(TEST_VERSION_CURRENT))
+ .setMaxBufferedDocs(4));
+ ((LogMergePolicy) writer.getMergePolicy()).setMergeFactor(2);
// Establish a base index of 100 docs:
for(int i=0;i<100;i++) {
@@ -184,7 +185,7 @@ public class TestAtomicUpdate extends Lu
FSDirectory.
*/
public void testAtomicUpdates() throws Exception {
- RANDOM = newRandom();
+ MockIndexWriter.RANDOM = newRandom();
Directory directory;
// First in a RAM directory: