*/
public static Analyzer createAnalyzer(final GenericConfiguration config) {
// Caching the analyzer instances is not possible as those do not implement Serializable
// TODO: cache the config (imho caching should be implemented in the config itself)
PerFieldAnalyzerWrapper analyzerWrapper = new PerFieldAnalyzerWrapper(createDefaultAnalyzer(config));
configuredAnalyzerMap.clear();
//Load analyzer config
GenericConfiguration analyzerConfig = loadAnalyzerConfig(config);
if (analyzerConfig != null) {
ArrayList<String> addedReverseAttributes = new ArrayList<String>();
List<String> reverseAttributes = getReverseAttributes(config);
Map<String, GenericConfiguration> subconfigs = analyzerConfig.getSortedSubconfigs();
if (subconfigs != null) {
for (Map.Entry<String, GenericConfiguration> entry : subconfigs.entrySet()) {
GenericConfiguration analyzerconfig = entry.getValue();
String fieldname = analyzerconfig.getString(FIELD_NAME_KEY);
String analyzerclass = analyzerconfig.getString(ANALYZER_CLASS_KEY);
Analyzer analyzerInstance = createAnalyzer(analyzerclass, analyzerconfig);
analyzerWrapper.addAnalyzer(fieldname, analyzerInstance);
configuredAnalyzerMap.put(fieldname, analyzerInstance.getClass().getCanonicalName());
//ADD REVERSE ANALYZERS
if (reverseAttributes != null && reverseAttributes.contains(fieldname)) {
addedReverseAttributes.add(fieldname);
ReverseAnalyzer reverseAnalyzer = new ReverseAnalyzer(analyzerInstance);
analyzerWrapper.addAnalyzer(fieldname + REVERSE_ATTRIBUTE_SUFFIX, reverseAnalyzer);
configuredAnalyzerMap.put(fieldname + REVERSE_ATTRIBUTE_SUFFIX, reverseAnalyzer.getClass()
.getCanonicalName());
}
}
}
//ADD ALL NON CONFIGURED REVERSE ANALYZERS
if (reverseAttributes != null && reverseAttributes.size() > 0) {
for (String att : reverseAttributes) {
if (!addedReverseAttributes.contains(att)) {
ReverseAnalyzer reverseAnalyzer = new ReverseAnalyzer(null);
analyzerWrapper.addAnalyzer(att + REVERSE_ATTRIBUTE_SUFFIX, reverseAnalyzer);
configuredAnalyzerMap.put(att + REVERSE_ATTRIBUTE_SUFFIX, reverseAnalyzer.getClass()
.getCanonicalName());
}
}
}