forked from apache/lucenenet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDocValuesFieldUpdates.cs
More file actions
214 lines (184 loc) · 8.89 KB
/
Copy pathDocValuesFieldUpdates.cs
File metadata and controls
214 lines (184 loc) · 8.89 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
using Lucene.Net.Diagnostics;
using System;
using System.Collections.Generic;
using JCG = J2N.Collections.Generic;
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.
*/
/// <summary>
/// Holds updates of a single <see cref="DocValues"/> field, for a set of documents.
/// <para/>
/// @lucene.experimental
/// </summary>
internal abstract class DocValuesFieldUpdates
{
// LUCENENET specific: de-nested Type enum and renamed DocValuesFieldUpdatesType
// LUCENENET specific: de-nested Iterator and renamed DocValuesFieldUpdatesIterator. Also created a generic version that exposes the Value property.
public class Container
{
internal readonly IDictionary<string, NumericDocValuesFieldUpdates> numericDVUpdates = new JCG.Dictionary<string, NumericDocValuesFieldUpdates>();
internal readonly IDictionary<string, BinaryDocValuesFieldUpdates> binaryDVUpdates = new JCG.Dictionary<string, BinaryDocValuesFieldUpdates>();
internal virtual bool Any()
{
foreach (NumericDocValuesFieldUpdates updates in numericDVUpdates.Values)
{
if (updates.Any())
{
return true;
}
}
foreach (BinaryDocValuesFieldUpdates updates in binaryDVUpdates.Values)
{
if (updates.Any())
{
return true;
}
}
return false;
}
internal virtual int Count => numericDVUpdates.Count + binaryDVUpdates.Count; // LUCENENET NOTE: This was size() in Lucene.
internal virtual DocValuesFieldUpdates GetUpdates(string field, DocValuesFieldUpdatesType type)
{
switch (type)
{
case DocValuesFieldUpdatesType.NUMERIC:
NumericDocValuesFieldUpdates num;
numericDVUpdates.TryGetValue(field, out num);
return num;
case DocValuesFieldUpdatesType.BINARY:
BinaryDocValuesFieldUpdates bin;
binaryDVUpdates.TryGetValue(field, out bin);
return bin;
default:
throw new ArgumentException("unsupported type: " + type);
}
}
internal virtual DocValuesFieldUpdates NewUpdates(string field, DocValuesFieldUpdatesType type, int maxDoc)
{
switch (type)
{
case DocValuesFieldUpdatesType.NUMERIC:
NumericDocValuesFieldUpdates numericUpdates;
if (Debugging.AssertsEnabled) Debugging.Assert(!numericDVUpdates.ContainsKey(field));
numericUpdates = new NumericDocValuesFieldUpdates(field, maxDoc);
numericDVUpdates[field] = numericUpdates;
return numericUpdates;
case DocValuesFieldUpdatesType.BINARY:
BinaryDocValuesFieldUpdates binaryUpdates;
if (Debugging.AssertsEnabled) Debugging.Assert(!binaryDVUpdates.ContainsKey(field));
binaryUpdates = new BinaryDocValuesFieldUpdates(field, maxDoc);
binaryDVUpdates[field] = binaryUpdates;
return binaryUpdates;
default:
throw new ArgumentException("unsupported type: " + type);
}
}
public override string ToString()
{
return "numericDVUpdates=" + string.Format(J2N.Text.StringFormatter.InvariantCulture, "{0}", numericDVUpdates) +
" binaryDVUpdates=" + string.Format(J2N.Text.StringFormatter.InvariantCulture, "{0}", binaryDVUpdates);
}
}
internal readonly string field;
internal readonly DocValuesFieldUpdatesType type;
protected DocValuesFieldUpdates(string field, DocValuesFieldUpdatesType type)
{
this.field = field;
this.type = type;
}
// LUCENENET specific - use this instance to decide which subclass to cast to, which will expose the
// strongly typed value. This allows us to access the long? type without boxing/unboxing.
// The Add() method was removed and replaced with the following two.
/// <summary>
/// Add an update to a document from a <see cref="DocValuesFieldUpdatesIterator"/>.
/// The <see cref="DocValuesFieldUpdatesIterator"/>'s value should be <c>null</c> to unset a value.
/// Note that the value is exposed by casting to the appropriate <see cref="DocValuesFieldUpdatesIterator"/> subclasss.
/// </summary>
public abstract void AddFromIterator(int doc, DocValuesFieldUpdatesIterator iterator);
/// <summary>
/// Add an update to a document from a <see cref="DocValuesUpdate"/>.
/// The <see cref="DocValuesUpdate"/>'s value should be <c>null</c> to unset a value.
/// Note that the value is exposed by casting to the appropriate <see cref="DocValuesUpdate"/> subclasss.
/// </summary>
public abstract void AddFromUpdate(int doc, DocValuesUpdate update);
/// <summary>
/// Returns a <see cref="DocValuesFieldUpdatesIterator"/> over the updated documents and their
/// values.
/// </summary>
public abstract DocValuesFieldUpdatesIterator GetIterator();
/// <summary>
/// Merge with another <see cref="DocValuesFieldUpdates"/>. this is called for a
/// segment which received updates while it was being merged. The given updates
/// should override whatever updates are in that instance.
/// </summary>
public abstract void Merge(DocValuesFieldUpdates other);
/// <summary>
/// Returns true if this instance contains any updates. </summary>
/// <returns> TODO </returns>
public abstract bool Any();
}
// LUCENENET specific - de-nested Type enumeration and renamed DocValuesFieldUpdatesType
// primarily so it doesn't conflict with System.Type.
internal enum DocValuesFieldUpdatesType
{
NUMERIC,
BINARY
}
/// <summary>
/// An iterator over documents. Only documents with
/// updates are returned by this iterator, and the documents are returned in
/// increasing order.
/// </summary>
internal abstract class DocValuesFieldUpdatesIterator
{
/// <summary>
/// Returns the next document which has an update, or
/// <see cref="Search.DocIdSetIterator.NO_MORE_DOCS"/> if there are no more documents to
/// return.
/// </summary>
public abstract int NextDoc();
/// <summary>
/// Returns the current document this iterator is on. </summary>
public abstract int Doc { get; }
/// <summary>
/// Reset the iterator's state. Should be called before <see cref="NextDoc()"/>
/// and value.
/// </summary>
public abstract void Reset();
}
/// <summary>
/// An iterator over documents and their updated values. This differs from
/// <see cref="DocValuesFieldUpdatesIterator"/> in that it exposes the strongly-typed value.
/// Only documents with updates are returned by this iterator, and the documents are returned in
/// increasing order.
/// </summary>
internal abstract class DocValuesFieldUpdatesIterator<T> : DocValuesFieldUpdatesIterator
{
/// <inheritdoc/>
public override abstract int NextDoc();
/// <inheritdoc/>
public override abstract int Doc { get; }
/// <summary>
/// Returns the value of the document returned from <see cref="NextDoc()"/>. A
/// <c>null</c> value means that it was unset for this document.
/// </summary>
public abstract T Value { get; }
/// <inheritdoc/>
public override abstract void Reset();
}
}