Class SharingStemmer

All Implemented Interfaces:
Stemmer

@ThreadSafe public final class SharingStemmer extends DelegatingStemmer<Stemmer>
A Stemmer that is safe to share across threads by routing each call to a per-thread delegate minted from a StemmerFactory. Use it to share a stemmer whose implementation is not itself thread-safe, such as PorterStemmer; thread-safe implementations like SnowballStemmer do not need this wrapper.

The first thread uses a single owner delegate without touching ThreadLocal until a second thread appears, matching the OwnerOrPerThreadState pattern used by the thread-safe *ME components.

  • Constructor Details

    • SharingStemmer

      public SharingStemmer(StemmerFactory factory)
      Creates a sharing stemmer.
      Parameters:
      factory - The factory that mints per-thread delegates. Must not be null.
      Throws:
      IllegalArgumentException - Thrown if factory is null.
  • Method Details

    • stem

      public CharSequence stem(CharSequence word)
      Stems word.
      Parameters:
      word - The input word. Must not be null.
      Returns:
      The stemmed form.
    • stemAll

      public List<CharSequence> stemAll(CharSequence word)
      Returns all stem forms for word. Defaults to a single-element list from Stemmer.stem(CharSequence). Dictionary-based engines may override this to return multiple roots; delegating wrappers must forward it to preserve the full list.
      Parameters:
      word - The input word. Must not be null.
      Returns:
      all stem forms for word