1 package org.apache.lucene.index;
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 /** @lucene.experimental */
21 public final class FieldInfo {
27 // true if term vector for this field should be stored
28 boolean storeTermVector;
29 boolean storeOffsetWithTermVector;
30 boolean storePositionWithTermVector;
32 public boolean omitNorms; // omit norms associated with indexed fields
33 public IndexOptions indexOptions;
35 boolean storePayloads; // whether this field stores payloads together with term positions
38 * Controls how much information is stored in the postings lists.
39 * @lucene.experimental
41 public static enum IndexOptions {
42 /** only documents are indexed: term frequencies and positions are omitted */
44 /** only documents and term frequencies are indexed: positions are omitted */
46 /** full postings: documents, frequencies, and positions */
47 DOCS_AND_FREQS_AND_POSITIONS
50 FieldInfo(String na, boolean tk, int nu, boolean storeTermVector,
51 boolean storePositionWithTermVector, boolean storeOffsetWithTermVector,
52 boolean omitNorms, boolean storePayloads, IndexOptions indexOptions) {
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;
71 assert indexOptions == IndexOptions.DOCS_AND_FREQS_AND_POSITIONS || !storePayloads;
75 public Object clone() {
76 return new FieldInfo(name, isIndexed, number, storeTermVector, storePositionWithTermVector,
77 storeOffsetWithTermVector, omitNorms, storePayloads, indexOptions);
80 void update(boolean isIndexed, boolean storeTermVector, boolean storePositionWithTermVector,
81 boolean storeOffsetWithTermVector, boolean omitNorms, boolean storePayloads, IndexOptions indexOptions) {
83 if (this.isIndexed != isIndexed) {
84 this.isIndexed = true; // once indexed, always index
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
90 if (this.storePositionWithTermVector != storePositionWithTermVector) {
91 this.storePositionWithTermVector = true; // once vector, always vector
93 if (this.storeOffsetWithTermVector != storeOffsetWithTermVector) {
94 this.storeOffsetWithTermVector = true; // once vector, always vector
96 if (this.storePayloads != storePayloads) {
97 this.storePayloads = true;
99 if (this.omitNorms != omitNorms) {
100 this.omitNorms = false; // once norms are stored, always store
102 if (this.indexOptions != indexOptions) {
104 this.indexOptions = this.indexOptions.compareTo(indexOptions) < 0 ? this.indexOptions : indexOptions;
105 this.storePayloads = false;
108 assert this.indexOptions == IndexOptions.DOCS_AND_FREQS_AND_POSITIONS || !this.storePayloads;