Package org.apache.lucene.analysis.hunspell

# Class Suggester

java.lang.Object
org.apache.lucene.analysis.hunspell.Suggester

public class Suggester extends Object
A generator for misspelled word corrections based on Hunspell flags. The suggestions are searched for in two main ways:

1. Modification: trying to insert/remove/delete/swap parts of the word to get something acceptable. The performance of this part depends heavily on the contents of TRY, MAP, REP, KEY directives in the .aff file. To speed up this part, consider using `withFragmentChecker(org.apache.lucene.analysis.hunspell.FragmentChecker)`.
2. Enumeration: if the modification hasn't produced "good enough" suggestions, the whole dictionary is scanned and simple affixes are added onto the entries to check if that produces anything similar to the given misspelled word. This depends on the dictionary size and the affix count, and it can take noticeable amount of time. To speed this up, `withSuggestibleEntryCache()` can be used.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Suggester(Dictionary dictionary)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Suggester`
  `proceedPastRep()`
  Returns a copy of this suggester instance that doesn't stop after encountering acceptable words after applying REP rules.
  `List<String>`
  `suggestNoTimeout(String word, Runnable checkCanceled)`
  Compute suggestions for the given misspelled word
  `List<String>`
  `suggestWithTimeout(String word, long timeLimitMs, Runnable checkCanceled)`
  `Suggester`
  `withFragmentChecker(FragmentChecker checker)`
  Returns a copy of this suggester instance with `FragmentChecker` hint that can improve the performance of the "Modification" phase performance.
  `Suggester`
  `withSuggestibleEntryCache()`
  Returns a copy of this suggester instance with better "Enumeration" phase performance (see `Suggester` documentation), but using more memory.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### Suggester

    public Suggester(Dictionary dictionary)

- ## Method Details

  - ### withSuggestibleEntryCache

    public Suggester withSuggestibleEntryCache()
    Returns a copy of this suggester instance with better "Enumeration" phase performance (see `Suggester` documentation), but using more memory. With this option, the dictionary entries are stored as fast-to-iterate plain words instead of highly compressed prefix trees.

  - ### withFragmentChecker

    public Suggester withFragmentChecker(FragmentChecker checker)
    Returns a copy of this suggester instance with `FragmentChecker` hint that can improve the performance of the "Modification" phase performance.

  - ### proceedPastRep

    public Suggester proceedPastRep()
    Returns a copy of this suggester instance that doesn't stop after encountering acceptable words after applying REP rules. By default, Hunspell stops when it finds any, but this behavior may not always be desirable, e.g., if we have "REP i ea", "tims" be replaced only by "teams" and not "times", which could also be meant.

  - ### suggestNoTimeout

    public List<String> suggestNoTimeout(String word, Runnable checkCanceled)
    Compute suggestions for the given misspelled word
    Parameters:
      `word` - the misspelled word to calculate suggestions for
      `checkCanceled` - an object that's periodically called, allowing to interrupt or suggestion generation by throwing an exception

  - ### suggestWithTimeout

    public List<String> suggestWithTimeout(String word, long timeLimitMs, Runnable checkCanceled) throws SuggestionTimeoutException
    Parameters:
      `word` - the misspelled word to calculate suggestions for
      `timeLimitMs` - the duration limit in milliseconds after which the computation is interruped by an exception
      `checkCanceled` - an object that's periodically called, allowing to interrupt or suggestion generation by throwing an exception
    Throws:
      `SuggestionTimeoutException` - if the computation takes too long. Use `SuggestionTimeoutException.getPartialResult()` to get the suggestions computed up to that point