diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene90/blocktree/Lucene90BlockTreeTermsWriter.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene90/blocktree/Lucene90BlockTreeTermsWriter.java index 8d0d5aaaa22..e122c83156e 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/lucene90/blocktree/Lucene90BlockTreeTermsWriter.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene90/blocktree/Lucene90BlockTreeTermsWriter.java @@ -545,6 +545,7 @@ public final class Lucene90BlockTreeTermsWriter extends FieldsConsumer { .suffixRAMLimitMB(0d) .dataOutput(getOnHeapReaderWriter(pageBits)) .setVersion(fstVersion) + .setInitLength(prefix.length + 1) .build(); // if (DEBUG) { // System.out.println(" compile index for prefix=" + prefix); diff --git a/lucene/core/src/java/org/apache/lucene/util/fst/FSTCompiler.java b/lucene/core/src/java/org/apache/lucene/util/fst/FSTCompiler.java index d51c256d48e..727f94c647a 100644 --- a/lucene/core/src/java/org/apache/lucene/util/fst/FSTCompiler.java +++ b/lucene/core/src/java/org/apache/lucene/util/fst/FSTCompiler.java @@ -164,7 +164,8 @@ public class FSTCompiler { boolean allowFixedLengthArcs, DataOutput dataOutput, float directAddressingMaxOversizingFactor, - int version) { + int version, + int initLength) { this.allowFixedLengthArcs = allowFixedLengthArcs; this.directAddressingMaxOversizingFactor = directAddressingMaxOversizingFactor; this.version = version; @@ -185,7 +186,7 @@ public class FSTCompiler { NO_OUTPUT = outputs.getNoOutput(); @SuppressWarnings({"rawtypes", "unchecked"}) - final UnCompiledNode[] f = (UnCompiledNode[]) new UnCompiledNode[10]; + final UnCompiledNode[] f = (UnCompiledNode[]) new UnCompiledNode[initLength]; frontier = f; for (int idx = 0; idx < frontier.length; idx++) { frontier[idx] = new UnCompiledNode<>(this, idx); @@ -247,6 +248,7 @@ public class FSTCompiler { private DataOutput dataOutput; private float directAddressingMaxOversizingFactor = DIRECT_ADDRESSING_MAX_OVERSIZING_FACTOR; private int version = FST.VERSION_CURRENT; + private int initLength = 10; /** * @param inputType The input type (transition labels). Can be anything from {@link INPUT_TYPE} @@ -346,6 +348,11 @@ public class FSTCompiler { return this; } + public Builder setInitLength(int initLength) { + this.initLength = initLength; + return this; + } + /** Creates a new {@link FSTCompiler}. */ public FSTCompiler build() { // create a default DataOutput if not specified @@ -359,7 +366,8 @@ public class FSTCompiler { allowFixedLengthArcs, dataOutput, directAddressingMaxOversizingFactor, - version); + version, + initLength); } }