1460
|
1 package goodjava.lucene.api;
|
|
2
|
|
3 import java.util.Map;
|
|
4 import java.util.concurrent.ConcurrentHashMap;
|
|
5 import org.apache.lucene.analysis.Analyzer;
|
|
6 import org.apache.lucene.analysis.AnalyzerWrapper;
|
|
7 import org.apache.lucene.analysis.core.KeywordAnalyzer;
|
|
8
|
|
9
|
|
10 public final class FieldAnalyzer extends AnalyzerWrapper {
|
|
11 private static final Analyzer defaultAnalyzer = new KeywordAnalyzer();
|
|
12 private final Map<String,Analyzer> fieldAnalyzers = new ConcurrentHashMap<String,Analyzer>();
|
|
13
|
|
14 public void add(String fieldName,Analyzer analyzer) {
|
|
15 fieldAnalyzers.put(fieldName,analyzer);
|
|
16 }
|
|
17
|
|
18 public boolean isAdded(String fieldName) {
|
|
19 return fieldAnalyzers.containsKey(fieldName);
|
|
20 }
|
|
21
|
|
22 protected Analyzer getWrappedAnalyzer(String fieldName) {
|
|
23 Analyzer analyzer = fieldAnalyzers.get(fieldName);
|
|
24 /*
|
|
25 if( analyzer == null )
|
|
26 throw new RuntimeException("no analyzer for field: "+fieldName);
|
|
27 return analyzer;
|
|
28 */
|
|
29 return analyzer!=null ? analyzer : defaultAnalyzer;
|
|
30 }
|
|
31 }
|