1 package org.apache.maven.index.context;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.Reader;
23
24 import org.apache.lucene.analysis.Analyzer;
25 import org.apache.lucene.analysis.CharTokenizer;
26 import org.apache.lucene.analysis.TokenStream;
27 import org.apache.lucene.analysis.Tokenizer;
28 import org.apache.maven.index.creator.JarFileContentsIndexCreator;
29
30
31
32
33
34
35
36
37
38 public final class NexusAnalyzer
39 extends Analyzer
40 {
41 public TokenStream tokenStream( String fieldName, Reader reader )
42 {
43 return getTokenizer( fieldName, reader );
44 }
45
46 protected Tokenizer getTokenizer( String fieldName, Reader reader )
47 {
48 if ( JarFileContentsIndexCreator.FLD_CLASSNAMES_KW.getKey().equals( fieldName ) )
49 {
50
51 return new DeprecatedClassnamesTokenizer( reader );
52 }
53 else
54 {
55 return new LetterOrDigitTokenizer( reader );
56 }
57 }
58
59
60
61 public static class NoopTokenizer
62 extends CharTokenizer
63 {
64 public NoopTokenizer( Reader in )
65 {
66 super( in );
67 }
68
69 @Override
70 protected boolean isTokenChar( char c )
71 {
72 return true;
73 }
74 }
75
76 @Deprecated
77 public static class DeprecatedClassnamesTokenizer
78 extends CharTokenizer
79 {
80 public DeprecatedClassnamesTokenizer( Reader in )
81 {
82 super( in );
83 }
84
85 @Override
86 protected boolean isTokenChar( char c )
87 {
88 return c != '\n';
89 }
90
91 @Override
92 protected char normalize( char c )
93 {
94 return Character.toLowerCase( c );
95 }
96 }
97
98 public static class LetterOrDigitTokenizer
99 extends CharTokenizer
100 {
101 public LetterOrDigitTokenizer( Reader in )
102 {
103 super( in );
104 }
105
106 @Override
107 protected boolean isTokenChar( char c )
108 {
109 return Character.isLetterOrDigit( c );
110 }
111
112 @Override
113 protected char normalize( char c )
114 {
115 return Character.toLowerCase( c );
116 }
117 }
118
119 }