1 6 package org.roller.business.search; 7 8 import org.apache.lucene.analysis.Analyzer; 9 import org.apache.lucene.analysis.Token; 10 import org.apache.lucene.analysis.TokenStream; 11 import org.apache.lucene.index.Term; 12 import org.roller.business.IndexManagerImpl; 13 14 import java.io.IOException ; 15 import java.io.StringReader ; 16 17 22 public class IndexUtil { 23 24 31 public static final Term getTerm(String field, String input) { 32 if (input==null || field==null) return null; 33 Analyzer analyer = IndexManagerImpl.getAnalyzer(); 34 TokenStream tokens = analyer.tokenStream(field, 35 new StringReader (input)); 36 37 Token token = null; 38 Term term = null; 39 try { 40 token = tokens.next(); 41 } catch (IOException e) {} 42 if (token!=null) { 43 String termt = token.termText(); 44 term = new Term(field,termt); 45 } 46 return term; 47 } 48 49 } 50 | Popular Tags |