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