1 |
28918
|
claudio.at
|
package eu.dnetlib.functionality.index.utils;
|
2 |
|
|
|
3 |
|
|
import java.util.Map;
|
4 |
|
|
import java.util.Map.Entry;
|
5 |
|
|
|
6 |
|
|
import org.antlr.stringtemplate.StringTemplate;
|
7 |
|
|
import org.apache.commons.logging.Log;
|
8 |
|
|
import org.apache.commons.logging.LogFactory;
|
9 |
|
|
import org.springframework.beans.factory.annotation.Required;
|
10 |
|
|
|
11 |
|
|
import com.google.common.base.Predicate;
|
12 |
|
|
import com.google.common.collect.Maps;
|
13 |
|
|
|
14 |
|
|
import eu.dnetlib.data.provision.index.rmi.IndexServiceException;
|
15 |
|
|
|
16 |
|
|
public class IndexConfigFactory {
|
17 |
|
|
|
18 |
29973
|
sandro.lab
|
private static final Log log = LogFactory.getLog(IndexConfigFactory.class); // NOPMD
|
19 |
|
|
// by
|
20 |
|
|
// marko
|
21 |
|
|
// on
|
22 |
|
|
// 11/24/08
|
23 |
|
|
// 5:02
|
24 |
|
|
// PM
|
25 |
28918
|
claudio.at
|
|
26 |
|
|
public enum CONFIG_PARAMS {
|
27 |
|
|
// TODO replace with actual values
|
28 |
46709
|
claudio.at
|
luceneMatchVersion,
|
29 |
|
|
serverLibPath,
|
30 |
|
|
filterCacheSize,
|
31 |
|
|
filterCacheInitialSize,
|
32 |
|
|
queryCacheSize,
|
33 |
|
|
queryCacheInitialSize,
|
34 |
|
|
documentCacheSize,
|
35 |
|
|
documentCacheInitialSize,
|
36 |
|
|
queryResultWindowSize,
|
37 |
|
|
queryResultMaxDocCached,
|
38 |
|
|
ramBufferSizeMB,
|
39 |
|
|
mergeFactor,
|
40 |
|
|
termIndexInterval,
|
41 |
|
|
autosoftcommit,
|
42 |
|
|
autocommit,
|
43 |
|
|
maxIndexingThreads;
|
44 |
28918
|
claudio.at
|
|
45 |
|
|
static boolean isValid(final String v) {
|
46 |
|
|
try {
|
47 |
|
|
CONFIG_PARAMS.valueOf(v);
|
48 |
|
|
return true;
|
49 |
|
|
} catch (Throwable e) {
|
50 |
|
|
return false;
|
51 |
|
|
}
|
52 |
|
|
}
|
53 |
|
|
};
|
54 |
|
|
|
55 |
|
|
/**
|
56 |
|
|
* Index configuration template.
|
57 |
|
|
*/
|
58 |
|
|
private StringTemplate solrConfig;
|
59 |
|
|
|
60 |
|
|
/**
|
61 |
|
|
* @param docIn
|
62 |
|
|
* input document
|
63 |
29973
|
sandro.lab
|
* @return the application of the schemaXslt transformation to the docIn
|
64 |
|
|
* document
|
65 |
28918
|
claudio.at
|
* @throws IndexServiceException
|
66 |
|
|
*/
|
67 |
29973
|
sandro.lab
|
public String getConfig(final Map<String, String> params)
|
68 |
|
|
throws IndexServiceException {
|
69 |
|
|
final StringTemplate conf = new StringTemplate(getSolrConfig()
|
70 |
|
|
.getTemplate());
|
71 |
28918
|
claudio.at
|
for (Entry<String, String> e : filter(params).entrySet()) {
|
72 |
29973
|
sandro.lab
|
log.debug("setting conf property [" + e.getKey() + ":"
|
73 |
|
|
+ e.getValue() + "]");
|
74 |
28918
|
claudio.at
|
conf.setAttribute(e.getKey(), e.getValue());
|
75 |
|
|
}
|
76 |
|
|
return conf.toString();
|
77 |
|
|
}
|
78 |
|
|
|
79 |
|
|
private Map<String, String> filter(final Map<String, String> params) {
|
80 |
|
|
return Maps.filterKeys(params, new Predicate<String>() {
|
81 |
|
|
|
82 |
|
|
@Override
|
83 |
|
|
public boolean apply(final String input) {
|
84 |
|
|
return CONFIG_PARAMS.isValid(input);
|
85 |
|
|
}
|
86 |
|
|
});
|
87 |
|
|
}
|
88 |
|
|
|
89 |
|
|
public StringTemplate getSolrConfig() {
|
90 |
|
|
return solrConfig;
|
91 |
|
|
}
|
92 |
|
|
|
93 |
|
|
@Required
|
94 |
|
|
public void setSolrConfig(final StringTemplate solrConfig) {
|
95 |
|
|
this.solrConfig = solrConfig;
|
96 |
|
|
}
|
97 |
|
|
|
98 |
|
|
}
|