Package org.apache.lucene.index

# Class IndexWriterConfig

java.lang.Object
org.apache.lucene.index.LiveIndexWriterConfig
org.apache.lucene.index.IndexWriterConfig

public final class IndexWriterConfig extends LiveIndexWriterConfig
Holds all the configuration that is used to create an `IndexWriter`. Once `IndexWriter` has been created with this object, changes to this object will not affect the `IndexWriter` instance. For that, use `LiveIndexWriterConfig` that is returned from `IndexWriter.getConfig()`.

All setter methods return `IndexWriterConfig` to allow chaining settings conveniently, for example:

     IndexWriterConfig conf = new IndexWriterConfig(analyzer);
     conf.setter1().setter2();

Since:
  3.1
See Also:
  - `IndexWriter.getConfig()`

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static enum`
`IndexWriterConfig.OpenMode`
Specifies the open mode for `IndexWriter`.

## Field Summary

Fields
Modifier and Type
Field
Description
`static final boolean`
`DEFAULT_COMMIT_ON_CLOSE`
Default value for whether calls to `IndexWriter.close()` include a commit.
`static final int`
`DEFAULT_MAX_BUFFERED_DELETE_TERMS`
Disabled by default (because IndexWriter flushes by RAM usage by default).
`static final int`
`DEFAULT_MAX_BUFFERED_DOCS`
Disabled by default (because IndexWriter flushes by RAM usage by default).
`static final long`
`DEFAULT_MAX_FULL_FLUSH_MERGE_WAIT_MILLIS`
Default value for time to wait for merges on commit or getReader (when using a `MergePolicy` that implements `MergePolicy.findFullFlushMerges(org.apache.lucene.index.MergeTrigger, org.apache.lucene.index.SegmentInfos, org.apache.lucene.index.MergePolicy.MergeContext)`).
`static final double`
`DEFAULT_RAM_BUFFER_SIZE_MB`
Default value is 16 MB (which means flush when buffered docs consume approximately 16 MB RAM).
`static final int`
`DEFAULT_RAM_PER_THREAD_HARD_LIMIT_MB`
Default value is 1945.
`static final boolean`
`DEFAULT_READER_POOLING`
Default setting (true) for `setReaderPooling(boolean)`.
`static final boolean`
`DEFAULT_USE_COMPOUND_FILE_SYSTEM`
Default value for compound file system for newly written segments (set to `true`).
`static final int`
`DISABLE_AUTO_FLUSH`
Denotes a flush trigger is disabled.

### Fields inherited from class org.apache.lucene.index.LiveIndexWriterConfig

`checkPendingFlushOnUpdate, codec, commit, commitOnClose, createdVersionMajor, delPolicy, eventListener, flushPolicy, indexSort, indexSortFields, infoStream, leafSorter, maxFullFlushMergeWaitMillis, mergePolicy, mergeScheduler, openMode, parentField, perThreadHardLimitMB, readerPooling, similarity, softDeletesField, useCompoundFile`

## Constructor Summary

Constructors
Constructor
Description
`IndexWriterConfig()`
Creates a new config, using `StandardAnalyzer` as the analyzer.
`IndexWriterConfig(Analyzer analyzer)`
Creates a new config that with the provided `Analyzer`.

## Method Summary

Modifier and Type
Method
Description
`Analyzer`
`getAnalyzer()`
Returns the default analyzer to use for indexing documents.
`Codec`
`getCodec()`
Returns the current `Codec`.
`IndexCommit`
`getIndexCommit()`
Returns the `IndexCommit` as specified in `setIndexCommit(IndexCommit)` or the default, `null` which specifies to open the latest index commit point.
`IndexDeletionPolicy`
`getIndexDeletionPolicy()`
Returns the `IndexDeletionPolicy` specified in `setIndexDeletionPolicy(IndexDeletionPolicy)` or the default `KeepOnlyLastCommitDeletionPolicy`/
`InfoStream`
`getInfoStream()`
Returns `InfoStream` used for debugging.
`int`
`getMaxBufferedDocs()`
Returns the number of buffered added documents that will trigger a flush if enabled.
`IndexWriter.IndexReaderWarmer`
`getMergedSegmentWarmer()`
Returns the current merged segment warmer.
`MergePolicy`
`getMergePolicy()`
Returns the current MergePolicy in use by this writer.
`MergeScheduler`
`getMergeScheduler()`
Returns the `MergeScheduler` that was set by `setMergeScheduler(MergeScheduler)`.
`IndexWriterConfig.OpenMode`
`getOpenMode()`
Returns the `IndexWriterConfig.OpenMode` set by `setOpenMode(OpenMode)`.
`double`
`getRAMBufferSizeMB()`
Returns the value set by `LiveIndexWriterConfig.setRAMBufferSizeMB(double)` if enabled.
`int`
`getRAMPerThreadHardLimitMB()`
Returns the max amount of memory each `DocumentsWriterPerThread` can consume until forcefully flushed.
`boolean`
`getReaderPooling()`
Returns `true` if `IndexWriter` should pool readers even if `DirectoryReader.open(IndexWriter)` has not been called.
`Similarity`
`getSimilarity()`
Expert: returns the `Similarity` implementation used by this `IndexWriter`.
`IndexWriterConfig`
`setCheckPendingFlushUpdate(boolean checkPendingFlushOnUpdate)`
Expert: sets if indexing threads check for pending flushes on update in order to help our flushing indexing buffers to disk.
`IndexWriterConfig`
`setCodec(Codec codec)`
Set the `Codec`.
`IndexWriterConfig`
`setCommitOnClose(boolean commitOnClose)`
Sets if calls `IndexWriter.close()` should first commit before closing.
`IndexWriterConfig`
`setIndexCommit(IndexCommit commit)`
Expert: allows to open a certain commit point.
`IndexWriterConfig`
`setIndexCreatedVersionMajor(int indexCreatedVersionMajor)`
Expert: set the compatibility version to use for this index.
`IndexWriterConfig`
`setIndexDeletionPolicy(IndexDeletionPolicy delPolicy)`
Expert: allows an optional `IndexDeletionPolicy` implementation to be specified.
`IndexWriterConfig`
`setIndexSort(Sort sort)`
Set the `Sort` order to use for all (flushed and merged) segments.
`IndexWriterConfig`
`setIndexWriterEventListener(IndexWriterEventListener eventListener)`
Set event listener to record key events in IndexWriter
`IndexWriterConfig`
`setInfoStream(PrintStream printStream)`
Convenience method that uses `PrintStreamInfoStream`.
`IndexWriterConfig`
`setInfoStream(InfoStream infoStream)`
Information about merges, deletes and a message when maxFieldLength is reached will be printed to this.
`IndexWriterConfig`
`setLeafSorter(Comparator<LeafReader> leafSorter)`
Set the comparator for sorting leaf readers.
`IndexWriterConfig`
`setMaxBufferedDocs(int maxBufferedDocs)`
Determines the minimal number of documents required before the buffered in-memory documents are flushed as a new Segment.
`IndexWriterConfig`
`setMaxFullFlushMergeWaitMillis(long maxFullFlushMergeWaitMillis)`
Expert: sets the amount of time to wait for merges (during `IndexWriter.commit()` or `IndexWriter.getReader(boolean, boolean)`) returned by MergePolicy.findFullFlushMerges(...).
`IndexWriterConfig`
`setMergedSegmentWarmer(IndexWriter.IndexReaderWarmer mergeSegmentWarmer)`
Set the merged segment warmer.
`IndexWriterConfig`
`setMergePolicy(MergePolicy mergePolicy)`
Expert: `MergePolicy` is invoked whenever there are changes to the segments in the index.
`IndexWriterConfig`
`setMergeScheduler(MergeScheduler mergeScheduler)`
Expert: sets the merge scheduler used by this writer.
`IndexWriterConfig`
`setOpenMode(IndexWriterConfig.OpenMode openMode)`
Specifies `IndexWriterConfig.OpenMode` of the index.
`IndexWriterConfig`
`setParentField(String parentField)`
Sets the parent document field.
`IndexWriterConfig`
`setRAMBufferSizeMB(double ramBufferSizeMB)`
Determines the amount of RAM that may be used for buffering added documents and deletions before they are flushed to the Directory.
`IndexWriterConfig`
`setRAMPerThreadHardLimitMB(int perThreadHardLimitMB)`
Expert: Sets the maximum memory consumption per thread triggering a forced flush if exceeded.
`IndexWriterConfig`
`setReaderPooling(boolean readerPooling)`
By default, IndexWriter does not pool the SegmentReaders it must open for deletions and merging, unless a near-real-time reader has been obtained by calling `DirectoryReader.open(IndexWriter)`.
`IndexWriterConfig`
`setSimilarity(Similarity similarity)`
Expert: set the `Similarity` implementation used by this IndexWriter.
`IndexWriterConfig`
`setSoftDeletesField(String softDeletesField)`
Sets the soft deletes field.
`IndexWriterConfig`
`setUseCompoundFile(boolean useCompoundFile)`
Sets if the `IndexWriter` should pack newly written segments in a compound file.
`String`
`toString()`

### Methods inherited from class org.apache.lucene.index.LiveIndexWriterConfig

`getCommitOnClose, getIndexCreatedVersionMajor, getIndexSort, getIndexSortFields, getIndexWriterEventListener, getLeafSorter, getMaxFullFlushMergeWaitMillis, getParentField, getSoftDeletesField, getUseCompoundFile, isCheckPendingFlushOnUpdate`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Field Details

### DISABLE_AUTO_FLUSH

public static final int DISABLE_AUTO_FLUSH
Denotes a flush trigger is disabled.

See Also:
  - Constant Field Values

### DEFAULT_MAX_BUFFERED_DELETE_TERMS

public static final int DEFAULT_MAX_BUFFERED_DELETE_TERMS
Disabled by default (because IndexWriter flushes by RAM usage by default).

See Also:
  - Constant Field Values

### DEFAULT_MAX_BUFFERED_DOCS

public static final int DEFAULT_MAX_BUFFERED_DOCS
Disabled by default (because IndexWriter flushes by RAM usage by default).

See Also:
  - Constant Field Values

### DEFAULT_RAM_BUFFER_SIZE_MB

public static final double DEFAULT_RAM_BUFFER_SIZE_MB
Default value is 16 MB (which means flush when buffered docs consume approximately 16 MB RAM).

See Also:
  - Constant Field Values

### DEFAULT_READER_POOLING

public static final boolean DEFAULT_READER_POOLING
Default setting (true) for `setReaderPooling(boolean)`.

See Also:
  - Constant Field Values

### DEFAULT_RAM_PER_THREAD_HARD_LIMIT_MB

public static final int DEFAULT_RAM_PER_THREAD_HARD_LIMIT_MB
Default value is 1945. Change using `setRAMPerThreadHardLimitMB(int)`

See Also:
  - Constant Field Values

### DEFAULT_USE_COMPOUND_FILE_SYSTEM

public static final boolean DEFAULT_USE_COMPOUND_FILE_SYSTEM
Default value for compound file system for newly written segments (set to `true`). For batch indexing with very large ram buffers use `false`

See Also:
  - Constant Field Values

### DEFAULT_COMMIT_ON_CLOSE

public static final boolean DEFAULT_COMMIT_ON_CLOSE
Default value for whether calls to `IndexWriter.close()` include a commit.

See Also:
  - Constant Field Values

### DEFAULT_MAX_FULL_FLUSH_MERGE_WAIT_MILLIS

public static final long DEFAULT_MAX_FULL_FLUSH_MERGE_WAIT_MILLIS
Default value for time to wait for merges on commit or getReader (when using a `MergePolicy` that implements `MergePolicy.findFullFlushMerges(org.apache.lucene.index.MergeTrigger, org.apache.lucene.index.SegmentInfos, org.apache.lucene.index.MergePolicy.MergeContext)`).

See Also:
  - Constant Field Values

## Constructor Details

### IndexWriterConfig

public IndexWriterConfig()
Creates a new config, using `StandardAnalyzer` as the analyzer. By default, `TieredMergePolicy` is used for merging; Note that `TieredMergePolicy` is free to select non-contiguous merges, which means docIDs may not remain monotonic over time. If this is a problem you should switch to `LogByteSizeMergePolicy` or `LogDocMergePolicy`.

### IndexWriterConfig

public IndexWriterConfig(Analyzer analyzer)
Creates a new config that with the provided `Analyzer`. By default, `TieredMergePolicy` is used for merging; Note that `TieredMergePolicy` is free to select non-contiguous merges, which means docIDs may not remain monotonic over time. If this is a problem you should switch to `LogByteSizeMergePolicy` or `LogDocMergePolicy`.

## Method Details

### setOpenMode

public IndexWriterConfig setOpenMode(IndexWriterConfig.OpenMode openMode)
Specifies `IndexWriterConfig.OpenMode` of the index.

Only takes effect when IndexWriter is first created.

### getOpenMode

public IndexWriterConfig.OpenMode getOpenMode()
Description copied from class: `LiveIndexWriterConfig`
Returns the `IndexWriterConfig.OpenMode` set by `setOpenMode(OpenMode)`.

Overrides:
  `getOpenMode` in class `LiveIndexWriterConfig`

### setIndexCreatedVersionMajor

public IndexWriterConfig setIndexCreatedVersionMajor(int indexCreatedVersionMajor)
Expert: set the compatibility version to use for this index. In case the index is created, it will use the given major version for compatibility. It is sometimes useful to set the previous major version for compatibility due to the fact that `IndexWriter.addIndexes(org.apache.lucene.store.Directory...)` only accepts indices that have been written with the same major version as the current index. If the index already exists, then this value is ignored. Default value is the `major` of the `latest version`.

NOTE: Changing the creation version reduces backward compatibility guarantees. For instance an index created with Lucene 8 with a compatibility version of 7 can't be read with Lucene 9 due to the fact that Lucene only supports reading indices created with the current or previous major release.

Parameters:
  `indexCreatedVersionMajor` - the major version to use for compatibility

### setIndexDeletionPolicy

public IndexWriterConfig setIndexDeletionPolicy(IndexDeletionPolicy delPolicy)
Expert: allows an optional `IndexDeletionPolicy` implementation to be specified. You can use this to control when prior commits are deleted from the index. The default policy is `KeepOnlyLastCommitDeletionPolicy` which removes all prior commits as soon as a new commit is done (this matches behavior before 2.2). Creating your own policy can allow you to explicitly keep previous "point in time" commits alive in the index for some time, to allow readers to refresh to the new commit without having the old commit deleted out from under them. This is necessary on filesystems like NFS that do not support "delete on last close" semantics, which Lucene's "point in time" search normally relies on.

NOTE: the deletion policy must not be null.

Only takes effect when IndexWriter is first created.

### getIndexDeletionPolicy

public IndexDeletionPolicy getIndexDeletionPolicy()
Description copied from class: `LiveIndexWriterConfig`
Returns the `IndexDeletionPolicy` specified in `setIndexDeletionPolicy(IndexDeletionPolicy)` or the default `KeepOnlyLastCommitDeletionPolicy`/

Overrides:
  `getIndexDeletionPolicy` in class `LiveIndexWriterConfig`

### setIndexCommit

public IndexWriterConfig setIndexCommit(IndexCommit commit)
Expert: allows to open a certain commit point. The default is null which opens the latest commit point. This can also be used to open `IndexWriter` from a near-real-time reader, if you pass the reader's `DirectoryReader.getIndexCommit()`.

Only takes effect when IndexWriter is first created.

### getIndexCommit

public IndexCommit getIndexCommit()
Description copied from class: `LiveIndexWriterConfig`
Returns the `IndexCommit` as specified in `setIndexCommit(IndexCommit)` or the default, `null` which specifies to open the latest index commit point.

Overrides:
  `getIndexCommit` in class `LiveIndexWriterConfig`

### setSimilarity

public IndexWriterConfig setSimilarity(Similarity similarity)
Expert: set the `Similarity` implementation used by this IndexWriter.

NOTE: the similarity must not be null.

Only takes effect when IndexWriter is first created.

### getSimilarity

public Similarity getSimilarity()
Description copied from class: `LiveIndexWriterConfig`
Expert: returns the `Similarity` implementation used by this `IndexWriter`.

Overrides:
  `getSimilarity` in class `LiveIndexWriterConfig`

### setMergeScheduler

public IndexWriterConfig setMergeScheduler(MergeScheduler mergeScheduler)
Expert: sets the merge scheduler used by this writer. The default is `ConcurrentMergeScheduler`.

NOTE: the merge scheduler must not be null.

Only takes effect when IndexWriter is first created.

### getMergeScheduler

public MergeScheduler getMergeScheduler()
Description copied from class: `LiveIndexWriterConfig`
Returns the `MergeScheduler` that was set by `setMergeScheduler(MergeScheduler)`.

Overrides:
  `getMergeScheduler` in class `LiveIndexWriterConfig`

### setCodec

public IndexWriterConfig setCodec(Codec codec)
Set the `Codec`.

Only takes effect when IndexWriter is first created.

### getCodec

public Codec getCodec()
Description copied from class: `LiveIndexWriterConfig`
Returns the current `Codec`.

Overrides:
  `getCodec` in class `LiveIndexWriterConfig`

### getMergePolicy

public MergePolicy getMergePolicy()
Description copied from class: `LiveIndexWriterConfig`
Returns the current MergePolicy in use by this writer.

Overrides:
  `getMergePolicy` in class `LiveIndexWriterConfig`
See Also:
  - `setMergePolicy(MergePolicy)`

### setReaderPooling

public IndexWriterConfig setReaderPooling(boolean readerPooling)
By default, IndexWriter does not pool the SegmentReaders it must open for deletions and merging, unless a near-real-time reader has been obtained by calling `DirectoryReader.open(IndexWriter)`. This method lets you enable pooling without getting a near-real-time reader. NOTE: if you set this to false, IndexWriter will still pool readers once `DirectoryReader.open(IndexWriter)` is called.

Only takes effect when IndexWriter is first created.

### getReaderPooling

public boolean getReaderPooling()
Description copied from class: `LiveIndexWriterConfig`
Returns `true` if `IndexWriter` should pool readers even if `DirectoryReader.open(IndexWriter)` has not been called.

Overrides:
  `getReaderPooling` in class `LiveIndexWriterConfig`

### setRAMPerThreadHardLimitMB

public IndexWriterConfig setRAMPerThreadHardLimitMB(int perThreadHardLimitMB)
Expert: Sets the maximum memory consumption per thread triggering a forced flush if exceeded. A `DocumentsWriterPerThread` is forcefully flushed once it exceeds this limit even if the `getRAMBufferSizeMB()` has not been exceeded. This is a safety limit to prevent a `DocumentsWriterPerThread` from address space exhaustion due to its internal 32 bit signed integer based memory addressing. The given value must be less that 2GB (2048MB)

See Also:
  - `DEFAULT_RAM_PER_THREAD_HARD_LIMIT_MB`

### getRAMPerThreadHardLimitMB

public int getRAMPerThreadHardLimitMB()
Description copied from class: `LiveIndexWriterConfig`
Returns the max amount of memory each `DocumentsWriterPerThread` can consume until forcefully flushed.

Overrides:
  `getRAMPerThreadHardLimitMB` in class `LiveIndexWriterConfig`
See Also:
  - `setRAMPerThreadHardLimitMB(int)`

### getInfoStream

public InfoStream getInfoStream()
Description copied from class: `LiveIndexWriterConfig`
Returns `InfoStream` used for debugging.

Overrides:
  `getInfoStream` in class `LiveIndexWriterConfig`
See Also:
  - `setInfoStream(InfoStream)`

### getAnalyzer

public Analyzer getAnalyzer()
Description copied from class: `LiveIndexWriterConfig`
Returns the default analyzer to use for indexing documents.

Overrides:
  `getAnalyzer` in class `LiveIndexWriterConfig`

### getMaxBufferedDocs

public int getMaxBufferedDocs()
Description copied from class: `LiveIndexWriterConfig`
Returns the number of buffered added documents that will trigger a flush if enabled.

Overrides:
  `getMaxBufferedDocs` in class `LiveIndexWriterConfig`
See Also:
  - `LiveIndexWriterConfig.setMaxBufferedDocs(int)`

### getMergedSegmentWarmer

public IndexWriter.IndexReaderWarmer getMergedSegmentWarmer()
Description copied from class: `LiveIndexWriterConfig`
Returns the current merged segment warmer. See `IndexWriter.IndexReaderWarmer`.

Overrides:
  `getMergedSegmentWarmer` in class `LiveIndexWriterConfig`

### getRAMBufferSizeMB

public double getRAMBufferSizeMB()
Description copied from class: `LiveIndexWriterConfig`
Returns the value set by `LiveIndexWriterConfig.setRAMBufferSizeMB(double)` if enabled.

Overrides:
  `getRAMBufferSizeMB` in class `LiveIndexWriterConfig`

### setInfoStream

public IndexWriterConfig setInfoStream(InfoStream infoStream)
Information about merges, deletes and a message when maxFieldLength is reached will be printed to this. Must not be null, but `InfoStream.NO_OUTPUT` may be used to suppress output.

### setInfoStream

public IndexWriterConfig setInfoStream(PrintStream printStream)
Convenience method that uses `PrintStreamInfoStream`. Must not be null.

### setMergePolicy

public IndexWriterConfig setMergePolicy(MergePolicy mergePolicy)
Description copied from class: `LiveIndexWriterConfig`
Expert: `MergePolicy` is invoked whenever there are changes to the segments in the index. Its role is to select which merges to do, if any, and return a `MergePolicy.MergeSpecification` describing the merges. It also selects merges to do for forceMerge.

Takes effect on subsequent merge selections. Any merges in flight or any merges already registered by the previous `MergePolicy` are not affected.

Overrides:
  `setMergePolicy` in class `LiveIndexWriterConfig`

### setMaxBufferedDocs

public IndexWriterConfig setMaxBufferedDocs(int maxBufferedDocs)
Description copied from class: `LiveIndexWriterConfig`
Determines the minimal number of documents required before the buffered in-memory documents are flushed as a new Segment. Large values generally give faster indexing.

When this is set, the writer will flush every maxBufferedDocs added documents. Pass in `DISABLE_AUTO_FLUSH` to prevent triggering a flush due to number of buffered documents. Note that if flushing by RAM usage is also enabled, then the flush will be triggered by whichever comes first.

Disabled by default (writer flushes by RAM usage).

Takes effect immediately, but only the next time a document is added, updated or deleted.

Overrides:
  `setMaxBufferedDocs` in class `LiveIndexWriterConfig`
See Also:
  - `LiveIndexWriterConfig.setRAMBufferSizeMB(double)`

### setMergedSegmentWarmer

public IndexWriterConfig setMergedSegmentWarmer(IndexWriter.IndexReaderWarmer mergeSegmentWarmer)
Description copied from class: `LiveIndexWriterConfig`
Set the merged segment warmer. See `IndexWriter.IndexReaderWarmer`.

Takes effect on the next merge.

Overrides:
  `setMergedSegmentWarmer` in class `LiveIndexWriterConfig`

### setRAMBufferSizeMB

public IndexWriterConfig setRAMBufferSizeMB(double ramBufferSizeMB)
Description copied from class: `LiveIndexWriterConfig`
Determines the amount of RAM that may be used for buffering added documents and deletions before they are flushed to the Directory. Generally for faster indexing performance it's best to flush by RAM usage instead of document count and use as large a RAM buffer as you can.

When this is set, the writer will flush whenever buffered documents and deletions use this much RAM. Pass in `DISABLE_AUTO_FLUSH` to prevent triggering a flush due to RAM usage. Note that if flushing by document count is also enabled, then the flush will be triggered by whichever comes first.

The maximum RAM limit is inherently determined by the JVMs available memory. Yet, an `IndexWriter` session can consume a significantly larger amount of memory than the given RAM limit since this limit is just an indicator when to flush memory resident documents to the Directory. Flushes are likely happen concurrently while other threads adding documents to the writer. For application stability the available memory in the JVM should be significantly larger than the RAM buffer used for indexing.

NOTE: the account of RAM usage for pending deletions is only approximate. Specifically, if you delete by Query, Lucene currently has no way to measure the RAM usage of individual Queries so the accounting will under-estimate and you should compensate by either calling commit() or refresh() periodically yourself.

NOTE: It's not guaranteed that all memory resident documents are flushed once this limit is exceeded. Depending on the configured `FlushPolicy` only a subset of the buffered documents are flushed and therefore only parts of the RAM buffer is released.

The default value is `DEFAULT_RAM_BUFFER_SIZE_MB`.

Takes effect immediately, but only the next time a document is added, updated or deleted.

Overrides:
  `setRAMBufferSizeMB` in class `LiveIndexWriterConfig`
See Also:
  - `setRAMPerThreadHardLimitMB(int)`

### setUseCompoundFile

public IndexWriterConfig setUseCompoundFile(boolean useCompoundFile)
Description copied from class: `LiveIndexWriterConfig`
Sets if the `IndexWriter` should pack newly written segments in a compound file. Default is `true`.

Use `false` for batch indexing with very large ram buffer settings.

Note: To control compound file usage during segment merges see `MergePolicy.setNoCFSRatio(double)` and `MergePolicy.setMaxCFSSegmentSizeMB(double)`. This setting only applies to newly created segments.

Overrides:
  `setUseCompoundFile` in class `LiveIndexWriterConfig`

### setCommitOnClose

public IndexWriterConfig setCommitOnClose(boolean commitOnClose)
Sets if calls `IndexWriter.close()` should first commit before closing. Use `true` to match behavior of Lucene 4.x.

### setMaxFullFlushMergeWaitMillis

public IndexWriterConfig setMaxFullFlushMergeWaitMillis(long maxFullFlushMergeWaitMillis)
Expert: sets the amount of time to wait for merges (during `IndexWriter.commit()` or `IndexWriter.getReader(boolean, boolean)`) returned by MergePolicy.findFullFlushMerges(...). If this time is reached, we proceed with the commit based on segments merged up to that point. The merges are not aborted, and will still run to completion independent of the commit or getReader call, like natural segment merges. The default is `500L`.

Note: Which segments would get merged depends on the implementation of `MergePolicy.findFullFlushMerges(MergeTrigger, SegmentInfos, MergePolicy.MergeContext)`

Note: Set to 0 to disable merging on full flush.

Note: If `SerialMergeScheduler` is used and a non-zero timout is configured, full-flush merges will always wait for the merge to finish without honoring the configured timeout.

### setIndexSort

public IndexWriterConfig setIndexSort(Sort sort)
Set the `Sort` order to use for all (flushed and merged) segments.

### setLeafSorter

public IndexWriterConfig setLeafSorter(Comparator<LeafReader> leafSorter)
Set the comparator for sorting leaf readers. A DirectoryReader opened from a IndexWriter with this configuration will have its leaf readers sorted with the provided leaf sorter.

Parameters:
  `leafSorter` - – a comparator for sorting leaf readers
Returns:
  IndexWriterConfig with leafSorter set.

### toString

public String toString()

Overrides:
  `toString` in class `LiveIndexWriterConfig`

### setCheckPendingFlushUpdate

public IndexWriterConfig setCheckPendingFlushUpdate(boolean checkPendingFlushOnUpdate)
Description copied from class: `LiveIndexWriterConfig`
Expert: sets if indexing threads check for pending flushes on update in order to help our flushing indexing buffers to disk. As a consequence, threads calling `DirectoryReader.openIfChanged(DirectoryReader, IndexWriter)` or `IndexWriter.flush()` will be the only thread writing segments to disk unless flushes are falling behind. If indexing is stalled due to too many pending flushes indexing threads will help our writing pending segment flushes to disk.

Overrides:
  `setCheckPendingFlushUpdate` in class `LiveIndexWriterConfig`

### setSoftDeletesField

public IndexWriterConfig setSoftDeletesField(String softDeletesField)
Sets the soft deletes field. A soft delete field in lucene is a doc-values field that marks a document as soft-deleted if a document has at least one value in that field. If a document is marked as soft-deleted the document is treated as if it has been hard-deleted through the IndexWriter API (`IndexWriter.deleteDocuments(Term...)`. Merges will reclaim soft-deleted as well as hard-deleted documents and index readers obtained from the IndexWriter will reflect all deleted documents in it's live docs. If soft-deletes are used documents must be indexed via `IndexWriter.softUpdateDocument(Term, Iterable, Field...)`. Deletes are applied via `IndexWriter.updateDocValues(Term, Field...)`.

Soft deletes allow to retain documents across merges if the merge policy modifies the live docs of a merge reader. `SoftDeletesRetentionMergePolicy` for instance allows to specify an arbitrary query to mark all documents that should survive the merge. This can be used to for example keep all document modifications for a certain time interval or the last N operations if some kind of sequence ID is available in the index.

Currently there is no API support to un-delete a soft-deleted document. In oder to un-delete the document must be re-indexed using `IndexWriter.softUpdateDocument(Term, Iterable, Field...)`.

The default value for this is `null` which disables soft-deletes. If soft-deletes are enabled documents can still be hard-deleted. Hard-deleted documents will won't considered as soft-deleted even if they have a value in the soft-deletes field.

See Also:
  - `LiveIndexWriterConfig.getSoftDeletesField()`

### setIndexWriterEventListener

public IndexWriterConfig setIndexWriterEventListener(IndexWriterEventListener eventListener)
Set event listener to record key events in IndexWriter

### setParentField

public IndexWriterConfig setParentField(String parentField)
Sets the parent document field. If this optional property is set, IndexWriter will add an internal field to every root document added to the index writer. A document is considered a parent document if it's the last document in a document block indexed via `IndexWriter.addDocuments(Iterable)` or `IndexWriter.updateDocuments(Term, Iterable)` and its relatives. Additionally, all individual documents added via the single document methods (`IndexWriter.addDocuments(Iterable)` etc.) are also considered parent documents. This property is optional for all indices that don't use document blocks in combination with index sorting. In order to maintain the API guarantee that the document order of a block is not altered by the `IndexWriter` a marker for parent documents is required.