1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.index.context;
20
21 import org.apache.lucene.analysis.Analyzer;
22 import org.apache.lucene.analysis.AnalyzerWrapper;
23 import org.apache.lucene.analysis.LowerCaseFilter;
24 import org.apache.lucene.analysis.Tokenizer;
25 import org.apache.lucene.analysis.standard.StandardAnalyzer;
26 import org.apache.lucene.analysis.util.CharTokenizer;
27 import org.apache.maven.index.ArtifactInfo;
28
29
30
31
32
33
34
35
36 public final class NexusLegacyAnalyzer extends AnalyzerWrapper {
37 private static final Analyzer DEFAULT_ANALYZER = new StandardAnalyzer();
38
39 private static final Analyzer LETTER_OR_DIGIT_ANALYZER = new Analyzer() {
40 @Override
41 protected TokenStreamComponents createComponents(final String fieldName) {
42 final Tokenizer tokenizer = new CharTokenizer() {
43 @Override
44 protected boolean isTokenChar(int c) {
45 return Character.isLetterOrDigit(c);
46 }
47 };
48
49 return new TokenStreamComponents(tokenizer, new LowerCaseFilter(tokenizer));
50 }
51 };
52
53 public NexusLegacyAnalyzer() {
54 super(PER_FIELD_REUSE_STRATEGY);
55 }
56
57 @Override
58 protected Analyzer getWrappedAnalyzer(String fieldName) {
59 if (!isTextField(fieldName)) {
60 return LETTER_OR_DIGIT_ANALYZER;
61 } else {
62 return DEFAULT_ANALYZER;
63 }
64 }
65
66 protected boolean isTextField(String field) {
67 return ArtifactInfo.NAME.equals(field)
68 || ArtifactInfo.DESCRIPTION.equals(field)
69 || ArtifactInfo.NAMES.equals(field);
70 }
71 }