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:
NodeIndex — the index of the node from which the result was received;
NextChunkSearchToken — the token for continuing the search, or null if the search is complete.
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#
stringbasePath=@"c:\SearchNetwork\";intbasePort=49100;// Loading the search network configuration from a fileConfigurationconfiguration=Configuration.Load(basePath+"Configuration.xml");// Creating, configuring and starting the master node; the timeouts are specified in millisecondsSearchNetworkNodenode=SearchNetworkNode.CreateMasterNode(0,basePath+"Node0",newTcpSettings(basePort,3000,3000,3000,1000),newFileLogger(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#
stringword="einstein";booluseSynonymSearch=true;Searchersearcher=node.Searcher;SearchQueryquery=SearchQuery.CreateWordQuery(word);Console.WriteLine();Console.WriteLine("First time search for: "+query);SearchOptionsoptions=newSearchOptions();options.IsChunkSearch=true;options.UseSynonymSearch=useSynonymSearch;inttotalOccurrences=0;List<NetworkFoundDocument>documents=newList<NetworkFoundDocument>();NetworkSearchResultresult=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(inti=0;i<documents.Count;i++){NetworkFoundDocumentdocument=documents[i];Console.WriteLine(document.ShardIndex+": "+document.FoundDocument.DocumentInfo.FilePath+" ("+document.FoundDocument.OccurrenceCount+" occurrences)");}