Text search in network

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.

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).

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.

Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.