1 package org.tigris.scarab.util.word; 2 3 48 49 import java.io.Reader ; 50 import java.io.IOException ; 51 import org.apache.lucene.analysis.PorterStemFilter; 52 import org.apache.lucene.analysis.Analyzer; 53 import org.apache.lucene.analysis.TokenStream; 54 import org.apache.lucene.analysis.Token; 55 import org.apache.lucene.analysis.standard.StandardAnalyzer; 56 import org.tigris.scarab.util.Log; 57 58 public class PorterStemAnalyzer extends Analyzer 59 { 60 private static final boolean DEBUG = false; 61 62 66 public final TokenStream tokenStream(String fieldName, Reader reader) 67 { 68 TokenStream result = new StandardAnalyzer() 69 .tokenStream(fieldName, reader); 70 result = new PorterStemFilter(result); 71 if (DEBUG) 72 { 73 final TokenStream delegate = result; 74 result = new TokenStream() 75 { 76 79 public Token next() throws IOException 80 { 81 Token token = delegate.next(); 82 if (token != null) 83 { 84 if (Log.get().isDebugEnabled()) 85 { 86 Log.get().debug("Token (" + token.type() + 87 "): " + token.termText()); 88 } 89 } 90 return token; 91 } 92 93 96 public void close() throws IOException 97 { 98 delegate.close(); 99 } 100 }; 101 } 102 103 return result; 104 } 105 } 106 | Popular Tags |