1 package org.jahia.services.search.analyzer; 2 3 import org.apache.lucene.analysis.*; 4 import org.apache.lucene.analysis.Token; 5 6 import java.io.IOException ; 7 import java.util.Stack ; 8 import java.util.StringTokenizer ; 9 10 17 public class TokenWithQuoteFilter extends TokenFilter 18 implements StandardTokenizerConstants { 19 20 private static final String APOSTROPHE_TYPE = tokenImage[APOSTROPHE]; 21 22 private Stack splittedWords; 23 24 public TokenWithQuoteFilter(TokenStream in) { 25 super(in); 26 splittedWords = new Stack (); 27 } 28 29 public final Token next() throws IOException { 30 if ( splittedWords.size()>0 ){ 31 return (Token)splittedWords.pop(); 32 } 33 Token t = input.next(); 34 if ( t == null ){ 35 return null; 36 } 37 splitWords(t); 38 return t; 39 } 40 41 private void splitWords(Token t){ 42 if (t.type() == APOSTROPHE_TYPE) { 43 44 StringTokenizer st = new StringTokenizer (t.termText(),"'"); 45 Token token = null; 46 String text = null; 47 while ( st.hasMoreTokens() ){ 48 text = st.nextToken(); 49 if ( text.length()>1 ){ 50 token = new Token(text,t.startOffset(),t.endOffset()); 51 token.setPositionIncrement(0); 52 splittedWords.push(token); 53 } 54 } 55 } 56 } 57 58 } 59 | Popular Tags |