1 package org.jahia.services.search.analyzer; 2 3 56 57 import org.apache.lucene.analysis.*; 58 59 60 61 public final class StandardFilter extends TokenFilter 62 implements StandardTokenizerConstants { 63 64 65 66 public StandardFilter(TokenStream in) { 67 super(in); 68 } 69 70 private static final String APOSTROPHE_TYPE = tokenImage[APOSTROPHE]; 71 private static final String ACRONYM_TYPE = tokenImage[ACRONYM]; 72 73 77 public final org.apache.lucene.analysis.Token next() throws java.io.IOException { 78 org.apache.lucene.analysis.Token t = input.next(); 79 80 if (t == null) 81 return null; 82 83 String text = t.termText(); 84 String type = t.type(); 85 86 if (type == APOSTROPHE_TYPE && (text.endsWith("'s") || text.endsWith("'S"))) { 88 return new org.apache.lucene.analysis.Token 89 (text.substring(0,text.length()-2), 90 t.startOffset(), t.endOffset(), type); 91 92 } else if (type == ACRONYM_TYPE) { StringBuffer trimmed = new StringBuffer (); 94 for (int i = 0; i < text.length(); i++) { 95 char c = text.charAt(i); 96 if (c != '.') 97 trimmed.append(c); 98 } 99 return new org.apache.lucene.analysis.Token 100 (trimmed.toString(), t.startOffset(), t.endOffset(), type); 101 102 } else { 103 return t; 104 } 105 } 106 } 107 | Popular Tags |