Clover Coverage Report
Coverage timestamp: Wed Oct 14 2009 06:20:44 CDT
../../../../img/srcFileCovDistChart7.png 63% of files have more coverage
105   274   49   5.83
60   164   0.47   18
18     2.72  
1    
 
  AbstractField       Line # 23 105 49 62.3% 0.6229508
 
  (133)
 
1    package org.apache.lucene.document;
2    /**
3    * Copyright 2006 The Apache Software Foundation
4    *
5    * Licensed under the Apache License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    * http://www.apache.org/licenses/LICENSE-2.0
10    *
11    * Unless required by applicable law or agreed to in writing, software
12    * distributed under the License is distributed on an "AS IS" BASIS,
13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    * See the License for the specific language governing permissions and
15    * limitations under the License.
16    */
17   
18   
19    /**
20    *
21    *
22    **/
 
23    public abstract class AbstractField implements Fieldable {
24   
25    protected String name = "body";
26    protected boolean storeTermVector = false;
27    protected boolean storeOffsetWithTermVector = false;
28    protected boolean storePositionWithTermVector = false;
29    protected boolean omitNorms = false;
30    protected boolean isStored = false;
31    protected boolean isIndexed = true;
32    protected boolean isTokenized = true;
33    protected boolean isBinary = false;
34    protected boolean isCompressed = false;
35    protected boolean lazy = false;
36    protected float boost = 1.0f;
37    // the one and only data object for all different kind of field values
38    protected Object fieldsData = null;
39   
 
40  2644506 toggle protected AbstractField()
41    {
42   
43    }
44   
 
45  153632 toggle protected AbstractField(String name, Field.Store store, Field.Index index, Field.TermVector termVector) {
46  153634 if (name == null)
47  0 throw new NullPointerException("name cannot be null");
48  153632 this.name = name.intern(); // field names are interned
49   
50  153631 if (store == Field.Store.YES){
51  153627 this.isStored = true;
52  153631 this.isCompressed = false;
53    }
54  0 else if (store == Field.Store.COMPRESS) {
55  0 this.isStored = true;
56  0 this.isCompressed = true;
57    }
58  0 else if (store == Field.Store.NO){
59  0 this.isStored = false;
60  0 this.isCompressed = false;
61    }
62    else
63  0 throw new IllegalArgumentException("unknown store parameter " + store);
64   
65  153633 if (index == Field.Index.NO) {
66  1 this.isIndexed = false;
67  1 this.isTokenized = false;
68  153633 } else if (index == Field.Index.TOKENIZED) {
69  153631 this.isIndexed = true;
70  153631 this.isTokenized = true;
71  0 } else if (index == Field.Index.UN_TOKENIZED) {
72  0 this.isIndexed = true;
73  0 this.isTokenized = false;
74  0 } else if (index == Field.Index.NO_NORMS) {
75  0 this.isIndexed = true;
76  0 this.isTokenized = false;
77  0 this.omitNorms = true;
78    } else {
79  0 throw new IllegalArgumentException("unknown index parameter " + index);
80    }
81   
82  153634 this.isBinary = false;
83   
84  153634 setStoreTermVector(termVector);
85    }
86   
87    /** Sets the boost factor hits on this field. This value will be
88    * multiplied into the score of all hits on this this field of this
89    * document.
90    *
91    * <p>The boost is multiplied by {@link org.apache.lucene.document.Document#getBoost()} of the document
92    * containing this field. If a document has multiple fields with the same
93    * name, all such values are multiplied together. This product is then
94    * multipled by the value {@link org.apache.lucene.search.Similarity#lengthNorm(String,int)}, and
95    * rounded by {@link org.apache.lucene.search.Similarity#encodeNorm(float)} before it is stored in the
96    * index. One should attempt to ensure that this product does not overflow
97    * the range of that encoding.
98    *
99    * @see org.apache.lucene.document.Document#setBoost(float)
100    * @see org.apache.lucene.search.Similarity#lengthNorm(String, int)
101    * @see org.apache.lucene.search.Similarity#encodeNorm(float)
102    */
 
103  1 toggle public void setBoost(float boost) {
104  1 this.boost = boost;
105    }
106   
107    /** Returns the boost factor for hits for this field.
108    *
109    * <p>The default value is 1.0.
110    *
111    * <p>Note: this value is not stored directly with the document in the index.
112    * Documents returned from {@link org.apache.lucene.index.IndexReader#document(int)} and
113    * {@link org.apache.lucene.search.Hits#doc(int)} may thus not have the same value present as when
114    * this field was indexed.
115    *
116    * @see #setBoost(float)
117    */
 
118  515765 toggle public float getBoost() {
119  515765 return boost;
120    }
121   
122    /** Returns the name of the field as an interned string.
123    * For example "date", "title", "body", ...
124    */
 
125  3509518 toggle public String name() { return name; }
126   
 
127  826958 toggle protected void setStoreTermVector(Field.TermVector termVector) {
128  826964 if (termVector == Field.TermVector.NO) {
129  821601 this.storeTermVector = false;
130  821607 this.storePositionWithTermVector = false;
131  821604 this.storeOffsetWithTermVector = false;
132    }
133  5355 else if (termVector == Field.TermVector.YES) {
134  1827 this.storeTermVector = true;
135  1827 this.storePositionWithTermVector = false;
136  1827 this.storeOffsetWithTermVector = false;
137    }
138  3528 else if (termVector == Field.TermVector.WITH_POSITIONS) {
139  1715 this.storeTermVector = true;
140  1715 this.storePositionWithTermVector = true;
141  1715 this.storeOffsetWithTermVector = false;
142    }
143  1813 else if (termVector == Field.TermVector.WITH_OFFSETS) {
144  885 this.storeTermVector = true;
145  885 this.storePositionWithTermVector = false;
146  885 this.storeOffsetWithTermVector = true;
147    }
148  928 else if (termVector == Field.TermVector.WITH_POSITIONS_OFFSETS) {
149  928 this.storeTermVector = true;
150  928 this.storePositionWithTermVector = true;
151  928 this.storeOffsetWithTermVector = true;
152    }
153    else {
154  0 throw new IllegalArgumentException("unknown termVector parameter " + termVector);
155    }
156    }
157   
158    /** True iff the value of the field is to be stored in the index for return
159    with search hits. It is an error for this to be true if a field is
160    Reader-valued. */
 
161  4975319 toggle public final boolean isStored() { return isStored; }
162   
163    /** True iff the value of the field is to be indexed, so that it may be
164    searched on. */
 
165  1033165 toggle public final boolean isIndexed() { return isIndexed; }
166   
167    /** True iff the value of the field should be tokenized as text prior to
168    indexing. Un-tokenized fields are indexed as a single word and may not be
169    Reader-valued. */
 
170  2985549 toggle public final boolean isTokenized() { return isTokenized; }
171   
172    /** True if the value of the field is stored and compressed within the index */
 
173  4939566 toggle public final boolean isCompressed() { return isCompressed; }
174   
175    /** True iff the term or terms used to index this field are stored as a term
176    * vector, available from {@link org.apache.lucene.index.IndexReader#getTermFreqVector(int,String)}.
177    * These methods do not provide access to the original content of the field,
178    * only to terms used to index it. If the original content must be
179    * preserved, use the <code>stored</code> attribute instead.
180    *
181    * @see org.apache.lucene.index.IndexReader#getTermFreqVector(int, String)
182    */
 
183  516684 toggle public final boolean isTermVectorStored() { return storeTermVector; }
184   
185    /**
186    * True iff terms are stored as term vector together with their offsets
187    * (start and end positon in source text).
188    */
 
189  2630849 toggle public boolean isStoreOffsetWithTermVector(){
190  2630849 return storeOffsetWithTermVector;
191    }
192   
193    /**
194    * True iff terms are stored as term vector together with their token positions.
195    */
 
196  516500 toggle public boolean isStorePositionWithTermVector(){
197  516500 return storePositionWithTermVector;
198    }
199   
200    /** True iff the value of the filed is stored as binary */
 
201  4942813 toggle public final boolean isBinary() { return isBinary; }
202   
203    /** True if norms are omitted for this indexed field */
 
204  516634 toggle public boolean getOmitNorms() { return omitNorms; }
205   
206    /** Expert:
207    *
208    * If set, omit normalization factors associated with this indexed field.
209    * This effectively disables indexing boosts and length normalization for this field.
210    */
 
211  310825 toggle public void setOmitNorms(boolean omitNorms) { this.omitNorms=omitNorms; }
212   
 
213  102 toggle public boolean isLazy() {
214  102 return lazy;
215    }
216   
217    /** Prints a Field for human consumption. */
 
218  40 toggle public final String toString() {
219  40 StringBuffer result = new StringBuffer();
220  40 if (isStored) {
221  40 result.append("stored");
222  40 if (isCompressed)
223  0 result.append("/compressed");
224    else
225  40 result.append("/uncompressed");
226    }
227  40 if (isIndexed) {
228  40 if (result.length() > 0)
229  40 result.append(",");
230  40 result.append("indexed");
231    }
232  40 if (isTokenized) {
233  0 if (result.length() > 0)
234  0 result.append(",");
235  0 result.append("tokenized");
236    }
237  40 if (storeTermVector) {
238  0 if (result.length() > 0)
239  0 result.append(",");
240  0 result.append("termVector");
241    }
242  40 if (storeOffsetWithTermVector) {
243  0 if (result.length() > 0)
244  0 result.append(",");
245  0 result.append("termVectorOffsets");
246    }
247  40 if (storePositionWithTermVector) {
248  0 if (result.length() > 0)
249  0 result.append(",");
250  0 result.append("termVectorPosition");
251    }
252  40 if (isBinary) {
253  0 if (result.length() > 0)
254  0 result.append(",");
255  0 result.append("binary");
256    }
257  40 if (omitNorms) {
258  0 result.append(",omitNorms");
259    }
260  40 if (lazy){
261  0 result.append(",lazy");
262    }
263  40 result.append('<');
264  40 result.append(name);
265  40 result.append(':');
266   
267  40 if (fieldsData != null && lazy == false) {
268  40 result.append(fieldsData);
269    }
270   
271  40 result.append('>');
272  40 return result.toString();
273    }
274    }