KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openedit > modules > search > CompositeAnalyzer


1 package com.openedit.modules.search;
2
3 import java.io.Reader JavaDoc;
4 import java.util.HashMap JavaDoc;
5 import java.util.Map JavaDoc;
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 /** An Analyzer that filters LetterTokenizer with LowerCaseFilter. */
12
13
14 public class CompositeAnalyzer extends Analyzer
15 {
16     //some fields use StandardAnaliser
17
protected Analyzer fieldDefaultAnalyzer = new StandardAnalyzer();
18     protected Map JavaDoc fieldChoices = new HashMap JavaDoc();
19      public TokenStream tokenStream(String JavaDoc fieldName, Reader JavaDoc reader)
20      {
21         Analyzer ana = getAnalizer(fieldName);
22         return ana.tokenStream(fieldName, reader);
23      }
24      public Analyzer getAnalizer(String JavaDoc 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 JavaDoc getChoices()
38     {
39         return fieldChoices;
40     }
41     protected void setChoices(Map JavaDoc inChoices)
42     {
43         fieldChoices = inChoices;
44     }
45     public void setAnalyzer(String JavaDoc inField, Analyzer inAnalyzer)
46     {
47         getChoices().put(inField, inAnalyzer);
48     }
49
50 }
51
52
Popular Tags