Text Indexing and Search your Directories using C#

Using the .NET API, you can perform searching by parts and specify the number of search threads in C#. This feature will be more beneficial when you search text in large indexes that contain thousands of documents. Furthermore, you can now get the start & end time, and the total search time to get the search results.

Following code snippet shows how to create an index and then search text in chunks from the mentioned folder in C# using GroupDocs.Search for .NET. To utilize the best performance, and updated features, I would recommend you install and use the latest version of API.

Search Text by Indexing in C#

The following example shows how to perform the search by parts/chunks.

  • Create the Index with your index folder.
  • Add your documents folder in the created index.
  • Set the Search Option and set your IsChunkSearch to true for search by chunk/parts
  • Call the Search method of your index by providing your search query and searching options.
  • Now in the result, you may traverse each segment using Search Next and passing it Chunk Search Token as a parameter.
string indexFolder = @"c:\MyIndex\";
string documentsFolder = @"c:\MyDocuments\";
string query = "Einstein";
// 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();
options.IsChunkSearch = true; // Enabling the search by chunks
// Starting the search by chunks
SearchResult result = index.Search(query, options);
Console.WriteLine("Document count: " + result.DocumentCount);
Console.WriteLine("Occurrence count: " + result.OccurrenceCount);
// Continuing the search by chunks
while (result.NextChunkSearchToken != null)
{
    result = index.SearchNext(result.NextChunkSearchToken);
    Console.WriteLine("Document count: " + result.DocumentCount);
    Console.WriteLine("Occurrence count: " + result.OccurrenceCount);
}

For any suggestions, confusions, or queries related to the .NET Search API, you may use the forum for a quick response. You may quickly create a thread to share your thoughts.