github.com/balzaczyy/golucene@v0.0.0-20151210033525-d0be9ee89713/core/index/config.go (about) 1 package index 2 3 import ( 4 "github.com/balzaczyy/golucene/core/analysis" 5 "github.com/balzaczyy/golucene/core/util" 6 ) 7 8 // index/IndexWriterConfig.java 9 10 // Specifies the open mode for IndeWriter 11 type OpenMode int 12 13 const ( 14 // Creates a new index or overwrites an existing one. 15 OPEN_MODE_CREATE = OpenMode(1) 16 // Opens an existing index. 17 OPEN_MODE_APPEND = OpenMode(2) 18 // Creates a new index if one does not exist, 19 // otherwise it opens the index and documents will be appended. 20 OPEN_MODE_CREATE_OR_APPEND = OpenMode(3) 21 ) 22 23 // Default value is 32. 24 const DEFAULT_TERM_INDEX_INTERVAL = 32 // TODO: this should be private to the codec, not settable here 25 26 // Denotes a flush trigger is disabled. 27 const DISABLE_AUTO_FLUSH = -1 28 29 // Disabled by default (because IndexWriter flushes by RAM usage by default). 30 const DEFAULT_MAX_BUFFERED_DELETE_TERMS = DISABLE_AUTO_FLUSH 31 32 // Disabled by default (because IndexWriter flushes by RAM usage by default). 33 const DEFAULT_MAX_BUFFERED_DOCS = DISABLE_AUTO_FLUSH 34 35 // Default value is 16 MB (which means flush when buffered docs 36 // consume approximately 16 MB RAM) 37 const DEFAULT_RAM_BUFFER_SIZE_MB = 16 38 39 // Default value for the write lock timeout (1,000 ms) 40 const WRITE_LOCK_TIMEOUT = 1000 41 42 const DEFAULT_READER_POOLING = false 43 44 // Default value is 1. 45 const DEFAULT_READER_TERMS_INDEX_DIVISOR = DEFAULT_TERMS_INDEX_DIVISOR 46 47 // Default value is 1945. 48 const DEFAULT_RAM_PER_THREAD_HARD_LIMIT_MB = 1945 49 50 // The maximum number of simultaneous threads that may be indexing 51 // documents at once in IndexWriter; if more than this many threads 52 // arrive they will wait for others to finish. Default value is 8. 53 const DEFAULT_MAX_THREAD_STATES = 8 54 55 // Default value for compound file system for newly written segments 56 // (set to true). For batch indexing with very large ram buffers use 57 // false. 58 const DEFAULT_USE_COMPOUND_FILE_SYSTEM = true 59 60 /* 61 Default value for calling checkIntegrity() before merging segments 62 (set to false). You can set this to true for additional safety. 63 */ 64 const DEFAULT_CHECK_INTEGRITY_AT_MERGE = false 65 66 /* 67 Holds all the configuration that is used to create an IndexWriter. Once 68 IndexWriter has been created with this object, changes to this object will not 69 affect the IndexWriter instance. For that, use LiveIndexWriterConfig that is 70 returned from IndexWriter.Config(). 71 72 All setter methods return IndexWriterConfig to allow chaining settings 73 conveniently, for example: 74 75 conf := NewIndexWriterConfig(analyzer) 76 .setter1() 77 .setter2() 78 */ 79 type IndexWriterConfig struct { 80 *LiveIndexWriterConfigImpl 81 writer *util.SetOnce 82 } 83 84 // Sets the IndexWriter this config is attached to. 85 func (conf *IndexWriterConfig) setIndexWriter(writer *IndexWriter) *IndexWriterConfig { 86 conf.writer.Set(writer) 87 return conf 88 } 89 90 // L523 91 /* 92 Information about merges, deletes and a message when maxFieldLength 93 is reached will be printed to this. Must not be nil, but NO_OUTPUT 94 may be used to surpress output. 95 */ 96 func (conf *IndexWriterConfig) SetInfoStream(infoStream util.InfoStream) *IndexWriterConfig { 97 assert2(infoStream != nil, "Cannot set InfoStream implementation to null. "+ 98 "To disable logging use InfoStream.NO_OUTPUT") 99 conf.infoStream = infoStream 100 return conf 101 } 102 103 /* 104 Creates a new config that with defaults that match the specified 105 Version as well as the default Analyzer. If matchVersion is >= 3.2, 106 TieredMergePolicy is used for merging; else LogByteSizeMergePolicy. 107 Note that TieredMergePolicy is free to select non-contiguous merges, 108 which means docIDs may not remain monotonic over time. If this is a 109 problem, you should switch to LogByteSizeMergePolicy or 110 LogDocMergePolicy. 111 */ 112 func NewIndexWriterConfig(matchVersion util.Version, analyzer analysis.Analyzer) *IndexWriterConfig { 113 return &IndexWriterConfig{ 114 LiveIndexWriterConfigImpl: newLiveIndexWriterConfig(analyzer, matchVersion), 115 writer: util.NewSetOnce(), 116 } 117 } 118 119 /* 120 Expert: allows an optional IndexDeletionPolicy implementation to be 121 specified. You can use this to control when prior commits are deleted 122 from the index. The default policy is 123 KeepOnlyLastCommitDeletionPolicy which removes all prior commits as 124 soon as a new commit is done (this matches behavior before 2.2). 125 Creating your own policy can allow you to explicitly keep previous 126 "point in time" commits alive in the index for some time, to allow 127 readers to refresh to the new commit without having the old commit 128 deleted out from under them. This is necessary on filesystems like 129 NFS that do not support "delete on last close" semantics, which 130 Lucene's "point in time" search normally relies on. 131 132 NOTE: the deletion policy can not be nil 133 */ 134 func (conf *IndexWriterConfig) SetIndexDeletionPolicy(delPolicy IndexDeletionPolicy) *IndexWriterConfig { 135 if delPolicy == nil { 136 panic("indexDeletionPolicy must not be nil") 137 } 138 conf.delPolicy = delPolicy 139 return conf 140 } 141 142 type Similarity interface { 143 ComputeNorm(fs *FieldInvertState) int64 144 } 145 146 // L259 147 /* 148 Expert: set the Similarity implementation used by this IndexWriter. 149 150 NOTE: the similarity cannot be nil. 151 152 Only takes effect when IndexWriter is first created. 153 */ 154 func (conf *IndexWriterConfig) SetSimilarity(similarity Similarity) *IndexWriterConfig { 155 assert2(similarity != nil, "similarity must not be nil") 156 conf.similarity = similarity 157 return conf 158 } 159 160 /* 161 Expert: sets the merge scheduler used by this writer. The default is 162 ConcurentMergeScheduler. 163 164 NOTE: the merge scheduler cannot be nil. 165 166 Only takes effect when IndexWriter is first created. 167 */ 168 func (conf *IndexWriterConfig) SetMergeScheduler(mergeScheduler MergeScheduler) *IndexWriterConfig { 169 assert2(mergeScheduler != nil, "mergeScheduler must not be nil") 170 conf.mergeScheduler = mergeScheduler 171 return conf 172 } 173 174 // L310 175 func (conf *IndexWriterConfig) MergePolicy() MergePolicy { 176 return conf.mergePolicy 177 } 178 179 // L406 180 /* 181 By default, IndexWriter does not pool the SegmentReaders it must open 182 for deletions and merging, unless a near-real-time reader has been 183 obtained by calling openDirectoryReader(IndexWriter, bool). This 184 method lets you enable pooling without getting a near-real-time 185 reader. NOTE: if you set this to false, IndexWriter will still pool 186 readers once openDirectoryReader(IndexWriter, bool) is called. 187 */ 188 func (conf *IndexWriterConfig) SetReaderPooling(readerPooling bool) *IndexWriterConfig { 189 conf.readerPooling = readerPooling 190 return conf 191 } 192 193 // L478 194 func (conf *IndexWriterConfig) InfoStream() util.InfoStream { 195 return conf.infoStream 196 } 197 198 // L548 199 func (conf *IndexWriterConfig) SetMaxBufferedDocs(maxBufferedDocs int) *IndexWriterConfig { 200 conf.LiveIndexWriterConfigImpl.SetMaxBufferedDocs(maxBufferedDocs) 201 return conf 202 } 203 204 func (conf *IndexWriterConfig) SetMergedSegmentWarmer(mergeSegmentWarmer IndexReaderWarmer) *IndexWriterConfig { 205 conf.LiveIndexWriterConfigImpl.SetMergedSegmentWarmer(mergeSegmentWarmer) 206 return conf 207 } 208 209 func (conf *IndexWriterConfig) SetReaderTermsIndexDivisor(divisor int) *IndexWriterConfig { 210 conf.LiveIndexWriterConfigImpl.SetReaderTermsIndexDivisor(divisor) 211 return conf 212 } 213 214 func (conf *IndexWriterConfig) SetUseCompoundFile(useCompoundFile bool) *IndexWriterConfig { 215 conf.LiveIndexWriterConfigImpl.SetUseCompoundFile(useCompoundFile) 216 return conf 217 } 218 219 func (conf *IndexWriterConfig) String() string { 220 panic("not implemented yet") 221 }