GroupDocs team is pleased to announce three enhancements in GroupDocs.Search for .NET 18.2. Using the latest version, you can now perform indexing in multiple threads using multi-threaded indexing. Furthermore, you can now implement compact indexing that consumes up to 5 times less disk space. We would recommend you to download the latest version for better user experience.
Note: the code examples in this article have been updated to the API of GroupDocs.Search for .NET 26.10. The features described here were introduced in version 18.2 and are still available in the current version. The examples use the namespaces
GroupDocs.Search,GroupDocs.Search.Common,GroupDocs.Search.OptionsandSystem.Threading.
Multi-Threaded Indexing in C#
In this enhancement, you can perform indexing in multiple threads. Multi-threaded indexing is faster but uses more memory and may cause memory overflow error. If you have only 8 GB of RAM installed, it is recommended to use not more than 2 threads for indexing. If you have 16 GB of RAM installed, you can use 4 threads for indexing. The number of indexing threads is set by the Threads property of the IndexingOptions class and must be in the range from 1 to 4. Following code sample shows how to use multi-threaded indexing.
string indexFolder = @"c:\MyIndex\"; // Specify path to the index folder
string documentsFolder = @"c:\MyDocuments\"; // Specify path to the folder with documents
// Creating an index
Index index = new Index(indexFolder);
// Creating indexing options
IndexingOptions options = new IndexingOptions();
options.Threads = 2; // Indexing in 2 threads
// Indexing documents
index.Add(documentsFolder, options);
// Searching
SearchResult result = index.Search("Einstein");
Console.WriteLine("Documents found: " + result.DocumentCount);
You can also run multi-threaded indexing asynchronously by setting the IsAsync property of the indexing options. In this case, the Add method returns control before the indexing is completed, and the end of the operation is reported by the StatusChanged event of the index, as shown in the following code sample.
string indexFolder = @"c:\MyIndex\"; // Specify path to the index folder
string documentsFolder = @"c:\MyDocuments\"; // Specify path to the folder with documents
// Creating an index
Index index = new Index(indexFolder);
// Subscribing to the event that reports the end of the operation
ManualResetEventSlim indexingFinished = new ManualResetEventSlim(false);
index.Events.StatusChanged += (sender, args) =>
{
if (args.Status == IndexStatus.Ready || args.Status == IndexStatus.Failed)
{
indexingFinished.Set();
}
};
// Creating indexing options
IndexingOptions options = new IndexingOptions();
options.Threads = 2; // Indexing in 2 threads
options.IsAsync = true; // Performing the operation asynchronously
// Starting the indexing, the method returns control before the operation is completed
index.Add(documentsFolder, options);
// The user can perform a search after the completion of the indexing operation
indexingFinished.Wait();
SearchResult result = index.Search("Einstein");
Console.WriteLine("Documents found: " + result.DocumentCount);
Compact Indexing
This enhancement allows you to create an index that consumes up to 5 times less disk space. This is possible for the reason of containing only number of word occurrences without positions. For the same reason, index of this type does not support phrase search and date range search. The index type is specified by the IndexType property of the IndexSettings class when the index is created.
string indexFolder = @"c:\MyIndex\"; // Specify path to the index folder
string documentsFolder = @"c:\MyDocuments\"; // Specify path to the folder with documents
// Creating an index settings object
IndexSettings settings = new IndexSettings();
settings.IndexType = IndexType.CompactIndex; // Setting the compact index type
// Creating an index
Index index = new Index(indexFolder, settings);
// Indexing documents
index.Add(documentsFolder);
// Searching
SearchResult result = index.Search("Einstein");
Console.WriteLine("Documents found: " + result.DocumentCount);
Improved Index Structure to Increase Indexing Speed
This enhancement is implemented to increase indexing performance. As a result, the performance of single-threaded indexing has been improved by around 8%.
Available Channels and Resources
Here are a few channels and resources for you to download, try, learn and get technical support on GroupDocs.Search:
- Download - MSI Package
- NuGet - NuGet Install
- Documentation - API docs
- Examples/Plugins/Showcases - Examples and Open Source Application
- Video Tutorials - YouTube Videos
- Product Support Forum - Technical Support Forum for GroupDocs.Search
Feedback
If you have any suggestions, questions, or queries related to the .NET Search API, we will be happy to hear from you. Just create a forum thread to share your thoughts.