|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TermVectorsWriter | Line # 52 | 133 | 51 | 86.1% |
0.8605769
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TermVectorsWriter.TVField | Line # 353 | 3 | 1 | 100% |
1.0
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TermVectorsWriter.TVTerm | Line # 365 | 0 | 0 | - |
-1.0
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (11) | |||
| Result | |||
|
0.8490566
|
org.apache.lucene.index.TestIndexReader.testGetFieldNames
org.apache.lucene.index.TestIndexReader.testGetFieldNames
|
1 PASS | |
|
0.7971698
|
org.apache.lucene.index.TestSegmentMerger.testMerge
org.apache.lucene.index.TestSegmentMerger.testMerge
|
1 PASS | |
|
0.6839623
|
org.apache.lucene.index.TestDocumentWriter.testAddDocument
org.apache.lucene.index.TestDocumentWriter.testAddDocument
|
1 PASS | |
|
0.6839623
|
org.apache.lucene.index.TestFieldsReader.testLazyPerformance
org.apache.lucene.index.TestFieldsReader.testLazyPerformance
|
1 PASS | |
|
0.6839623
|
org.apache.lucene.index.TestSegmentReader.testDelete
org.apache.lucene.index.TestSegmentReader.testDelete
|
1 PASS | |
|
0.6698113
|
org.apache.lucene.search.TestTermVectors.testKnownSetOfDocuments
org.apache.lucene.search.TestTermVectors.testKnownSetOfDocuments
|
1 PASS | |
|
0.5849057
|
org.apache.lucene.index.TestTermVectorsWriter.testMultipleFields
org.apache.lucene.index.TestTermVectorsWriter.testMultipleFields
|
1 PASS | |
|
0.5849057
|
org.apache.lucene.index.TestTermVectorsWriter.testMultipleDocuments
org.apache.lucene.index.TestTermVectorsWriter.testMultipleDocuments
|
1 PASS | |
|
0.5849057
|
org.apache.lucene.index.TestTermVectorsWriter.testWriter
org.apache.lucene.index.TestTermVectorsWriter.testWriter
|
1 PASS | |
|
0.29245284
|
org.apache.lucene.index.TestTermVectorsWriter.testBadSegment
org.apache.lucene.index.TestTermVectorsWriter.testBadSegment
|
1 PASS | |
|
0.009433962
|
org.apache.lucene.index.TestTermVectorsReader.test
org.apache.lucene.index.TestTermVectorsReader.test
|
1 PASS | |
| 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.IndexOutput; | |
| 21 | import org.apache.lucene.util.StringHelper; | |
| 22 | ||
| 23 | import java.io.IOException; | |
| 24 | import java.util.Vector; | |
| 25 | ||
| 26 | /** | |
| 27 | * Writer works by opening a document and then opening the fields within the document and then | |
| 28 | * writing out the vectors for each field. | |
| 29 | * | |
| 30 | * Rough usage: | |
| 31 | * | |
| 32 | <CODE> | |
| 33 | for each document | |
| 34 | { | |
| 35 | writer.openDocument(); | |
| 36 | for each field on the document | |
| 37 | { | |
| 38 | writer.openField(field); | |
| 39 | for all of the terms | |
| 40 | { | |
| 41 | writer.addTerm(...) | |
| 42 | } | |
| 43 | writer.closeField | |
| 44 | } | |
| 45 | writer.closeDocument() | |
| 46 | } | |
| 47 | </CODE> | |
| 48 | * | |
| 49 | * @version $Id: TermVectorsWriter.java 413201 2006-06-10 01:23:22Z gsingers $ | |
| 50 | * | |
| 51 | */ | |
| 52 | final class TermVectorsWriter { | |
| 53 | static final byte STORE_POSITIONS_WITH_TERMVECTOR = 0x1; | |
| 54 | static final byte STORE_OFFSET_WITH_TERMVECTOR = 0x2; | |
| 55 | ||
| 56 | static final int FORMAT_VERSION = 2; | |
| 57 | //The size in bytes that the FORMAT_VERSION will take up at the beginning of each file | |
| 58 | static final int FORMAT_SIZE = 4; | |
| 59 | ||
| 60 | static final String TVX_EXTENSION = ".tvx"; | |
| 61 | static final String TVD_EXTENSION = ".tvd"; | |
| 62 | static final String TVF_EXTENSION = ".tvf"; | |
| 63 | ||
| 64 | private IndexOutput tvx = null, tvd = null, tvf = null; | |
| 65 | private Vector fields = null; | |
| 66 | private Vector terms = null; | |
| 67 | private FieldInfos fieldInfos; | |
| 68 | ||
| 69 | private TVField currentField = null; | |
| 70 | private long currentDocPointer = -1; | |
| 71 | ||
| 72 | 5786 |
public TermVectorsWriter(Directory directory, String segment, |
| 73 | FieldInfos fieldInfos) | |
| 74 | throws IOException { | |
| 75 | // Open files for TermVector storage | |
| 76 | 5786 | tvx = directory.createOutput(segment + TVX_EXTENSION); |
| 77 | 5786 | tvx.writeInt(FORMAT_VERSION); |
| 78 | 5786 | tvd = directory.createOutput(segment + TVD_EXTENSION); |
| 79 | 5786 | tvd.writeInt(FORMAT_VERSION); |
| 80 | 5786 | tvf = directory.createOutput(segment + TVF_EXTENSION); |
| 81 | 5786 | tvf.writeInt(FORMAT_VERSION); |
| 82 | ||
| 83 | 5786 | this.fieldInfos = fieldInfos; |
| 84 | 5786 | fields = new Vector(fieldInfos.size()); |
| 85 | 5786 | terms = new Vector(); |
| 86 | } | |
| 87 | ||
| 88 | ||
| 89 | 20478 |
public final void openDocument() |
| 90 | throws IOException { | |
| 91 | 20478 | closeDocument(); |
| 92 | 20478 | currentDocPointer = tvd.getFilePointer(); |
| 93 | } | |
| 94 | ||
| 95 | ||
| 96 | 46742 |
public final void closeDocument() |
| 97 | throws IOException { | |
| 98 | 46742 | if (isDocumentOpen()) { |
| 99 | 20478 | closeField(); |
| 100 | 20478 | writeDoc(); |
| 101 | 20478 | fields.clear(); |
| 102 | 20478 | currentDocPointer = -1; |
| 103 | } | |
| 104 | } | |
| 105 | ||
| 106 | ||
| 107 | 85984 |
public final boolean isDocumentOpen() { |
| 108 | 85984 | return currentDocPointer != -1; |
| 109 | } | |
| 110 | ||
| 111 | ||
| 112 | /** Start processing a field. This can be followed by a number of calls to | |
| 113 | * addTerm, and a final call to closeField to indicate the end of | |
| 114 | * processing of this field. If a field was previously open, it is | |
| 115 | * closed automatically. | |
| 116 | */ | |
| 117 | 5533 |
public final void openField(String field) throws IOException { |
| 118 | 5533 | FieldInfo fieldInfo = fieldInfos.fieldInfo(field); |
| 119 | 5533 | openField(fieldInfo.number, fieldInfo.storePositionWithTermVector, fieldInfo.storeOffsetWithTermVector); |
| 120 | } | |
| 121 | ||
| 122 | 20945 |
private void openField(int fieldNumber, boolean storePositionWithTermVector, |
| 123 | boolean storeOffsetWithTermVector) throws IOException{ | |
| 124 | 20945 | if (!isDocumentOpen()) |
| 125 | 0 | throw new IllegalStateException("Cannot open field when no document is open."); |
| 126 | 20945 | closeField(); |
| 127 | 20945 | currentField = new TVField(fieldNumber, storePositionWithTermVector, storeOffsetWithTermVector); |
| 128 | } | |
| 129 | ||
| 130 | /** Finished processing current field. This should be followed by a call to | |
| 131 | * openField before future calls to addTerm. | |
| 132 | */ | |