001: package org.apache.lucene.index;
002:
003: /**
004: * Licensed to the Apache Software Foundation (ASF) under one or more
005: * contributor license agreements. See the NOTICE file distributed with
006: * this work for additional information regarding copyright ownership.
007: * The ASF licenses this file to You under the Apache License, Version 2.0
008: * (the "License"); you may not use this file except in compliance with
009: * the License. You may obtain a copy of the License at
010: *
011: * http://www.apache.org/licenses/LICENSE-2.0
012: *
013: * Unless required by applicable law or agreed to in writing, software
014: * distributed under the License is distributed on an "AS IS" BASIS,
015: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: * See the License for the specific language governing permissions and
017: * limitations under the License.
018: */
019:
020: /**
021: * Useful constants representing filenames and extensions used by lucene
022: *
023: * @author Bernhard Messer
024: * @version $rcs = ' $Id: Exp $ ' ;
025: */
026: final class IndexFileNames {
027:
028: /** Name of the index segment file */
029: static final String SEGMENTS = "segments";
030:
031: /** Name of the generation reference file name */
032: static final String SEGMENTS_GEN = "segments.gen";
033:
034: /** Name of the index deletable file (only used in
035: * pre-lockless indices) */
036: static final String DELETABLE = "deletable";
037:
038: /** Extension of norms file */
039: static final String NORMS_EXTENSION = "nrm";
040:
041: /** Extension of freq postings file */
042: static final String FREQ_EXTENSION = "frq";
043:
044: /** Extension of prox postings file */
045: static final String PROX_EXTENSION = "prx";
046:
047: /** Extension of terms file */
048: static final String TERMS_EXTENSION = "tis";
049:
050: /** Extension of terms index file */
051: static final String TERMS_INDEX_EXTENSION = "tii";
052:
053: /** Extension of stored fields index file */
054: static final String FIELDS_INDEX_EXTENSION = "fdx";
055:
056: /** Extension of stored fields file */
057: static final String FIELDS_EXTENSION = "fdt";
058:
059: /** Extension of vectors fields file */
060: static final String VECTORS_FIELDS_EXTENSION = "tvf";
061:
062: /** Extension of vectors documents file */
063: static final String VECTORS_DOCUMENTS_EXTENSION = "tvd";
064:
065: /** Extension of vectors index file */
066: static final String VECTORS_INDEX_EXTENSION = "tvx";
067:
068: /** Extension of compound file */
069: static final String COMPOUND_FILE_EXTENSION = "cfs";
070:
071: /** Extension of compound file for doc store files*/
072: static final String COMPOUND_FILE_STORE_EXTENSION = "cfx";
073:
074: /** Extension of deletes */
075: static final String DELETES_EXTENSION = "del";
076:
077: /** Extension of field infos */
078: static final String FIELD_INFOS_EXTENSION = "fnm";
079:
080: /** Extension of plain norms */
081: static final String PLAIN_NORMS_EXTENSION = "f";
082:
083: /** Extension of separate norms */
084: static final String SEPARATE_NORMS_EXTENSION = "s";
085:
086: /** Extension of gen file */
087: static final String GEN_EXTENSION = "gen";
088:
089: /**
090: * This array contains all filename extensions used by
091: * Lucene's index files, with two exceptions, namely the
092: * extension made up from <code>.f</code> + a number and
093: * from <code>.s</code> + a number. Also note that
094: * Lucene's <code>segments_N</code> files do not have any
095: * filename extension.
096: */
097: static final String INDEX_EXTENSIONS[] = new String[] {
098: COMPOUND_FILE_EXTENSION, FIELD_INFOS_EXTENSION,
099: FIELDS_INDEX_EXTENSION, FIELDS_EXTENSION,
100: TERMS_INDEX_EXTENSION, TERMS_EXTENSION, FREQ_EXTENSION,
101: PROX_EXTENSION, DELETES_EXTENSION, VECTORS_INDEX_EXTENSION,
102: VECTORS_DOCUMENTS_EXTENSION, VECTORS_FIELDS_EXTENSION,
103: GEN_EXTENSION, NORMS_EXTENSION,
104: COMPOUND_FILE_STORE_EXTENSION, };
105:
106: /** File extensions that are added to a compound file
107: * (same as above, minus "del", "gen", "cfs"). */
108: static final String[] INDEX_EXTENSIONS_IN_COMPOUND_FILE = new String[] {
109: FIELD_INFOS_EXTENSION, FIELDS_INDEX_EXTENSION,
110: FIELDS_EXTENSION, TERMS_INDEX_EXTENSION, TERMS_EXTENSION,
111: FREQ_EXTENSION, PROX_EXTENSION, VECTORS_INDEX_EXTENSION,
112: VECTORS_DOCUMENTS_EXTENSION, VECTORS_FIELDS_EXTENSION,
113: NORMS_EXTENSION };
114:
115: static final String[] STORE_INDEX_EXTENSIONS = new String[] {
116: VECTORS_INDEX_EXTENSION, VECTORS_FIELDS_EXTENSION,
117: VECTORS_DOCUMENTS_EXTENSION, FIELDS_INDEX_EXTENSION,
118: FIELDS_EXTENSION };
119:
120: static final String[] NON_STORE_INDEX_EXTENSIONS = new String[] {
121: FIELD_INFOS_EXTENSION, FREQ_EXTENSION, PROX_EXTENSION,
122: TERMS_EXTENSION, TERMS_INDEX_EXTENSION, NORMS_EXTENSION };
123:
124: /** File extensions of old-style index files */
125: static final String COMPOUND_EXTENSIONS[] = new String[] {
126: FIELD_INFOS_EXTENSION, FREQ_EXTENSION, PROX_EXTENSION,
127: FIELDS_INDEX_EXTENSION, FIELDS_EXTENSION,
128: TERMS_INDEX_EXTENSION, TERMS_EXTENSION };
129:
130: /** File extensions for term vector support */
131: static final String VECTOR_EXTENSIONS[] = new String[] {
132: VECTORS_INDEX_EXTENSION, VECTORS_DOCUMENTS_EXTENSION,
133: VECTORS_FIELDS_EXTENSION };
134:
135: /**
136: * Computes the full file name from base, extension and
137: * generation. If the generation is -1, the file name is
138: * null. If it's 0, the file name is <base><extension>.
139: * If it's > 0, the file name is <base>_<generation><extension>.
140: *
141: * @param base -- main part of the file name
142: * @param extension -- extension of the filename (including .)
143: * @param gen -- generation
144: */
145: static final String fileNameFromGeneration(String base,
146: String extension, long gen) {
147: if (gen == SegmentInfo.NO) {
148: return null;
149: } else if (gen == SegmentInfo.WITHOUT_GEN) {
150: return base + extension;
151: } else {
152: return base + "_" + Long.toString(gen, Character.MAX_RADIX)
153: + extension;
154: }
155: }
156:
157: /**
158: * Returns true if the provided filename is one of the doc
159: * store files (ends with an extension in
160: * STORE_INDEX_EXTENSIONS).
161: */
162: static final boolean isDocStoreFile(String fileName) {
163: if (fileName.endsWith(COMPOUND_FILE_STORE_EXTENSION))
164: return true;
165: for (int i = 0; i < STORE_INDEX_EXTENSIONS.length; i++)
166: if (fileName.endsWith(STORE_INDEX_EXTENSIONS[i]))
167: return true;
168: return false;
169: }
170: }
|