-
Notifications
You must be signed in to change notification settings - Fork 624
/
AtomicReader.cs
334 lines (309 loc) · 12 KB
/
AtomicReader.cs
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
using Lucene.Net.Diagnostics;
using System.Diagnostics;
using System;
namespace Lucene.Net.Index
{
/*
* 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.
*/
// javadocs
using IBits = Lucene.Net.Util.IBits;
/// <summary>
/// <see cref="AtomicReader"/> is an abstract class, providing an interface for accessing an
/// index. Search of an index is done entirely through this abstract interface,
/// so that any subclass which implements it is searchable. <see cref="IndexReader"/>s implemented
/// by this subclass do not consist of several sub-readers,
/// they are atomic. They support retrieval of stored fields, doc values, terms,
/// and postings.
///
/// <para/>For efficiency, in this API documents are often referred to via
/// <i>document numbers</i>, non-negative integers which each name a unique
/// document in the index. These document numbers are ephemeral -- they may change
/// as documents are added to and deleted from an index. Clients should thus not
/// rely on a given document having the same number between sessions.
///
/// <para/>
/// <b>NOTE</b>: <see cref="IndexReader"/>
/// instances are completely thread
/// safe, meaning multiple threads can call any of its methods,
/// concurrently. If your application requires external
/// synchronization, you should <b>not</b> synchronize on the
/// <see cref="IndexReader"/> instance; use your own
/// (non-Lucene) objects instead.
/// </summary>
public abstract class AtomicReader : IndexReader
{
private readonly AtomicReaderContext readerContext; // LUCENENET: marked readonly
/// <summary>
/// Sole constructor. (For invocation by subclass
/// constructors, typically implicit.)
/// </summary>
protected AtomicReader()
: base()
{
readerContext = new AtomicReaderContext(this);
}
public sealed override IndexReaderContext Context
{
get
{
EnsureOpen();
return readerContext;
}
}
/// <summary>
/// LUCENENET specific propety that allows access to
/// the context as <see cref="AtomicReaderContext"/>,
/// which prevents the need to cast.
/// </summary>
public AtomicReaderContext AtomicContext
{
get
{
EnsureOpen();
return readerContext;
}
}
/// <summary>
/// Returns true if there are norms stored for this <paramref name="field"/>.
/// </summary>
[Obsolete("(4.0) use FieldInfos and check FieldInfo.HasNorms for the field instead.")]
public bool HasNorms(string field)
{
EnsureOpen();
// note: using normValues(field) != null would potentially cause i/o
FieldInfo fi = FieldInfos.FieldInfo(field);
return fi != null && fi.HasNorms;
}
/// <summary>
/// Returns <see cref="Index.Fields"/> for this reader.
/// this property may return <c>null</c> if the reader has no
/// postings.
/// </summary>
public abstract Fields Fields { get; }
public override sealed int DocFreq(Term term)
{
Fields fields = Fields;
if (fields == null)
{
return 0;
}
Terms terms = fields.GetTerms(term.Field);
if (terms == null)
{
return 0;
}
TermsEnum termsEnum = terms.GetEnumerator();
if (termsEnum.SeekExact(term.Bytes))
{
return termsEnum.DocFreq;
}
else
{
return 0;
}
}
/// <summary>
/// Returns the number of documents containing the <paramref name="term"/>.
/// This method returns 0 if the term or
/// field does not exist. This method does not take into
/// account deleted documents that have not yet been merged
/// away.
/// </summary>
public override sealed long TotalTermFreq(Term term)
{
Fields fields = Fields;
if (fields == null)
{
return 0;
}
Terms terms = fields.GetTerms(term.Field);
if (terms == null)
{
return 0;
}
TermsEnum termsEnum = terms.GetEnumerator();
if (termsEnum.SeekExact(term.Bytes))
{
return termsEnum.TotalTermFreq;
}
else
{
return 0;
}
}
public override sealed long GetSumDocFreq(string field)
{
Terms terms = GetTerms(field);
if (terms == null)
{
return 0;
}
return terms.SumDocFreq;
}
public override sealed int GetDocCount(string field)
{
Terms terms = GetTerms(field);
if (terms == null)
{
return 0;
}
return terms.DocCount;
}
public override sealed long GetSumTotalTermFreq(string field)
{
Terms terms = GetTerms(field);
if (terms == null)
{
return 0;
}
return terms.SumTotalTermFreq;
}
/// <summary>
/// This may return <c>null</c> if the field does not exist. </summary>
public Terms GetTerms(string field) // LUCENENET specific: Renamed from Terms()
{
Fields fields = Fields;
if (fields == null)
{
return null;
}
return fields.GetTerms(field);
}
/// <summary>
/// Returns <see cref="DocsEnum"/> for the specified term.
/// This will return <c>null</c> if either the field or
/// term does not exist.
/// </summary>
/// <seealso cref="TermsEnum.Docs(IBits, DocsEnum)"/>
public DocsEnum GetTermDocsEnum(Term term) // LUCENENET specific: Renamed from TermDocsEnum()
{
if (Debugging.AssertsEnabled)
{
Debugging.Assert(term.Field != null);
Debugging.Assert(term.Bytes != null);
}
Fields fields = Fields;
if (fields != null)
{
Terms terms = fields.GetTerms(term.Field);
if (terms != null)
{
TermsEnum termsEnum = terms.GetEnumerator();
if (termsEnum.SeekExact(term.Bytes))
{
return termsEnum.Docs(LiveDocs, null);
}
}
}
return null;
}
/// <summary>
/// Returns <see cref="DocsAndPositionsEnum"/> for the specified
/// term. This will return <c>null</c> if the
/// field or term does not exist or positions weren't indexed. </summary>
/// <seealso cref="TermsEnum.DocsAndPositions(IBits, DocsAndPositionsEnum)"/>
public DocsAndPositionsEnum GetTermPositionsEnum(Term term) // LUCENENET specific: Renamed from TermPositionsEnum()
{
if (Debugging.AssertsEnabled) Debugging.Assert(term.Field != null);
if (Debugging.AssertsEnabled) Debugging.Assert(term.Bytes != null);
Fields fields = Fields;
if (fields != null)
{
Terms terms = fields.GetTerms(term.Field);
if (terms != null)
{
TermsEnum termsEnum = terms.GetEnumerator();
if (termsEnum.SeekExact(term.Bytes))
{
return termsEnum.DocsAndPositions(LiveDocs, null);
}
}
}
return null;
}
/// <summary>
/// Returns <see cref="NumericDocValues"/> for this field, or
/// null if no <see cref="NumericDocValues"/> were indexed for
/// this field. The returned instance should only be
/// used by a single thread.
/// </summary>
public abstract NumericDocValues GetNumericDocValues(string field);
/// <summary>
/// Returns <see cref="BinaryDocValues"/> for this field, or
/// <c>null</c> if no <see cref="BinaryDocValues"/> were indexed for
/// this field. The returned instance should only be
/// used by a single thread.
/// </summary>
public abstract BinaryDocValues GetBinaryDocValues(string field);
/// <summary>
/// Returns <see cref="SortedDocValues"/> for this field, or
/// <c>null</c> if no <see cref="SortedDocValues"/> were indexed for
/// this field. The returned instance should only be
/// used by a single thread.
/// </summary>
public abstract SortedDocValues GetSortedDocValues(string field);
/// <summary>
/// Returns <see cref="SortedSetDocValues"/> for this field, or
/// <c>null</c> if no <see cref="SortedSetDocValues"/> were indexed for
/// this field. The returned instance should only be
/// used by a single thread.
/// </summary>
public abstract SortedSetDocValues GetSortedSetDocValues(string field);
/// <summary>
/// Returns a <see cref="IBits"/> at the size of <c>reader.MaxDoc</c>,
/// with turned on bits for each docid that does have a value for this field,
/// or <c>null</c> if no <see cref="DocValues"/> were indexed for this field. The
/// returned instance should only be used by a single thread.
/// </summary>
public abstract IBits GetDocsWithField(string field);
/// <summary>
/// Returns <see cref="NumericDocValues"/> representing norms
/// for this field, or <c>null</c> if no <see cref="NumericDocValues"/>
/// were indexed. The returned instance should only be
/// used by a single thread.
/// </summary>
public abstract NumericDocValues GetNormValues(string field);
/// <summary>
/// Get the <see cref="Index.FieldInfos"/> describing all fields in
/// this reader.
/// <para/>
/// @lucene.experimental
/// </summary>
public abstract FieldInfos FieldInfos { get; }
/// <summary>
/// Returns the <see cref="IBits"/> representing live (not
/// deleted) docs. A set bit indicates the doc ID has not
/// been deleted. If this method returns <c>null</c> it means
/// there are no deleted documents (all documents are
/// live).
/// <para/>
/// The returned instance has been safely published for
/// use by multiple threads without additional
/// synchronization.
/// </summary>
public abstract IBits LiveDocs { get; }
/// <summary>
/// Checks consistency of this reader.
/// <para/>
/// Note that this may be costly in terms of I/O, e.g.
/// may involve computing a checksum value against large data files.
/// <para/>
/// @lucene.internal
/// </summary>
public abstract void CheckIntegrity();
}
}