1
package org.apache.lucene.index;
3
* Copyright 2007 The Apache Software Foundation
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
9
* http://www.apache.org/licenses/LICENSE-2.0
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.
20
* The TermVectorMapper can be used to map Term Vectors into your own
21
* structure instead of the parallel array structure used by
22
* {@link org.apache.lucene.index.IndexReader#getTermFreqVector(int,String)}.
24
* It is up to the implementation to make sure it is thread-safe.
28
public abstract class TermVectorMapper {
30
private boolean ignoringPositions;
31
private boolean ignoringOffsets;
34
protected TermVectorMapper() {
39
* @param ignoringPositions true if this mapper should tell Lucene to ignore positions even if they are stored
40
* @param ignoringOffsets similar to ignoringPositions
42
protected TermVectorMapper(boolean ignoringPositions, boolean ignoringOffsets) {
43
this.ignoringPositions = ignoringPositions;
44
this.ignoringOffsets = ignoringOffsets;
48
* Tell the mapper what to expect in regards to field, number of terms, offset and position storage.
49
* This method will be called once before retrieving the vector for a field.
51
* This method will be called before {@link #map(String,int,TermVectorOffsetInfo[],int[])}.
52
* @param field The field the vector is for
53
* @param numTerms The number of terms that need to be mapped
54
* @param storeOffsets true if the mapper should expect offset information
55
* @param storePositions true if the mapper should expect positions info
57
public abstract void setExpectations(String field, int numTerms, boolean storeOffsets, boolean storePositions);
59
* Map the Term Vector information into your own structure
60
* @param term The term to add to the vector
61
* @param frequency The frequency of the term in the document
62
* @param offsets null if the offset is not specified, otherwise the offset into the field of the term
63
* @param positions null if the position is not specified, otherwise the position in the field of the term
65
public abstract void map(String term, int frequency, TermVectorOffsetInfo [] offsets, int [] positions);
68
* Indicate to Lucene that even if there are positions stored, this mapper is not interested in them and they
69
* can be skipped over. Derived classes should set this to true if they want to ignore positions. The default
70
* is false, meaning positions will be loaded if they are stored.
73
public boolean isIgnoringPositions()
75
return ignoringPositions;
80
* @see #isIgnoringPositions() Same principal as {@link #isIgnoringPositions()}, but applied to offsets. false by default.
83
public boolean isIgnoringOffsets()
85
return ignoringOffsets;
89
* Passes down the index of the document whose term vector is currently being mapped,
90
* once for each top level call to a term vector reader.
92
* Default implementation IGNORES the document number. Override if your implementation needs the document number.
94
* NOTE: Document numbers are internal to Lucene and subject to change depending on indexing operations.
96
* @param documentNumber index of document currently being mapped
98
public void setDocumentNumber(int documentNumber) {