1 package org.apache.lucene.analysis; 2 3 18 19 import java.io.Reader ; 20 import java.util.Map ; 21 import java.util.HashMap ; 22 23 43 public class PerFieldAnalyzerWrapper extends Analyzer { 44 private Analyzer defaultAnalyzer; 45 private Map analyzerMap = new HashMap (); 46 47 48 54 public PerFieldAnalyzerWrapper(Analyzer defaultAnalyzer) { 55 this.defaultAnalyzer = defaultAnalyzer; 56 } 57 58 64 public void addAnalyzer(String fieldName, Analyzer analyzer) { 65 analyzerMap.put(fieldName, analyzer); 66 } 67 68 public TokenStream tokenStream(String fieldName, Reader reader) { 69 Analyzer analyzer = (Analyzer) analyzerMap.get(fieldName); 70 if (analyzer == null) { 71 analyzer = defaultAnalyzer; 72 } 73 74 return analyzer.tokenStream(fieldName, reader); 75 } 76 77 public String toString() { 78 return "PerFieldAnalyzerWrapper(" + analyzerMap + ", default=" + defaultAnalyzer + ")"; 79 } 80 } 81 | Popular Tags |