Lucene4.3进阶开发之漫漫修行( 四)
转载请务必注明,原创地址,谢谢配合!
http://qindongliang1922.iteye.com/blog/1997577
散仙,在上篇文章中分析了IndexReader家族的两个重要模块分别是它的两个重要的子类,一种是基于原子的Reader可以直接获取索引存储的具体信息,另外一种复合Reader,用于宏观层面上接入索引的重要辅助类,两者相辅相成,缺一不可。
那么本篇,散仙简要分析下IndexWriterConfig这个类的作用,IndexWriterConfig这个类并不是一个顶级基类,在它的上面还有一个父类LiveIndexWriterConfig,我们先来分析下这个父类的一些作用,LiveIndexWriterConfig这个类是4.0以后新扩展的父类,在4.0之前并没有这个类,那么引入这个类的作用是什么呢?
这个先不着急,我们先来看下LiveIndexWriterConfig里面的部分源码:
private final Analyzer analyzer; private volatile int maxBufferedDocs; private volatile double ramBufferSizeMB; private volatile int maxBufferedDeleteTerms; private volatile int readerTermsIndexDivisor; private volatile IndexReaderWarmer mergedSegmentWarmer; private volatile int termIndexInterval; // TODO: this should be private to the codec, not settable here // modified by IndexWriterConfig /** {@link IndexDeletionPolicy} controlling when commit * points are deleted. */ protected volatile IndexDeletionPolicy delPolicy; /** {@link IndexCommit} that {@link IndexWriter} is * opened on. */ protected volatile IndexCommit commit; /** {@link OpenMode} that {@link IndexWriter} is opened * with. */ protected volatile OpenMode openMode; /** {@link Similarity} to use when encoding norms. */ protected volatile Similarity similarity; /** {@link MergeScheduler} to use for running merges. */ protected volatile MergeScheduler mergeScheduler; /** Timeout when trying to obtain the write lock on init. */ protected volatile long writeLockTimeout; /** {@link IndexingChain} that determines how documents are * indexed. */ protected volatile IndexingChain indexingChain; /** {@link Codec} used to write new segments. */ protected volatile Codec codec; /** {@link InfoStream} for debugging messages. */ protected volatile InfoStream infoStream; /** {@link MergePolicy} for selecting merges. */ protected volatile MergePolicy mergePolicy; /** {@code DocumentsWriterPerThreadPool} to control how * threads are allocated to {@code DocumentsWriterPerThread}. */ protected volatile DocumentsWriterPerThreadPool indexerThreadPool; /** True if readers should be pooled. */ protected volatile boolean readerPooling; /** {@link FlushPolicy} to control when segments are * flushed. */ protected volatile FlushPolicy flushPolicy; /** Sets the hard upper bound on RAM usage for a single * segment, after which the segment is forced to flush. */ protected volatile int perThreadHardLimitMB; /** {@link Version} that {@link IndexWriter} should emulate. */ protected final Version matchVersion; /** True if segment flushes should use compound file format */ protected volatile boolean useCompoundFile = IndexWriterConfig.DEFAULT_USE_COMPOUND_FILE_SYSTEM;