view src/goodjava/lucene/api/FieldAnalyzer.java @ 1495:2e8a5df45d56

better xml
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 05 May 2020 11:03:48 -0600
parents 3ab0d043370f
children
line wrap: on
line source

package goodjava.lucene.api;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.AnalyzerWrapper;
import org.apache.lucene.analysis.core.KeywordAnalyzer;


public final class FieldAnalyzer extends AnalyzerWrapper {
	private static final Analyzer defaultAnalyzer = new KeywordAnalyzer();
	private final Map<String,Analyzer> fieldAnalyzers = new ConcurrentHashMap<String,Analyzer>();

	public void add(String fieldName,Analyzer analyzer) {
		fieldAnalyzers.put(fieldName,analyzer);
	}

	public boolean isAdded(String fieldName) {
		return fieldAnalyzers.containsKey(fieldName);
	}

	protected Analyzer getWrappedAnalyzer(String fieldName) {
		Analyzer analyzer = fieldAnalyzers.get(fieldName);
/*
		if( analyzer == null )
			throw new RuntimeException("no analyzer for field: "+fieldName);
		return analyzer;
*/
		return analyzer!=null ? analyzer : defaultAnalyzer;
	}
}