Text search in network

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Search MCP server lets your agent work with files on your machine; they are never uploaded. It runs in Docker: replace /path/to/documents with the folder it may use.

claude mcp add groupdocs-search -- docker run --rm -i -v /path/to/documents:/data ghcr.io/groupdocs-search/search-net-mcp:latest
Folders, licensing and more →

To run a text search, use the SearchFirst method of the Searcher class. This method returns the first portion of results.

To continue the search, the SearchNext method is used, returning the second and subsequent portions of results. Continue the search while the NextChunkSearchToken property of the result is not null.

Text and object forms of the search query are supported when appropriate overloads of the SearchFirst method are used. The options for a network search are the same as those for a single index search. The search network supports only search by chunks: the IsChunkSearch option must be set to true; otherwise, the SearchFirst method throws ArgumentException.

Since version 26.11, the SearchFirst method observes the Cancellation of the search options: when the cancellation is requested, the method returns at once with an empty result whose warnings are “Operation cancelled.” and which has no next chunk, as a search of an index does. A shard that has got the request completes the search, and its result is ignored. The SearchNext method does not observe the cancellation of the options of the first search.

Each portion of results is returned as a NetworkSearchResult object, which has the following members:

A found document is represented by the NetworkFoundDocument class, which contains the FoundDocument object, as in a single index search, and the index of the shard where the document was found (ShardIndex property).

Note
Since version 26.11, a NetworkSearchResult applies the limit of the evaluation mode as a search result of an index does: only the first 10 found documents of a result can be retrieved, the GetFoundDocument method throws LicenseRestrictionException for a document number of 10 or greater, and an enumeration of the result, such as the AddRange call in the example below, throws it after the first 10 documents. See Evaluation limitations and licensing.

The examples on this page use the master node of a running search network. The following code creates and starts the master node as described on the Search network deployment page; the slave nodes must be started beforehand.

C#

string basePath = @"c:\SearchNetwork\";
int basePort = 49100;

// Loading the search network configuration from a file
Configuration configuration = Configuration.Load(basePath + "Configuration.xml");

// Creating, configuring and starting the master node; the timeouts are specified in milliseconds
SearchNetworkNode node = SearchNetworkNode.CreateMasterNode(
    0,
    basePath + "Node0",
    new TcpSettings(basePort, 3000, 3000, 3000, 1000),
    new FileLogger(basePath + "Log.txt", 4.0),
    configuration);
node.ConfigureAllNodes();
node.Start();

The following code example, which continues the previous one, demonstrates performing a full-text search on the search network.

C#

string word = "einstein";
bool useSynonymSearch = true;

Searcher searcher = node.Searcher;

SearchQuery query = SearchQuery.CreateWordQuery(word);
Console.WriteLine();
Console.WriteLine("First time search for: " + query);
SearchOptions options = new SearchOptions();
options.IsChunkSearch = true;
options.UseSynonymSearch = useSynonymSearch;
int totalOccurrences = 0;
List<NetworkFoundDocument> documents = new List<NetworkFoundDocument>();

NetworkSearchResult result = searcher.SearchFirst(query, options);

documents.AddRange(result);
totalOccurrences += result.OccurrenceCount;
Console.WriteLine("Documents found (node " + result.NodeIndex + "): " + result.DocumentCount);

while (result.NextChunkSearchToken != null)
{
    Console.WriteLine();
    Console.WriteLine("Next time search for: " + query);

    result = searcher.SearchNext(result.NextChunkSearchToken);

    documents.AddRange(result);
    totalOccurrences += result.OccurrenceCount;
    Console.WriteLine("Documents found (node " + result.NodeIndex + "): " + result.DocumentCount);
}

Console.WriteLine();
Console.WriteLine("Total occurrences: " + totalOccurrences);
for (int i = 0; i < documents.Count; i++)
{
    NetworkFoundDocument document = documents[i];
    Console.WriteLine(document.ShardIndex + ": " + document.FoundDocument.DocumentInfo.FilePath +
        " (" + document.FoundDocument.OccurrenceCount + " occurrences)");
}

More information about search queries can be found on the Queries in text and object form page.

More resources

GitHub examples

You may easily run the code from documentation articles and see the features in action in our GitHub examples:

Free online document search App

Along with full featured .NET library we provide simple, but powerful free Apps.

You are welcome to search over your PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX and more with our free online Free Online Document Search App.