pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / src / java / org / apache / lucene / index / FieldInvertState.java
1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  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 package org.apache.lucene.index;
18
19 import org.apache.lucene.util.AttributeSource;
20
21 /**
22  * This class tracks the number and position / offset parameters of terms
23  * being added to the index. The information collected in this class is
24  * also used to calculate the normalization factor for a field.
25  * 
26  * @lucene.experimental
27  */
28 public final class FieldInvertState {
29   int position;
30   int length;
31   int numOverlap;
32   int offset;
33   int maxTermFrequency;
34   int uniqueTermCount;
35   float boost;
36   AttributeSource attributeSource;
37
38   public FieldInvertState() {
39   }
40
41   public FieldInvertState(int position, int length, int numOverlap, int offset, float boost) {
42     this.position = position;
43     this.length = length;
44     this.numOverlap = numOverlap;
45     this.offset = offset;
46     this.boost = boost;
47   }
48
49   /**
50    * Re-initialize the state, using this boost value.
51    * @param docBoost boost value to use.
52    */
53   void reset(float docBoost) {
54     position = 0;
55     length = 0;
56     numOverlap = 0;
57     offset = 0;
58     maxTermFrequency = 0;
59     uniqueTermCount = 0;
60     boost = docBoost;
61     attributeSource = null;
62   }
63
64   /**
65    * Get the last processed term position.
66    * @return the position
67    */
68   public int getPosition() {
69     return position;
70   }
71
72   /**
73    * Get total number of terms in this field.
74    * @return the length
75    */
76   public int getLength() {
77     return length;
78   }
79
80   public void setLength(int length) {
81     this.length = length;
82   }
83   
84   /**
85    * Get the number of terms with <code>positionIncrement == 0</code>.
86    * @return the numOverlap
87    */
88   public int getNumOverlap() {
89     return numOverlap;
90   }
91
92   public void setNumOverlap(int numOverlap) {
93     this.numOverlap = numOverlap;
94   }
95   
96   /**
97    * Get end offset of the last processed term.
98    * @return the offset
99    */
100   public int getOffset() {
101     return offset;
102   }
103
104   /**
105    * Get boost value. This is the cumulative product of
106    * document boost and field boost for all field instances
107    * sharing the same field name.
108    * @return the boost
109    */
110   public float getBoost() {
111     return boost;
112   }
113   
114   public void setBoost(float boost) {
115     this.boost = boost;
116   }
117
118   /**
119    * Get the maximum term-frequency encountered for any term in the field.  A
120    * field containing "the quick brown fox jumps over the lazy dog" would have
121    * a value of 2, because "the" appears twice.
122    */
123   public int getMaxTermFrequency() {
124     return maxTermFrequency;
125   }
126   
127   /**
128    * Return the number of unique terms encountered in this field.
129    */
130   public int getUniqueTermCount() {
131     return uniqueTermCount;
132   }
133   
134   public AttributeSource getAttributeSource() {
135     return attributeSource;
136   }
137 }