Interface IWordFormsProvider

  • All Known Implementing Classes:

    public interface IWordFormsProvider
    Defines interface of a word forms provider.

    Learn more

    The following example demonstrates how to implement a custom word forms provider.

     public class SimpleWordFormsProvider implements IWordFormsProvider {
         public final String[] getWordForms(String word) {
             ArrayList<String> result = new ArrayList<String>();
             // Assume that the input word is in the plural, then we add the singular
             if (word.length() > 2 &&
                 word.toLowerCase().endsWith("es")) {
                 result.add(word.substring(0, word.length() - 2));
             if (word.length() > 1 &&
                 word.toLowerCase().endsWith("s")) {
                 result.add(word.substring(0, word.length() - 1));
             // Then assume that the input word is in the singular, we add the plural
             if (word.length() > 1 &&
                 word.toLowerCase().endsWith("y")) {
                 result.add(word.substring(0, word.length() - 1).concat("is"));
             // All rules are implemented in the EnglishWordFormsProvider class
             return result.toArray(new String[0]);

    The next example demonstrates how to set a custom word forms provider for using.

     String indexFolder = "c:\\MyIndex\\";
     String documentsFolder = "c:\\MyDocuments\\";
     // Creating an index in the specified folder
     Index index = new Index(indexFolder);
     // Indexing documents from the specified folder
     // Setting the custom word forms provider instance
     index.getDictionaries().setWordFormsProvider(new SimpleWordFormsProvider());
     // Creating a search options instance
     SearchOptions options = new SearchOptions();
     options.setUseWordFormsSearch(true); // Enabling search for word forms
     // Searching in the index
     SearchResult result ="relative", options);
     // The following words can be found:
     // relative
     // relatives
    • Method Detail

      • getWordForms

        String[] getWordForms(String word)
        Gets the word forms for the specified word. The resulting array does not contain the original word.
        word - The word to suggest the word forms.
        The word forms for the specified word or empty array if the IWordFormsProvider does not provide word forms for the specified word.