1 18 19 package org.apache.roller.business.search; 20 21 import org.apache.lucene.analysis.Analyzer; 22 import org.apache.lucene.analysis.Token; 23 import org.apache.lucene.analysis.TokenStream; 24 import org.apache.lucene.index.Term; 25 import org.apache.roller.business.IndexManagerImpl; 26 27 import java.io.IOException ; 28 import java.io.StringReader ; 29 30 34 public class IndexUtil { 35 36 43 public static final Term getTerm(String field, String input) { 44 if (input==null || field==null) return null; 45 Analyzer analyer = IndexManagerImpl.getAnalyzer(); 46 TokenStream tokens = analyer.tokenStream(field, 47 new StringReader (input)); 48 49 Token token = null; 50 Term term = null; 51 try { 52 token = tokens.next(); 53 } catch (IOException e) {} 54 if (token!=null) { 55 String termt = token.termText(); 56 term = new Term(field,termt); 57 } 58 return term; 59 } 60 61 } 62 | Popular Tags |