Configuring a search network involves creating a configuration using the Configurator class and its fluent interface.
The Configurator class has methods for configuring general index settings, as well as for configuring each individual network node.
Index settings
The SetIndexSettings method returns an instance of the IndexSettingsConfigurator class, which allows you to set the following settings for the index of each shard of the search network:
Flag for using stop words when indexing (SetUseStopWords method).
Settings that are not set have their default values. The ReplaceUnpairedSurrogates and SkipBlendedOnlyTerms index settings cannot be configured for a search network: the index of a shard is created with their default values (both enabled). For a description of the index settings, see the Search index settings page.
A search network consists of exactly one master node and one or more slave nodes. Each node is identified by a unique non-negative node index.
To configure the master node, use the AddMasterNode method, which returns an instance of the MasterNodeConfigurator class. This class allows you to add the following services to the master node:
An indexing service, which is the input for all operations that change the contents of shards (AddIndexer method).
A search service, which is the input for all search queries to the network (AddSearcher method).
The master node also receives log messages from all other nodes of the network; this is configured automatically. The master node connects to the slave nodes, so no TCP endpoint is specified for it.
To configure a slave node, use the AddSlaveNode method, which returns an instance of the SlaveNodeConfigurator class. This class allows you to set the following node parameters:
The host name or IP address and the port number at which the slave node accepts connections (SetTcpEndpoint method). The endpoint must be set for every slave node, and the port must be the listening port of the node (see the Search network deployment page).
An extraction service used to extract data from documents added to the search network (AddExtractor method). Increasing the number of extraction services (one per network node) increases the performance of search network indexing.
A shard service used to store extracted data in a form suitable for searching (AddShard method). Increasing the number of shards (one for each network node) increases the performance of searching the network.
Each service is given a storage path, which is the folder where the service keeps its data. A node must contain at least one service.
Once the search network configuration is complete, call the CompleteConfiguration method, which returns an instance of the Configuration class. The method checks the configuration and throws InvalidOperationException if any of the following rules is violated:
the node indexes are unique;
the configuration contains exactly one master node;
the configuration of each node is completed;
the network contains exactly one indexer and exactly one searcher;
the network contains at least one shard.
An instance of the Configuration class can be saved to a file or a stream in the XML format using the Save method, and subsequently loaded from the file or stream using the static Load method.
The following code example shows how to create a search network configuration that describes four nodes and save it to a file.
C#
stringbasePath=@"c:\SearchNetwork\";stringaddress="127.0.0.1";intbasePort=49100;Configurationconfiguration=newConfigurator().SetIndexSettings().SetUseStopWords(false).SetUseCharacterReplacements(false).SetTextStorageSettings(true,Compression.High).SetIndexType(IndexType.NormalIndex).SetSearchThreads(NumberOfThreads.Default).CompleteIndexSettings().AddMasterNode(0).AddIndexer(basePath+"Indexer0").AddSearcher(basePath+"Searcher0").CompleteNode().AddSlaveNode(1).SetTcpEndpoint(address,basePort+1).AddShard(basePath+"Shard1").AddExtractor(basePath+"Extractor1").CompleteNode().AddSlaveNode(2).SetTcpEndpoint(address,basePort+2).AddShard(basePath+"Shard2").AddExtractor(basePath+"Extractor2").CompleteNode().AddSlaveNode(3).SetTcpEndpoint(address,basePort+3).AddShard(basePath+"Shard3").AddExtractor(basePath+"Extractor3").CompleteNode().CompleteConfiguration();// Saving the configuration to a fileconfiguration.Save(basePath+"Configuration.xml");
The following code example shows how to load the saved configuration from the file.
C#
stringbasePath=@"c:\SearchNetwork\";// Loading the configuration from a fileConfigurationconfiguration=Configuration.Load(basePath+"Configuration.xml");
More resources
GitHub examples
You may easily run the code from documentation articles and see the features in action in our GitHub examples: