forked from apache/lucenenet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFieldType.cs
More file actions
405 lines (377 loc) · 14.3 KB
/
Copy pathFieldType.cs
File metadata and controls
405 lines (377 loc) · 14.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
using Lucene.Net.Index;
using Lucene.Net.Util;
using System;
using System.Text;
namespace Lucene.Net.Documents
{
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/// <summary>
/// Describes the properties of a field.
/// </summary>
public class FieldType : IIndexableFieldType
{
// LUCENENET specific: Moved the NumericType enum outside of this class
private bool indexed;
private bool stored;
private bool tokenized = true;
private bool storeTermVectors;
private bool storeTermVectorOffsets;
private bool storeTermVectorPositions;
private bool storeTermVectorPayloads;
private bool omitNorms;
private IndexOptions indexOptions = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS;
private NumericType numericType;
private bool frozen;
private int numericPrecisionStep = NumericUtils.PRECISION_STEP_DEFAULT;
private DocValuesType docValueType;
/// <summary>
/// Create a new mutable <see cref="FieldType"/> with all of the properties from <paramref name="ref"/>
/// </summary>
public FieldType(FieldType @ref)
{
this.indexed = @ref.IsIndexed;
this.stored = @ref.IsStored;
this.tokenized = @ref.IsTokenized;
this.storeTermVectors = @ref.StoreTermVectors;
this.storeTermVectorOffsets = @ref.StoreTermVectorOffsets;
this.storeTermVectorPositions = @ref.StoreTermVectorPositions;
this.storeTermVectorPayloads = @ref.StoreTermVectorPayloads;
this.omitNorms = @ref.OmitNorms;
this.indexOptions = @ref.IndexOptions;
this.docValueType = @ref.DocValueType;
this.numericType = @ref.NumericType;
// Do not copy frozen!
}
/// <summary>
/// Create a new <see cref="FieldType"/> with default properties.
/// </summary>
public FieldType()
{
}
private void CheckIfFrozen()
{
if (frozen)
{
throw IllegalStateException.Create("this FieldType is already frozen and cannot be changed");
}
}
/// <summary>
/// Prevents future changes. Note, it is recommended that this is called once
/// the <see cref="FieldType"/>'s properties have been set, to prevent unintentional state
/// changes.
/// </summary>
/// <returns><c>this</c></returns>
// LUCENENET specific - returning self to make it possible to chain this to newing up the class so we can set and freeze on a single line.
// This is especially important for static field initializers.
public virtual FieldType Freeze()
{
this.frozen = true;
return this;
}
/// <summary>
/// Set to <c>true</c> to index (invert) this field. The default is <c>false</c>.
/// </summary>
/// <exception cref="InvalidOperationException"> if this <see cref="FieldType"/> is frozen against
/// future modifications. </exception>
public virtual bool IsIndexed
{
get => this.indexed;
set
{
CheckIfFrozen();
this.indexed = value;
}
}
/// <summary>
/// Set to <c>true</c> to store this field. The default is <c>false</c>.
/// </summary>
/// <exception cref="InvalidOperationException"> if this <see cref="FieldType"/> is frozen against
/// future modifications. </exception>
public virtual bool IsStored
{
get => this.stored;
set
{
CheckIfFrozen();
this.stored = value;
}
}
/// <summary>
/// Set to <c>true</c> to tokenize this field's contents via the
/// configured <see cref="Analysis.Analyzer"/>. The default is <c>true</c>.
/// </summary>
/// <exception cref="InvalidOperationException"> if this <see cref="FieldType"/> is frozen against
/// future modifications. </exception>
public virtual bool IsTokenized
{
get => this.tokenized;
set
{
CheckIfFrozen();
this.tokenized = value;
}
}
/// <summary>
/// Set to <c>true</c> if this field's indexed form should be also stored
/// into term vectors. The default is <c>false</c>.
/// </summary>
/// <exception cref="InvalidOperationException"> if this <see cref="FieldType"/> is frozen against
/// future modifications. </exception>
public virtual bool StoreTermVectors
{
get => this.storeTermVectors;
set
{
CheckIfFrozen();
this.storeTermVectors = value;
}
}
/// <summary>
/// Set to <c>true</c> to also store token character offsets into the term
/// vector for this field. The default is <c>false</c>.
/// </summary>
/// <exception cref="InvalidOperationException"> if this <see cref="FieldType"/> is frozen against
/// future modifications. </exception>
public virtual bool StoreTermVectorOffsets
{
get => this.storeTermVectorOffsets;
set
{
CheckIfFrozen();
this.storeTermVectorOffsets = value;
}
}
/// <summary>
/// Set to <c>true</c> to also store token positions into the term
/// vector for this field. The default is <c>false</c>.
/// </summary>
/// <exception cref="InvalidOperationException"> if this <see cref="FieldType"/> is frozen against
/// future modifications. </exception>
public virtual bool StoreTermVectorPositions
{
get => this.storeTermVectorPositions;
set
{
CheckIfFrozen();
this.storeTermVectorPositions = value;
}
}
/// <summary>
/// Set to <c>true</c> to also store token payloads into the term
/// vector for this field. The default is <c>false</c>.
/// </summary>
/// <exception cref="InvalidOperationException"> if this <see cref="FieldType"/> is frozen against
/// future modifications. </exception>
public virtual bool StoreTermVectorPayloads
{
get => this.storeTermVectorPayloads;
set
{
CheckIfFrozen();
this.storeTermVectorPayloads = value;
}
}
/// <summary>
/// Set to <c>true</c> to omit normalization values for the field. The default is <c>false</c>.
/// </summary>
/// <exception cref="InvalidOperationException"> if this <see cref="FieldType"/> is frozen against
/// future modifications. </exception>
public virtual bool OmitNorms
{
get => this.omitNorms;
set
{
CheckIfFrozen();
this.omitNorms = value;
}
}
/// <summary>
/// Sets the indexing options for the field.
/// <para/>
/// The default is <see cref="IndexOptions.DOCS_AND_FREQS_AND_POSITIONS"/>.
/// </summary>
/// <exception cref="InvalidOperationException"> if this <see cref="FieldType"/> is frozen against
/// future modifications. </exception>
public virtual IndexOptions IndexOptions
{
get => this.indexOptions;
set
{
CheckIfFrozen();
this.indexOptions = value;
}
}
/// <summary>
/// Specifies the field's numeric type, or set to <see cref="NumericType.NONE"/> if the field has no numeric type.
/// If not <see cref="NumericType.NONE"/> then the field's value will be indexed numerically so that
/// <see cref="Search.NumericRangeQuery"/> can be used at search time.
/// <para/>
/// The default is <see cref="NumericType.NONE"/>.
/// </summary>
/// <exception cref="InvalidOperationException"> if this <see cref="FieldType"/> is frozen against
/// future modifications. </exception>
public virtual NumericType NumericType
{
get => this.numericType;
set
{
CheckIfFrozen();
numericType = value;
}
}
/// <summary>
/// Sets the numeric precision step for the field.
/// <para/>
/// This has no effect if <see cref="NumericType"/> is <see cref="NumericType.NONE"/>.
/// <para/>
/// The default is <see cref="NumericUtils.PRECISION_STEP_DEFAULT"/>.
/// </summary>
/// <exception cref="ArgumentException"> if precisionStep is less than 1. </exception>
/// <exception cref="InvalidOperationException"> if this <see cref="FieldType"/> is frozen against
/// future modifications. </exception>
public virtual int NumericPrecisionStep
{
get => numericPrecisionStep;
set
{
CheckIfFrozen();
if (value < 1)
{
throw new ArgumentOutOfRangeException(nameof(NumericPrecisionStep), "precisionStep must be >= 1 (got " + value + ")"); // LUCENENET specific - changed from IllegalArgumentException to ArgumentOutOfRangeException (.NET convention)
}
this.numericPrecisionStep = value;
}
}
/// <summary>
/// Prints a <see cref="FieldType"/> for human consumption. </summary>
public override sealed string ToString()
{
var result = new StringBuilder();
if (IsStored)
{
result.Append("stored");
}
if (IsIndexed)
{
if (result.Length > 0)
{
result.Append(',');
}
result.Append("indexed");
if (IsTokenized)
{
result.Append(",tokenized");
}
if (StoreTermVectors)
{
result.Append(",termVector");
}
if (StoreTermVectorOffsets)
{
result.Append(",termVectorOffsets");
}
if (StoreTermVectorPositions)
{
result.Append(",termVectorPosition");
if (StoreTermVectorPayloads)
{
result.Append(",termVectorPayloads");
}
}
if (OmitNorms)
{
result.Append(",omitNorms");
}
if (indexOptions != IndexOptions.DOCS_AND_FREQS_AND_POSITIONS)
{
result.Append(",indexOptions=");
// LUCENENET: duplicate what would happen if you print a null indexOptions in Java
result.Append(indexOptions != IndexOptions.NONE ? indexOptions.ToString() : string.Empty);
}
if (numericType != NumericType.NONE)
{
result.Append(",numericType=");
result.Append(numericType);
result.Append(",numericPrecisionStep=");
result.Append(numericPrecisionStep);
}
}
if (docValueType != DocValuesType.NONE)
{
if (result.Length > 0)
{
result.Append(',');
}
result.Append("docValueType=");
result.Append(docValueType);
}
return result.ToString();
}
/// <summary>
/// Sets the field's <see cref="DocValuesType"/>, or set to <see cref="DocValuesType.NONE"/> if no <see cref="DocValues"/> should be stored.
/// <para/>
/// The default is <see cref="DocValuesType.NONE"/> (no <see cref="DocValues"/>).
/// </summary>
/// <exception cref="InvalidOperationException"> if this <see cref="FieldType"/> is frozen against
/// future modifications. </exception>
public virtual DocValuesType DocValueType
{
get => docValueType;
set
{
CheckIfFrozen();
docValueType = value;
}
}
}
/// <summary>
/// Data type of the numeric value
/// @since 3.2
/// </summary>
public enum NumericType
{
/// <summary>
/// No numeric type will be used.
/// <para/>
/// NOTE: This is the same as setting to <c>null</c> in Lucene
/// </summary>
// LUCENENET specific
NONE,
/// <summary>
/// 32-bit integer numeric type
/// <para/>
/// NOTE: This was INT in Lucene
/// </summary>
INT32,
/// <summary>
/// 64-bit long numeric type
/// <para/>
/// NOTE: This was LONG in Lucene
/// </summary>
INT64,
/// <summary>
/// 32-bit float numeric type
/// <para/>
/// NOTE: This was FLOAT in Lucene
/// </summary>
SINGLE,
/// <summary>
/// 64-bit double numeric type </summary>
DOUBLE
}
}