1 package com.openedit.modules.search; 2 3 import java.io.Reader ; 4 import java.util.HashMap ; 5 import java.util.Map ; 6 7 import org.apache.lucene.analysis.Analyzer; 8 import org.apache.lucene.analysis.TokenStream; 9 import org.apache.lucene.analysis.standard.StandardAnalyzer; 10 11 12 13 14 public class CompositeAnalyzer extends Analyzer 15 { 16 protected Analyzer fieldDefaultAnalyzer = new StandardAnalyzer(); 18 protected Map fieldChoices = new HashMap (); 19 public TokenStream tokenStream(String fieldName, Reader reader) 20 { 21 Analyzer ana = getAnalizer(fieldName); 22 return ana.tokenStream(fieldName, reader); 23 } 24 public Analyzer getAnalizer(String inField) 25 { 26 if( inField == null) 27 { 28 return fieldDefaultAnalyzer; 29 } 30 Analyzer res = (Analyzer)getChoices().get(inField); 31 if ( res == null) 32 { 33 return fieldDefaultAnalyzer; 34 } 35 return res; 36 } 37 protected Map getChoices() 38 { 39 return fieldChoices; 40 } 41 protected void setChoices(Map inChoices) 42 { 43 fieldChoices = inChoices; 44 } 45 public void setAnalyzer(String inField, Analyzer inAnalyzer) 46 { 47 getChoices().put(inField, inAnalyzer); 48 } 49 50 } 51 52 | Popular Tags |