Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lucene/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ Optimizations

* GITHUB#15597: Reduce memory usage of NeighborArray (Viliam Durina)

* GITHUB#15683: Reuse reader's fieldinfos. (Vliam Durina)

Bug Fixes
---------------------
* GITHUB#14049: Randomize KNN codec params in RandomCodec. Fixes scalar quantization div-by-zero
Expand Down
27 changes: 19 additions & 8 deletions lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,7 @@ public IndexWriter(Directory d, IndexWriterConfig conf) throws IOException {
// start with previous field numbers, but new FieldInfos
// NOTE: this is correct even for an NRT reader because we'll pull FieldInfos even for the
// un-committed segments:
globalFieldNumberMap = getFieldNumberMap();
globalFieldNumberMap = getFieldNumberMap(reader);
if (create == false
&& conf.getParentField() != null
&& globalFieldNumberMap.getFieldNames().isEmpty() == false
Expand Down Expand Up @@ -1258,17 +1258,28 @@ static FieldInfos readFieldInfos(SegmentCommitInfo si) throws IOException {
}

/**
* Loads or returns the already loaded global field number map for this {@link SegmentInfos}. If
* this {@link SegmentInfos} has no global field number map, the returned instance is empty.
* Loads the global field number map for this {@link SegmentInfos}. If this {@link SegmentInfos}
* has no global field number map the returned instance is empty.
*
* <p>If the a {@code reader} is given, then instead of reading the field info file (.fnm), the
* field infos from its leaves are used.
*/
private FieldNumbers getFieldNumberMap() throws IOException {
private FieldNumbers getFieldNumberMap(StandardDirectoryReader reader) throws IOException {
final FieldNumbers map =
new FieldNumbers(config.getSoftDeletesField(), config.getParentField());

for (SegmentCommitInfo info : segmentInfos) {
FieldInfos fis = readFieldInfos(info);
for (FieldInfo fi : fis) {
map.addOrGet(fi);
if (reader == null) {
for (SegmentCommitInfo info : segmentInfos) {
FieldInfos fis = readFieldInfos(info);
for (FieldInfo fi : fis) {
map.addOrGet(fi);
}
}
} else {
for (LeafReaderContext leafContext : reader.leaves()) {
for (FieldInfo fi : leafContext.reader().getFieldInfos()) {
map.addOrGet(fi);
}
}
}
return map;
Expand Down
Loading