KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > services > search > analyzer > LanguageIndependantFilter


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 JavaDoc;
7
8 /**
9  * Created by IntelliJ IDEA.
10  * User: hollis
11  * Date: 25 mai 2005
12  * Time: 21:05:11
13  * To change this template use File | Settings | File Templates.
14  */

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 JavaDoc {
28         Token t = input.next();
29         if ( t == null ){
30             return null;
31         }
32
33         String JavaDoc text = t.termText();
34                 
35         StringBuffer JavaDoc trimmed = new StringBuffer JavaDoc();
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