pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / src / java / org / apache / lucene / index / FieldInfo.java
1 package org.apache.lucene.index;
2
3 /**
4  * Licensed to the Apache Software Foundation (ASF) under one or more
5  * contributor license agreements.  See the NOTICE file distributed with
6  * this work for additional information regarding copyright ownership.
7  * The ASF licenses this file to You under the Apache License, Version 2.0
8  * (the "License"); you may not use this file except in compliance with
9  * the License.  You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 /** @lucene.experimental */
21 public final class FieldInfo {
22   final String name;
23   final int number;
24
25   boolean isIndexed;
26
27   // true if term vector for this field should be stored
28   boolean storeTermVector;
29   boolean storeOffsetWithTermVector;
30   boolean storePositionWithTermVector;
31
32   public boolean omitNorms; // omit norms associated with indexed fields  
33   public IndexOptions indexOptions;
34   
35   boolean storePayloads; // whether this field stores payloads together with term positions
36
37   /**
38    * Controls how much information is stored in the postings lists.
39    * @lucene.experimental
40    */
41   public static enum IndexOptions { 
42     /** only documents are indexed: term frequencies and positions are omitted */
43     DOCS_ONLY,
44     /** only documents and term frequencies are indexed: positions are omitted */  
45     DOCS_AND_FREQS,
46     /** full postings: documents, frequencies, and positions */
47     DOCS_AND_FREQS_AND_POSITIONS 
48   };
49
50   FieldInfo(String na, boolean tk, int nu, boolean storeTermVector, 
51             boolean storePositionWithTermVector,  boolean storeOffsetWithTermVector, 
52             boolean omitNorms, boolean storePayloads, IndexOptions indexOptions) {
53     name = na;
54     isIndexed = tk;
55     number = nu;
56     if (isIndexed) {
57       this.storeTermVector = storeTermVector;
58       this.storeOffsetWithTermVector = storeOffsetWithTermVector;
59       this.storePositionWithTermVector = storePositionWithTermVector;
60       this.storePayloads = storePayloads;
61       this.omitNorms = omitNorms;
62       this.indexOptions = indexOptions;
63     } else { // for non-indexed fields, leave defaults
64       this.storeTermVector = false;
65       this.storeOffsetWithTermVector = false;
66       this.storePositionWithTermVector = false;
67       this.storePayloads = false;
68       this.omitNorms = true;
69       this.indexOptions = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS;
70     }
71     assert indexOptions == IndexOptions.DOCS_AND_FREQS_AND_POSITIONS || !storePayloads;
72   }
73
74   @Override
75   public Object clone() {
76     return new FieldInfo(name, isIndexed, number, storeTermVector, storePositionWithTermVector,
77                          storeOffsetWithTermVector, omitNorms, storePayloads, indexOptions);
78   }
79
80   void update(boolean isIndexed, boolean storeTermVector, boolean storePositionWithTermVector, 
81               boolean storeOffsetWithTermVector, boolean omitNorms, boolean storePayloads, IndexOptions indexOptions) {
82
83     if (this.isIndexed != isIndexed) {
84       this.isIndexed = true;                      // once indexed, always index
85     }
86     if (isIndexed) { // if updated field data is not for indexing, leave the updates out
87       if (this.storeTermVector != storeTermVector) {
88         this.storeTermVector = true;                // once vector, always vector
89       }
90       if (this.storePositionWithTermVector != storePositionWithTermVector) {
91         this.storePositionWithTermVector = true;                // once vector, always vector
92       }
93       if (this.storeOffsetWithTermVector != storeOffsetWithTermVector) {
94         this.storeOffsetWithTermVector = true;                // once vector, always vector
95       }
96       if (this.storePayloads != storePayloads) {
97         this.storePayloads = true;
98       }
99       if (this.omitNorms != omitNorms) {
100         this.omitNorms = false;                // once norms are stored, always store
101       }
102       if (this.indexOptions != indexOptions) {
103         // downgrade
104         this.indexOptions = this.indexOptions.compareTo(indexOptions) < 0 ? this.indexOptions : indexOptions;
105         this.storePayloads = false;
106       }
107     }
108     assert this.indexOptions == IndexOptions.DOCS_AND_FREQS_AND_POSITIONS || !this.storePayloads;
109   }
110 }