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.IOException;
23 import java.io.Reader;
24
25 import org.apache.lucene.analysis.Analyzer;
26 import org.apache.lucene.analysis.CharTokenizer;
27 import org.apache.lucene.analysis.TokenStream;
28 import org.apache.lucene.analysis.standard.StandardAnalyzer;
29 import org.apache.lucene.util.Version;
30 import org.apache.maven.index.ArtifactInfo;
31
32
33
34
35
36
37
38
39 public final class NexusLegacyAnalyzer
40 extends Analyzer
41 {
42 private static Analyzer DEFAULT_ANALYZER = new StandardAnalyzer( Version.LUCENE_30 );
43
44 @Override
45 public TokenStream tokenStream( String field, final Reader reader )
46 {
47 if ( !isTextField( field ) )
48 {
49 return new CharTokenizer( reader )
50 {
51 @Override
52 protected boolean isTokenChar( char c )
53 {
54 return Character.isLetterOrDigit( c );
55 }
56
57 @Override
58 protected char normalize( char c )
59 {
60 return Character.toLowerCase( c );
61 }
62 };
63 }
64 else
65 {
66 return DEFAULT_ANALYZER.tokenStream( field, reader );
67 }
68 }
69
70 @Override
71 public TokenStream reusableTokenStream( String field, Reader reader )
72 throws IOException
73 {
74 if ( !isTextField( field ) )
75 {
76 return new CharTokenizer( reader )
77 {
78 @Override
79 protected boolean isTokenChar( char c )
80 {
81 return Character.isLetterOrDigit( c );
82 }
83
84 @Override
85 protected char normalize( char c )
86 {
87 return Character.toLowerCase( c );
88 }
89 };
90 }
91 else
92 {
93 return DEFAULT_ANALYZER.reusableTokenStream( field, reader );
94 }
95 }
96
97 protected boolean isTextField( String field )
98 {
99 return ArtifactInfo.NAME.equals( field ) || ArtifactInfo.DESCRIPTION.equals( field )
100 || ArtifactInfo.NAMES.equals( field );
101
102 }
103
104 }