The GroupDocs.Search search network consists of one master node and several slave nodes. Each node is a server with the .NET platform deployed on it. On each server, an application is deployed that creates an instance of the SearchNetworkNode class.
The indexing and search services also provide an interface to access all search network features through the Indexer and Searcher properties of the master node.
Creating nodes
The SearchNetworkNode class has no public constructor. Its instances are created with the following static methods:
CreateMasterNode(int nodeIndex, string storagePath, INetworkSettings networkSettings, ILogger logger, Configuration configuration) creates the master node. The configuration is required; it describes all nodes of the search network.
CreateSlaveNode(int nodeIndex, string storagePath, INetworkSettings networkSettings) and CreateSlaveNode(int nodeIndex, string storagePath, INetworkSettings networkSettings, ILogger logger) create a slave node. A slave node receives its configuration from the master node and saves it in its storage folder, so after a restart, the node uses the saved configuration.
The parameters of these methods are the following:
nodeIndex — the index of the node, which must match the node index in the configuration;
storagePath — the folder where the node keeps its data;
networkSettings — an instance of the TcpSettings class, which specifies the port at which a slave node accepts connections (it must match the port specified for the node in the configuration), as well as the send, receive, connect and retry timeouts in milliseconds;
logger — an implementation of the ILogger interface, for example, FileLogger, or null. The logger of the master node receives the log messages of all nodes of the search network.
A node can also be given an OCR connector (SetOcrConnector method), which is used by its extraction services, a word forms provider (SetWordFormsProvider method), which is used by its shards, and custom text extractors (CustomExtractors property).
Starting the search network
To deploy the GroupDocs.Search search network, perform the following steps:
On each slave server, create a slave node with the CreateSlaveNode method and call its Start method.
On the master server, create the master node with the CreateMasterNode method, passing the configuration object to it.
Call the ConfigureAllNodes method of the master node. The method sends the configuration to all slave nodes and waits until they are configured. To configure only one slave node, for example, a node that has been replaced, use the ConfigureNode method. Only the master node can configure other nodes.
All nodes of a search network must use the same version of GroupDocs.Search. For upgrading a search network to version 26.10, see the Index format and compatibility page.
The following code example demonstrates starting a slave node on a server.
C#
stringbasePath=@"c:\SearchNetwork\";intbasePort=49100;// The timeouts are specified in millisecondsintsendTimeout=3000;intreceiveTimeout=3000;intconnectTimeout=3000;intretryTimeout=1000;// Creating and starting the slave node with index 1, which listens on the port specified for it in the configurationSearchNetworkNodenode1=SearchNetworkNode.CreateSlaveNode(1,basePath+"Node1",newTcpSettings(basePort+1,sendTimeout,receiveTimeout,connectTimeout,retryTimeout));node1.Start();
The following code example demonstrates starting the master node on a server. The configuration is created as shown on the Configuring search network page and loaded from a file.
C#
stringbasePath=@"c:\SearchNetwork\";intbasePort=49100;// The timeouts are specified in millisecondsintsendTimeout=3000;intreceiveTimeout=3000;intconnectTimeout=3000;intretryTimeout=1000;// Loading the search network configuration from a fileConfigurationconfiguration=Configuration.Load(basePath+"Configuration.xml");// Creating the master node with index 0SearchNetworkNodenode0=SearchNetworkNode.CreateMasterNode(0,basePath+"Node0",newTcpSettings(basePort,sendTimeout,receiveTimeout,connectTimeout,retryTimeout),newConsoleLogger(),configuration);node0.Events.ConfigurationCompleted+=(s,e)=>{Console.WriteLine("Configuration complete");};Console.WriteLine();Console.WriteLine("Configuring the search network");node0.ConfigureAllNodes();Console.WriteLine("Launching the search network");node0.Start();
The following code example demonstrates the implementation of a simple console logger.