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 
18 using System;
19 using Lucene.Net.Support;
20 
21 namespace Lucene.Net.Index
22 {
23 
24 	/// <summary>Useful constants representing filenames and extensions used by lucene</summary>
25 	public sealed class IndexFileNames
26 	{
27 
28 		/// <summary>Name of the index segment file </summary>
29 		public /*internal*/ const System.String SEGMENTS = "segments";
30 
31 		/// <summary>Name of the generation reference file name </summary>
32 		public /*internal*/ const System.String SEGMENTS_GEN = "segments.gen";
33 
34 		/// <summary>Name of the index deletable file (only used in
35 		/// pre-lockless indices)
36 		/// </summary>
37 		public /*internal*/ const System.String DELETABLE = "deletable";
38 
39 		/// <summary>Extension of norms file </summary>
40 		public /*internal*/ const System.String NORMS_EXTENSION = "nrm";
41 
42 		/// <summary>Extension of freq postings file </summary>
43 		public /*internal*/ const System.String FREQ_EXTENSION = "frq";
44 
45 		/// <summary>Extension of prox postings file </summary>
46 		public /*internal*/ const System.String PROX_EXTENSION = "prx";
47 
48 		/// <summary>Extension of terms file </summary>
49 		public /*internal*/ const System.String TERMS_EXTENSION = "tis";
50 
51 		/// <summary>Extension of terms index file </summary>
52 		public /*internal*/ const System.String TERMS_INDEX_EXTENSION = "tii";
53 
54 		/// <summary>Extension of stored fields index file </summary>
55 		public /*internal*/ const System.String FIELDS_INDEX_EXTENSION = "fdx";
56 
57 		/// <summary>Extension of stored fields file </summary>
58 		public /*internal*/ const System.String FIELDS_EXTENSION = "fdt";
59 
60 		/// <summary>Extension of vectors fields file </summary>
61 		public /*internal*/ const System.String VECTORS_FIELDS_EXTENSION = "tvf";
62 
63 		/// <summary>Extension of vectors documents file </summary>
64 		public /*internal*/ const System.String VECTORS_DOCUMENTS_EXTENSION = "tvd";
65 
66 		/// <summary>Extension of vectors index file </summary>
67 		public /*internal*/ const System.String VECTORS_INDEX_EXTENSION = "tvx";
68 
69 		/// <summary>Extension of compound file </summary>
70 		public /*internal*/ const System.String COMPOUND_FILE_EXTENSION = "cfs";
71 
72 		/// <summary>Extension of compound file for doc store files</summary>
73 		public /*internal*/ const System.String COMPOUND_FILE_STORE_EXTENSION = "cfx";
74 
75 		/// <summary>Extension of deletes </summary>
76 		internal const System.String DELETES_EXTENSION = "del";
77 
78 		/// <summary>Extension of field infos </summary>
79 		public /*internal*/ const System.String FIELD_INFOS_EXTENSION = "fnm";
80 
81 		/// <summary>Extension of plain norms </summary>
82 		public /*internal*/ const System.String PLAIN_NORMS_EXTENSION = "f";
83 
84 		/// <summary>Extension of separate norms </summary>
85 		public /*internal*/ const System.String SEPARATE_NORMS_EXTENSION = "s";
86 
87 		/// <summary>Extension of gen file </summary>
88 		public /*internal*/ const System.String GEN_EXTENSION = "gen";
89 
90 		/// <summary> This array contains all filename extensions used by
91 		/// Lucene's index files, with two exceptions, namely the
92 		/// extension made up from <c>.f</c> + a number and
93 		/// from <c>.s</c> + a number.  Also note that
94 		/// Lucene's <c>segments_N</c> files do not have any
95 		/// filename extension.
96 		/// </summary>
97 		public /*internal*/ static readonly System.String[] INDEX_EXTENSIONS = new System.String[]{COMPOUND_FILE_EXTENSION, FIELD_INFOS_EXTENSION, FIELDS_INDEX_EXTENSION, FIELDS_EXTENSION, TERMS_INDEX_EXTENSION, TERMS_EXTENSION, FREQ_EXTENSION, PROX_EXTENSION, DELETES_EXTENSION, VECTORS_INDEX_EXTENSION, VECTORS_DOCUMENTS_EXTENSION, VECTORS_FIELDS_EXTENSION, GEN_EXTENSION, NORMS_EXTENSION, COMPOUND_FILE_STORE_EXTENSION};
98 
99 		/// <summary>File extensions that are added to a compound file
100 		/// (same as above, minus "del", "gen", "cfs").
101 		/// </summary>
102 		public /*internal*/ static readonly System.String[] INDEX_EXTENSIONS_IN_COMPOUND_FILE = new System.String[]{FIELD_INFOS_EXTENSION, FIELDS_INDEX_EXTENSION, FIELDS_EXTENSION, TERMS_INDEX_EXTENSION, TERMS_EXTENSION, FREQ_EXTENSION, PROX_EXTENSION, VECTORS_INDEX_EXTENSION, VECTORS_DOCUMENTS_EXTENSION, VECTORS_FIELDS_EXTENSION, NORMS_EXTENSION};
103 
104 		public /*internal*/ static readonly System.String[] STORE_INDEX_EXTENSIONS = new System.String[]{VECTORS_INDEX_EXTENSION, VECTORS_FIELDS_EXTENSION, VECTORS_DOCUMENTS_EXTENSION, FIELDS_INDEX_EXTENSION, FIELDS_EXTENSION};
105 
106 		public /*internal*/ static readonly System.String[] NON_STORE_INDEX_EXTENSIONS = new System.String[]{FIELD_INFOS_EXTENSION, FREQ_EXTENSION, PROX_EXTENSION, TERMS_EXTENSION, TERMS_INDEX_EXTENSION, NORMS_EXTENSION};
107 
108 		/// <summary>File extensions of old-style index files </summary>
109 		public /*internal*/ static readonly System.String[] COMPOUND_EXTENSIONS = new System.String[]{FIELD_INFOS_EXTENSION, FREQ_EXTENSION, PROX_EXTENSION, FIELDS_INDEX_EXTENSION, FIELDS_EXTENSION, TERMS_INDEX_EXTENSION, TERMS_EXTENSION};
110 
111 		/// <summary>File extensions for term vector support </summary>
112 		public /*internal*/ static readonly System.String[] VECTOR_EXTENSIONS = new System.String[]{VECTORS_INDEX_EXTENSION, VECTORS_DOCUMENTS_EXTENSION, VECTORS_FIELDS_EXTENSION};
113 
114 		/// <summary> Computes the full file name from base, extension and
115 		/// generation.  If the generation is -1, the file name is
116 		/// null.  If it's 0, the file name is
117 		/// If it's > 0, the file name is
118 		///
119 		/// </summary>
120         /// <param name="base_Renamed">-- main part of the file name
121 		/// </param>
122 		/// <param name="extension">-- extension of the filename (including .)
123 		/// </param>
124 		/// <param name="gen">-- generation
125 		/// </param>
FileNameFromGeneration(System.String base_Renamed, System.String extension, long gen)126 		public /*internal*/ static System.String FileNameFromGeneration(System.String base_Renamed, System.String extension, long gen)
127 		{
128 			if (gen == SegmentInfo.NO)
129 			{
130 				return null;
131 			}
132 			else if (gen == SegmentInfo.WITHOUT_GEN)
133 			{
134 				return base_Renamed + extension;
135 			}
136 			else
137 			{
138 #if !PRE_LUCENE_NET_2_0_0_COMPATIBLE
139 				return base_Renamed + "_" + Number.ToString(gen) + extension;
140 #else
141 				return base_Renamed + "_" + System.Convert.ToString(gen, 16) + extension;
142 #endif
143 			}
144 		}
145 
146 		/// <summary> Returns true if the provided filename is one of the doc
147 		/// store files (ends with an extension in
148 		/// STORE_INDEX_EXTENSIONS).
149 		/// </summary>
IsDocStoreFile(System.String fileName)150 		internal static bool IsDocStoreFile(System.String fileName)
151 		{
152 			if (fileName.EndsWith(COMPOUND_FILE_STORE_EXTENSION))
153 				return true;
154 			for (int i = 0; i < STORE_INDEX_EXTENSIONS.Length; i++)
155 				if (fileName.EndsWith(STORE_INDEX_EXTENSIONS[i]))
156 					return true;
157 			return false;
158 		}
159 
SegmentFileName(System.String segmentName, System.String ext)160 		internal static System.String SegmentFileName(System.String segmentName, System.String ext)
161 		{
162 			return segmentName + "." + ext;
163 		}
164 	}
165 }