dweiss commented on code in PR #11893:
URL: https://github.com/apache/lucene/pull/11893#discussion_r1009622594


##########
lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Hunspell.java:
##########
@@ -647,8 +671,23 @@ Root<CharsRef> findStem(
 
     if (!hasGoodSuggestions && dictionary.maxNGramSuggestions > 0) {
       List<String> generated =
-          new GeneratingSuggester(suggestionSpeller)
-              .suggest(dictionary.toLowerCase(word), wordCase, suggestions);
+          new GeneratingSuggester(suggestionSpeller) {
+            @Override
+            void processSuggestibleWords(
+                int minLength, int maxLength, BiConsumer<CharsRef, 
Supplier<IntsRef>> processor) {
+              if (cacheSuggestibleEntries) {
+                SuggestibleEntryCache cache = suggestibleCache;
+                if (cache == null) {
+                  // a benign race:
+                  // 
https://shipilev.net/blog/2016/close-encounters-of-jmm-kind/#wishful-benign-is-resilient

Review Comment:
   yeah, it's fine... although unless it's a crucial loop I'd just mark that 
field volatile so that advanced knowledge of jmm doesn't have to be explained 
to whoever would like to look at that code later on :)



##########
lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Hunspell.java:
##########
@@ -72,10 +77,29 @@ public Hunspell(Dictionary dictionary) {
    *     or suggestion generation by throwing an exception
    */
   public Hunspell(Dictionary dictionary, TimeoutPolicy policy, Runnable 
checkCanceled) {
+    this(dictionary, policy, checkCanceled, new Stemmer(dictionary), false);
+  }
+
+  private Hunspell(
+      Dictionary dictionary,
+      TimeoutPolicy policy,
+      Runnable checkCanceled,
+      Stemmer stemmer,
+      boolean cacheSuggestibleEntries) {
     this.dictionary = dictionary;
     this.policy = policy;
     this.checkCanceled = checkCanceled;
-    stemmer = new Stemmer(dictionary);
+    this.stemmer = stemmer;
+    this.cacheSuggestibleEntries = cacheSuggestibleEntries;
+  }
+
+  /**
+   * Returns a copy of this Hunspell instance with better suggestion 
performance but using more

Review Comment:
   This looks fine to me, although perhaps you'd consider an API similar to 
that used in codecs, where you pass a tradeoff enum hint (MEMORY, SPEED) and 
get an instance that tries to fulfill these hints?  The drawback is that it'd 
be backward-incompatible, unless you make it a new (static) factory method? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to