-
Notifications
You must be signed in to change notification settings - Fork 242
/
IndexWriterConfigSource.java
65 lines (54 loc) · 2.19 KB
/
IndexWriterConfigSource.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
* Hibernate Search, full-text search for your domain model
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.search.backend.lucene.lowlevel.writer.impl;
import java.util.List;
import org.hibernate.search.engine.cfg.spi.ConfigurationPropertySource;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.LogByteSizeMergePolicy;
/**
* A source of index writer configuration that can be re-used on multiple writers.
* <p>
* This is mostly necessary because we don't have access to the user configuration after startup,
* and we don't want to re-use the same IndexWriterConfig instance multiple times in order to be safe
* and make sure a previous, failing index writer will never affect the configuration of
* the new index writer created to replace it.
*
* @author Hardy Ferentschik
* @author Sanne Grinovero
*/
public class IndexWriterConfigSource {
// property path keywords
public static final String PROP_GROUP = "indexwriter";
private final List<IndexWriterSettingValue<?>> values;
public IndexWriterConfigSource(ConfigurationPropertySource propertySource) {
ConfigurationPropertySource indexingParameters = propertySource.withMask( PROP_GROUP );
values = IndexWriterSettings.extractAll( indexingParameters );
}
@Override
public String toString() {
return "IndexWriterConfigSource{" + values + '}';
}
/**
* Applies the parameters represented by this to a writer.
* Undefined parameters are not set, leaving the lucene default.
*
* @param writerConfig the IndexWriter configuration whereto the parameters will be applied.
*/
public void applyToWriter(IndexWriterConfig writerConfig) {
for ( IndexWriterSettingValue<?> value : values ) {
value.applySetting( writerConfig );
}
writerConfig.setMergePolicy( createMergePolicy() );
}
private LogByteSizeMergePolicy createMergePolicy() {
LogByteSizeMergePolicy logByteSizeMergePolicy = new LogByteSizeMergePolicy();
for ( IndexWriterSettingValue<?> value : values ) {
value.applySetting( logByteSizeMergePolicy );
}
return logByteSizeMergePolicy;
}
}