View Javadoc

1   package org.apache.maven.index;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0    
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.lucene.document.Field;
23  import org.apache.lucene.document.Field.Index;
24  import org.apache.lucene.document.Field.Store;
25  import org.apache.lucene.document.Field.TermVector;
26  
27  /**
28   * Holds basic information about Indexer field, how it is stored. To keep this centralized, and not spread across code.
29   * Since Lucene 2.x, the field names are encoded, so please use real chatty names instead of cryptic chars!
30   * 
31   * @author cstamas
32   */
33  public class IndexerField
34  {
35      private final org.apache.maven.index.Field ontology;
36  
37      private final IndexerFieldVersion version;
38  
39      private final String key;
40  
41      private final Store storeMethod;
42  
43      private final Index indexMethod;
44  
45      private final TermVector termVector;
46  
47      public IndexerField( final org.apache.maven.index.Field ontology, final IndexerFieldVersion version,
48                           final String key, final String description, final Store storeMethod, final Index indexMethod )
49      {
50          this( ontology, version, key, description, storeMethod, indexMethod, null );
51      }
52  
53      public IndexerField( final org.apache.maven.index.Field ontology, final IndexerFieldVersion version,
54                           final String key, final String description, final Store storeMethod, final Index indexMethod,
55                           final TermVector termVector )
56      {
57          this.ontology = ontology;
58  
59          this.version = version;
60  
61          this.key = key;
62  
63          this.storeMethod = storeMethod;
64  
65          this.indexMethod = indexMethod;
66  
67          this.termVector = termVector;
68  
69          ontology.addIndexerField( this );
70      }
71  
72      public org.apache.maven.index.Field getOntology()
73      {
74          return ontology;
75      }
76  
77      public IndexerFieldVersion getVersion()
78      {
79          return version;
80      }
81  
82      public String getKey()
83      {
84          return key;
85      }
86  
87      public Field.Store getStoreMethod()
88      {
89          return storeMethod;
90      }
91  
92      public Field.Index getIndexMethod()
93      {
94          return indexMethod;
95      }
96  
97      public Field.TermVector getTermVector()
98      {
99          return termVector;
100     }
101 
102     public boolean isIndexed()
103     {
104         return !Index.NO.equals( indexMethod );
105     }
106 
107     public boolean isKeyword()
108     {
109         return isIndexed() && !Index.ANALYZED.equals( indexMethod );
110     }
111 
112     public boolean isStored()
113     {
114         return !( Store.NO.equals( storeMethod ) );
115     }
116 
117     public Field toField( String value )
118     {
119         Field result;
120 
121         if ( getTermVector() != null )
122         {
123             result = new Field( getKey(), value, getStoreMethod(), getIndexMethod(), getTermVector() );
124         }
125         else
126         {
127             result = new Field( getKey(), value, getStoreMethod(), getIndexMethod() );
128         }
129 
130         // if ( isKeyword() )
131         // {
132         // result.setOmitNorms( true );
133         // result.setOmitTf( true );
134         // }
135 
136         return result;
137     }
138 }