IWordFormsProvider Interface |
Namespace: GroupDocs.Search.Dictionaries
The IWordFormsProvider type exposes the following members.
Name | Description | |
---|---|---|
![]() | GetWordForms |
Gets the word forms for the specified word.
The resulting array does not contain the original word.
|
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(); } }
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