Clover Coverage Report
Coverage timestamp: Fri May 9 2008 10:54:27 EST
../../../../img/srcFileCovDistChart9.png 37% of files have more coverage
148   315   50   16.44
68   201   0.34   9
9     5.56  
1    
 
  TermVectorsReader       Line # 27 148 50 85.3% 0.85333335
 
  (21)
 
1    package org.apache.lucene.index;
2   
3    /**
4    * Copyright 2004 The Apache Software Foundation
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10    * http://www.apache.org/licenses/LICENSE-2.0
11    *
12    * Unless required by applicable law or agreed to in writing, software
13    * distributed under the License is distributed on an "AS IS" BASIS,
14    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15    * See the License for the specific language governing permissions and
16    * limitations under the License.
17    */
18   
19    import org.apache.lucene.store.Directory;
20    import org.apache.lucene.store.IndexInput;
21   
22    import java.io.IOException;
23   
24    /**
25    * @version $Id: TermVectorsReader.java 413201 2006-06-10 01:23:22Z gsingers $
26    */
 
27    class TermVectorsReader implements Cloneable {
28    private FieldInfos fieldInfos;
29   
30    private IndexInput tvx;
31    private IndexInput tvd;
32    private IndexInput tvf;
33    private int size;
34   
35    private int tvdFormat;
36    private int tvfFormat;
37   
 
38  5761 toggle TermVectorsReader(Directory d, String segment, FieldInfos fieldInfos)
39    throws IOException {
40  5761 if (d.fileExists(segment + TermVectorsWriter.TVX_EXTENSION)) {
41  5760 tvx = d.openInput(segment + TermVectorsWriter.TVX_EXTENSION);
42  5760 checkValidFormat(tvx);
43  5760 tvd = d.openInput(segment + TermVectorsWriter.TVD_EXTENSION);
44  5760 tvdFormat = checkValidFormat(tvd);
45  5760 tvf = d.openInput(segment + TermVectorsWriter.TVF_EXTENSION);
46  5760 tvfFormat = checkValidFormat(tvf);
47  5760 size = (int) tvx.length() / 8;
48    }
49   
50  5761 this.fieldInfos = fieldInfos;
51    }
52   
 
53  17280 toggle private int checkValidFormat(IndexInput in) throws IOException
54    {
55  17280 int format = in.readInt();
56  17280 if (format > TermVectorsWriter.FORMAT_VERSION)
57    {
58  0 throw new IOException("Incompatible format version: " + format + " expected "
59    + TermVectorsWriter.FORMAT_VERSION + " or less");
60    }
61  17280 return format;
62    }
63   
 
64  5722 toggle void close() throws IOException {
65    // make all effort to close up. Keep the first exception
66    // and throw it as a new one.
67  5722 IOException keep = null;
68  0 if (tvx != null) try { tvx.close(); } catch (IOException e) { if (keep == null) keep = e; }
69  0 if (tvd != null) try { tvd.close(); } catch (IOException e) { if (keep == null) keep = e; }
70  0 if (tvf != null) try { tvf.close(); } catch (IOException e) { if (keep == null) keep = e; }
71  0 if (keep != null) throw (IOException) keep.fillInStackTrace();
72    }
73   
74    /**
75    *
76    * @return The number of documents in the reader
77    */
 
78  0 toggle int size() {
79  0 return size;
80    }
81   
82    /**
83    * Retrieve the term vector for the given document and field
84    * @param docNum The document number to retrieve the vector for
85    * @param field The field within the document to retrieve
86    * @return The TermFreqVector for the document and field or null if there is no termVector for this field.
87    * @throws IOException if there is an error reading the term vector files
88    */
 
89  60058 toggle TermFreqVector get(int docNum, String field) throws IOException {
90    // Check if no term vectors are available for this segment at all
91  60058 int fieldNumber = fieldInfos.fieldNumber(field);
92  60059 TermFreqVector result = null;
93  60059 if (tvx != null) {
94    //We need to account for the FORMAT_SIZE at when seeking in the tvx
95    //We don't need to do this in other seeks because we already have the
96    // file pointer
97    //that was written in another file
98  60059 tvx.seek((docNum * 8L) + TermVectorsWriter.FORMAT_SIZE);
99    //System.out.println("TVX Pointer: " + tvx.getFilePointer());
100  60057 long position = tvx.readLong();
101   
102  60058 tvd.seek(position);
103  60058 int fieldCount = tvd.readVInt();
104    //System.out.println("Num Fields: " + fieldCount);
105    // There are only a few fields per document. We opt for a full scan
106    // rather then requiring that they be ordered. We need to read through
107    // all of the fields anyway to get to the tvf pointers.
108  60052 int number = 0;
109  60053 int found = -1;
110  120172 for (int i = 0; i < fieldCount; i++) {
111  60121 if(tvdFormat == TermVectorsWriter.FORMAT_VERSION)
112  60121 number = tvd.readVInt();
113    else
114  0 number += tvd.readVInt();
115   
116  60117 if (number == fieldNumber)
117  60052 found = i;
118    }
119   
120    // This field, although valid in the segment, was not found in this
121    // document
122  60054 if (found != -1) {
123    // Compute position in the tvf file
124  60053 position = 0;