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 8 15 public class LanguageIndependantFilter extends TokenFilter 16 implements StandardTokenizerConstants { 17 18 char[] filteredChars = new char[]{'á','à','â','é','è','ê','ô','ù'}; 19 20 char[] replacedChars = new char[]{'a','a','a','e','e','e','o','u'}; 21 22 23 public LanguageIndependantFilter(TokenStream in) { 24 super(in); 25 } 26 27 public final org.apache.lucene.analysis.Token next() throws IOException { 28 Token t = input.next(); 29 if ( t == null ){ 30 return null; 31 } 32 33 String text = t.termText(); 34 35 StringBuffer trimmed = new StringBuffer (); 36 boolean found = false; 37 for (int i = 0; i < text.length(); i++) { 38 char c = text.charAt(i); 39 found = false; 40 for ( int j=0; j<filteredChars.length; j++){ 41 if ( c == filteredChars[j] ) { 42 trimmed.append(replacedChars[j]); 43 found = true; 44 break; 45 } 46 } 47 if ( !found ){ 48 trimmed.append(c); 49 } 50 } 51 return new org.apache.lucene.analysis.Token 52 (trimmed.toString(), t.startOffset(), t.endOffset(), t.type()); 53 } 54 } 55 | Popular Tags |