IWordFormsProvider Interface
Defines interface of a word forms provider.

Namespace: GroupDocs.Search.Dictionaries
Assembly: GroupDocs.Search (in GroupDocs.Search.dll) Version: 20.8
Syntax
public interface IWordFormsProvider

The IWordFormsProvider type exposes the following members.

Methods
  NameDescription
Public methodGetWordForms
Gets the word forms for the specified word. The resulting array does not contain the original word.
Remarks
Examples
The following example demonstrates how to implement a custom word forms provider.
C#
public class SimpleWordFormsProvider : IWordFormsProvider
{
    public string[] GetWordForms(string word)
    {
        List<string> result = new List<string>();

        // Assume that the input word is in the plural, then we add the singular
        if (word.Length > 2 &&
            word.EndsWith("es", StringComparison.InvariantCultureIgnoreCase))
        {
            result.Add(word.Substring(0, word.Length - 2));
        }
        if (word.Length > 1 &&
            word.EndsWith("s", StringComparison.InvariantCultureIgnoreCase))
        {
            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.EndsWith("y", StringComparison.InvariantCultureIgnoreCase))
        {
            result.Add(word.Substring(0, word.Length - 1) + "is");
        }
        result.Add(word + "s");
        result.Add(word + "es");
        // All rules are implemented in the EnglishWordFormsProvider class

        return result.ToArray();
    }
}
Examples
The next example demonstrates how to set a custom word forms provider for using.
C#
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
index.Add(documentsFolder);

// Setting the custom word forms provider instance
index.Dictionaries.WordFormsProvider = new SimpleWordFormsProvider();

// Creating a search options instance
SearchOptions options = new SearchOptions();
options.UseWordFormsSearch = true; // Enabling search for word forms

// Searching in the index
SearchResult result = index.Search("relative", options);

// The following words can be found:
// relative
// relatives
See Also