Skip to content

Commit 09c6a0e

Browse files
committed
applied feedback
1 parent 37634b9 commit 09c6a0e

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

server/src/main/java/org/elasticsearch/index/mapper/DocumentParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ private static void throwOnCreateDynamicNestedViaCopyTo(Mapper dynamicObjectMapp
615615
private static void parseArray(DocumentParserContext context, String lastFieldName) throws IOException {
616616
// Record previous immediate parent, so that it can be reset after array has been parsed.
617617
// This is for recording array offset with synthetic source. Only if the immediate parent is an array,
618-
// then we offsets can be accounted accurately.
618+
// then the offsets can be accounted accurately.
619619
var prev = context.getImmediateXContentParent();
620620
context.setImmediateXContentParent(context.parser().currentToken());
621621

server/src/main/java/org/elasticsearch/index/mapper/FieldArrayContext.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.apache.lucene.document.SortedDocValuesField;
1313
import org.apache.lucene.util.BitUtil;
1414
import org.elasticsearch.common.io.stream.BytesStreamOutput;
15+
import org.elasticsearch.common.io.stream.StreamInput;
1516

1617
import java.io.IOException;
1718
import java.util.ArrayList;
@@ -70,11 +71,20 @@ void addToLuceneDocument(DocumentParserContext context) throws IOException {
7071
}
7172
}
7273

74+
static int[] parseOffsetArray(StreamInput in) throws IOException {
75+
int[] offsetToOrd = new int[BitUtil.zigZagDecode(in.readVInt())];
76+
for (int i = 0; i < offsetToOrd.length; i++) {
77+
offsetToOrd[i] = BitUtil.zigZagDecode(in.readVInt());
78+
}
79+
return offsetToOrd;
80+
}
81+
7382
private static class Offsets {
7483

7584
int currentOffset;
76-
// Need to use TreeMap here, so that we maintain the order in which each value (with offset) gets inserted,
77-
// (which is in the same order the document gets parsed) so we store offsets in right order.
85+
// Need to use TreeMap here, so that we maintain the order in which each value (with offset) stored inserted,
86+
// (which is in the same order the document gets parsed) so we store offsets in right order. This is the same
87+
// order in what the values get stored in SortedSetDocValues.
7888
final Map<String, List<Integer>> valueToOffsets = new TreeMap<>();
7989
final List<Integer> nullValueOffsets = new ArrayList<>(2);
8090

server/src/main/java/org/elasticsearch/index/mapper/SortedSetWithOffsetsDocValuesSyntheticFieldLoaderLayer.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414
import org.apache.lucene.index.LeafReader;
1515
import org.apache.lucene.index.SortedDocValues;
1616
import org.apache.lucene.index.SortedSetDocValues;
17-
import org.apache.lucene.util.BitUtil;
1817
import org.apache.lucene.util.BytesRef;
1918
import org.elasticsearch.common.io.stream.ByteArrayStreamInput;
20-
import org.elasticsearch.common.io.stream.StreamInput;
2119
import org.elasticsearch.xcontent.XContentBuilder;
2220

2321
import java.io.IOException;
@@ -100,7 +98,7 @@ public boolean advanceToDoc(int docId) throws IOException {
10098
int offsetOrd = offsetDocValues.ordValue();
10199
var encodedValue = offsetDocValues.lookupOrd(offsetOrd);
102100
scratch.reset(encodedValue.bytes, encodedValue.offset, encodedValue.length);
103-
offsetToOrd = parseOffsetArray(scratch);
101+
offsetToOrd = FieldArrayContext.parseOffsetArray(scratch);
104102
} else {
105103
offsetToOrd = null;
106104
}
@@ -166,11 +164,4 @@ public void write(XContentBuilder b) throws IOException {
166164
}
167165
}
168166

169-
static int[] parseOffsetArray(StreamInput in) throws IOException {
170-
int[] offsetToOrd = new int[BitUtil.zigZagDecode(in.readVInt())];
171-
for (int i = 0; i < offsetToOrd.length; i++) {
172-
offsetToOrd[i] = BitUtil.zigZagDecode(in.readVInt());
173-
}
174-
return offsetToOrd;
175-
}
176167
}

server/src/test/java/org/elasticsearch/index/mapper/FieldArrayContextTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import java.io.IOException;
1616

17-
import static org.elasticsearch.index.mapper.SortedSetWithOffsetsDocValuesSyntheticFieldLoaderLayer.parseOffsetArray;
17+
import static org.elasticsearch.index.mapper.FieldArrayContext.parseOffsetArray;
1818

1919
public class FieldArrayContextTests extends ESTestCase {
2020

0 commit comments

Comments
 (0)