1 package org.apache.maven.index;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.lucene.document.Field;
23 import org.apache.lucene.document.FieldType;
24 import org.apache.lucene.index.IndexOptions;
25
26
27
28
29
30
31
32 public class IndexerField
33 {
34 private final org.apache.maven.index.Field ontology;
35
36 private final IndexerFieldVersion version;
37
38 private final String key;
39
40 private final FieldType fieldType;
41
42
43 public static final FieldType KEYWORD_NOT_STORED = new FieldType();
44
45
46 public static final FieldType KEYWORD_STORED = new FieldType();
47
48
49 public static final FieldType ANALYZED_NOT_STORED = new FieldType();
50
51
52 public static final FieldType ANALYZED_STORED = new FieldType();
53
54 static
55 {
56 KEYWORD_NOT_STORED.setIndexOptions( IndexOptions.DOCS_AND_FREQS_AND_POSITIONS );
57 KEYWORD_NOT_STORED.setStored( false );
58 KEYWORD_NOT_STORED.setTokenized( false );
59 KEYWORD_NOT_STORED.freeze();
60
61 KEYWORD_STORED.setIndexOptions( IndexOptions.DOCS_AND_FREQS_AND_POSITIONS );
62 KEYWORD_STORED.setStored( true );
63 KEYWORD_STORED.setTokenized( false );
64 KEYWORD_STORED.freeze();
65
66 ANALYZED_NOT_STORED.setIndexOptions( IndexOptions.DOCS_AND_FREQS_AND_POSITIONS );
67 ANALYZED_NOT_STORED.setStored( false );
68 ANALYZED_NOT_STORED.setTokenized( true );
69 ANALYZED_NOT_STORED.freeze();
70
71 ANALYZED_STORED.setIndexOptions( IndexOptions.DOCS_AND_FREQS_AND_POSITIONS );
72 ANALYZED_STORED.setStored( true );
73 ANALYZED_STORED.setTokenized( true );
74 ANALYZED_STORED.freeze();
75 }
76
77 public IndexerField( final org.apache.maven.index.Field ontology, final IndexerFieldVersion version,
78 final String key, final String description, final FieldType fieldType )
79 {
80 this.ontology = ontology;
81
82 this.version = version;
83
84 this.key = key;
85
86 this.fieldType = fieldType;
87
88 ontology.addIndexerField( this );
89 }
90
91 public org.apache.maven.index.Field getOntology()
92 {
93 return ontology;
94 }
95
96 public IndexerFieldVersion getVersion()
97 {
98 return version;
99 }
100
101 public String getKey()
102 {
103 return key;
104 }
105
106 public FieldType getFieldType()
107 {
108 return fieldType;
109 }
110
111 public boolean isIndexed()
112 {
113 return fieldType.indexOptions() != IndexOptions.NONE;
114 }
115
116 public boolean isKeyword()
117 {
118 return isIndexed() && !fieldType.tokenized();
119 }
120
121 public boolean isStored()
122 {
123 return fieldType.stored();
124 }
125
126 public Field toField( String value )
127 {
128 return new Field( getKey(), value, getFieldType() );
129 }
130 }