annotate src/goodjava/lucene/api/FieldAnalyzer.java @ 1730:b1b1f9a14928

fix Table.copy
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 01 Sep 2022 13:35:52 -0600
parents 3ab0d043370f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1460
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 package goodjava.lucene.api;
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 import java.util.Map;
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 import java.util.concurrent.ConcurrentHashMap;
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 import org.apache.lucene.analysis.Analyzer;
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 import org.apache.lucene.analysis.AnalyzerWrapper;
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 import org.apache.lucene.analysis.core.KeywordAnalyzer;
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 public final class FieldAnalyzer extends AnalyzerWrapper {
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 private static final Analyzer defaultAnalyzer = new KeywordAnalyzer();
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 private final Map<String,Analyzer> fieldAnalyzers = new ConcurrentHashMap<String,Analyzer>();
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 public void add(String fieldName,Analyzer analyzer) {
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 fieldAnalyzers.put(fieldName,analyzer);
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 }
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 public boolean isAdded(String fieldName) {
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 return fieldAnalyzers.containsKey(fieldName);
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 }
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 protected Analyzer getWrappedAnalyzer(String fieldName) {
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 Analyzer analyzer = fieldAnalyzers.get(fieldName);
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 /*
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 if( analyzer == null )
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 throw new RuntimeException("no analyzer for field: "+fieldName);
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 return analyzer;
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 */
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 return analyzer!=null ? analyzer : defaultAnalyzer;
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 }
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 }