Skip to content

Commit 80e4def

Browse files
authored
LUCENE-9697: Hunspell Stemmer: use the same FST.BytesReader on all recursion levels (#2242)
1 parent a82634d commit 80e4def

File tree

1 file changed

+6
-9
lines changed
  • lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell

1 file changed

+6
-9
lines changed

lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Stemmer.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ final class Stemmer {
5252
*/
5353
public Stemmer(Dictionary dictionary) {
5454
this.dictionary = dictionary;
55+
prefixReader = dictionary.prefixes == null ? null : dictionary.prefixes.getBytesReader();
56+
suffixReader = dictionary.suffixes == null ? null : dictionary.suffixes.getBytesReader();
5557
for (int level = 0; level < 3; level++) {
5658
if (dictionary.prefixes != null) {
5759
prefixArcs[level] = new FST.Arc<>();
58-
prefixReaders[level] = dictionary.prefixes.getBytesReader();
5960
}
6061
if (dictionary.suffixes != null) {
6162
suffixArcs[level] = new FST.Arc<>();
62-
suffixReaders[level] = dictionary.suffixes.getBytesReader();
6363
}
6464
}
6565
formStep = dictionary.formStep();
@@ -252,13 +252,12 @@ private CharsRef newStem(char[] buffer, int length, IntsRef forms, int formID) {
252252
}
253253

254254
// some state for traversing FSTs
255-
private final FST.BytesReader[] prefixReaders = new FST.BytesReader[3];
255+
private final FST.BytesReader prefixReader;
256+
private final FST.BytesReader suffixReader;
256257

257258
@SuppressWarnings({"unchecked", "rawtypes"})
258259
private final FST.Arc<IntsRef>[] prefixArcs = new FST.Arc[3];
259260

260-
private final FST.BytesReader[] suffixReaders = new FST.BytesReader[3];
261-
262261
@SuppressWarnings({"unchecked", "rawtypes"})
263262
private final FST.Arc<IntsRef>[] suffixArcs = new FST.Arc[3];
264263

@@ -302,7 +301,6 @@ private List<CharsRef> stem(
302301

303302
if (doPrefix && dictionary.prefixes != null) {
304303
FST<IntsRef> fst = dictionary.prefixes;
305-
FST.BytesReader bytesReader = prefixReaders[recursionDepth];
306304
FST.Arc<IntsRef> arc = prefixArcs[recursionDepth];
307305
fst.getFirstArc(arc);
308306
IntsRef NO_OUTPUT = fst.outputs.getNoOutput();
@@ -311,7 +309,7 @@ private List<CharsRef> stem(
311309
for (int i = 0; i < limit; i++) {
312310
if (i > 0) {
313311
int ch = word[i - 1];
314-
if (fst.findTargetArc(ch, arc, arc, bytesReader) == null) {
312+
if (fst.findTargetArc(ch, arc, arc, prefixReader) == null) {
315313
break;
316314
} else if (arc.output() != NO_OUTPUT) {
317315
output = fst.outputs.add(output, arc.output());
@@ -351,7 +349,6 @@ private List<CharsRef> stem(
351349

352350
if (doSuffix && dictionary.suffixes != null) {
353351
FST<IntsRef> fst = dictionary.suffixes;
354-
FST.BytesReader bytesReader = suffixReaders[recursionDepth];
355352
FST.Arc<IntsRef> arc = suffixArcs[recursionDepth];
356353
fst.getFirstArc(arc);
357354
IntsRef NO_OUTPUT = fst.outputs.getNoOutput();
@@ -360,7 +357,7 @@ private List<CharsRef> stem(
360357
for (int i = length; i >= limit; i--) {
361358
if (i < length) {
362359
int ch = word[i];
363-
if (fst.findTargetArc(ch, arc, arc, bytesReader) == null) {
360+
if (fst.findTargetArc(ch, arc, arc, suffixReader) == null) {
364361
break;
365362
} else if (arc.output() != NO_OUTPUT) {
366363
output = fst.outputs.add(output, arc.output());

0 commit comments

Comments
 (0)