You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by do...@apache.org on 2024/03/07 11:30:55 UTC

(lucene) 01/03: hunspell GeneratingSuggester: ensure there are never more than 100 roots to process (#13154)

This is an automated email from the ASF dual-hosted git repository.

donnerpeter pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/lucene.git

commit 9148bbf54fb7eccd3e974cc2b33302721fc62ee3
Author: Peter Gromov <pe...@jetbrains.com>
AuthorDate: Tue Mar 5 09:53:27 2024 +0100

    hunspell GeneratingSuggester: ensure there are never more than 100 roots to process (#13154)
    
    hunspell GeneratingSuggester: ensure there are never more than 100 roots to process
    
    (cherry picked from commit 193cc62c732a5f1e7bd5dfdb5556c0a244a7e196)
---
 lucene/CHANGES.txt                                                   | 2 ++
 .../org/apache/lucene/analysis/hunspell/GeneratingSuggester.java     | 5 ++---
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index e1a438aa47a..c5c43bd553a 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -44,6 +44,8 @@ Bug Fixes
 
 * GITHUB#13145: Detect MemorySegmentIndexInput correctly in NRTSuggester. (Uwe Schindler)
 
+* GITHUB#13154: Hunspell GeneratingSuggester: ensure there are never more than 100 roots to process (Peter Gromov)
+
 Other
 ---------------------
 
diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/GeneratingSuggester.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/GeneratingSuggester.java
index 82d58080f9b..18215059410 100644
--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/GeneratingSuggester.java
+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/GeneratingSuggester.java
@@ -97,8 +97,7 @@ class GeneratingSuggester {
 
           sc += commonPrefix(word, rootChars) - longerWorsePenalty(word.length(), rootChars.length);
 
-          boolean overflow = roots.size() == MAX_ROOTS;
-          if (overflow && isWorseThan(sc, rootChars, roots.peek())) {
+          if (roots.size() == MAX_ROOTS && isWorseThan(sc, rootChars, roots.peek())) {
             return;
           }
 
@@ -109,7 +108,7 @@ class GeneratingSuggester {
           for (int i = 0; i < forms.length; i++) {
             if (isSuggestible.test(forms.ints[forms.offset + i])) {
               roots.add(new Weighted<>(new Root<>(root, forms.ints[forms.offset + i]), sc));
-              if (overflow) {
+              if (roots.size() == MAX_ROOTS) {
                 roots.poll();
               }
             }