using GroupDocs.Search;
using GroupDocs.Search.Options;
using GroupDocs.Search.Results;

namespace SpellingCorrectioninDocumentSearchUsingCSharp
{
    internal class Program
    {
        static void Main(string[] args)
        {
            // Apply the license to remove the restrictions
            // imposed by the Search library
            License lic = new License();
            lic.SetLicense(@"GroupDocs.Search.lic");

            string indexFolder = @"d:\MyIndex\";
            string documentsFolder = @"d:\MyDocuments\";

            // Creating an index in the specified folder
            Index index = new Index(indexFolder);

            // Indexing documents from the specified folder
            index.Add(documentsFolder);

            // Creating a search options instance
            SearchOptions options = new SearchOptions();
            // Enabling the spelling correction
            options.SpellingCorrector.Enabled = true;
            // Setting the maximum number of mistakes
            options.SpellingCorrector.MaxMistakeCount = 1;
            // Enabling the option for only the best results of the spelling correction
            options.SpellingCorrector.OnlyBestResults = true; 

            // Search for the word "Rleativity" containing a spelling error
            // The word "Relativity" will be found that differs
            // from the search query in two transposed letters
            SearchResult result = index.Search("Rleativity", options);
        }
    }
}