add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / src / java / org / apache / lucene / index / TermVectorMapper.java
1 package org.apache.lucene.index;
2 /**
3  * Copyright 2007 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  * 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)}.
23  * <p/>
24  * It is up to the implementation to make sure it is thread-safe.
25  *
26  *
27  **/
28 public abstract class TermVectorMapper {
29
30   private boolean ignoringPositions;
31   private boolean ignoringOffsets;
32
33
34   protected TermVectorMapper() {
35   }
36
37   /**
38    *
39    * @param ignoringPositions true if this mapper should tell Lucene to ignore positions even if they are stored
40    * @param ignoringOffsets similar to ignoringPositions
41    */
42   protected TermVectorMapper(boolean ignoringPositions, boolean ignoringOffsets) {
43     this.ignoringPositions = ignoringPositions;
44     this.ignoringOffsets = ignoringOffsets;
45   }
46
47   /**
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.
50    *
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
56    */
57   public abstract void setExpectations(String field, int numTerms, boolean storeOffsets, boolean storePositions);
58   /**
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
64    */
65   public abstract void map(String term, int frequency, TermVectorOffsetInfo [] offsets, int [] positions);
66
67   /**
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.
71    * @return false
72    */
73   public boolean isIgnoringPositions()
74   {
75     return ignoringPositions;
76   }
77
78   /**
79    *
80    * @see #isIgnoringPositions() Same principal as {@link #isIgnoringPositions()}, but applied to offsets.  false by default.
81    * @return false
82    */
83   public boolean isIgnoringOffsets()
84   {
85     return ignoringOffsets;
86   }
87
88   /**
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.
91    *<p/>
92    * Default implementation IGNORES the document number.  Override if your implementation needs the document number.
93    * <p/> 
94    * NOTE: Document numbers are internal to Lucene and subject to change depending on indexing operations.
95    *
96    * @param documentNumber index of document currently being mapped
97    */
98   public void setDocumentNumber(int documentNumber) {
99   }
100
101 }