To obtain a dictionary from a shard of the search network, use the GetDictionary method of the Indexer class. The first parameter of the GetDictionary method is the type of the required dictionary, and the second parameter is the index of the shard in the network. The method returns an object of type DictionaryBase, which must be cast to the required dictionary type.
The returned object is a copy of the dictionary of the shard. You can perform all operations on it that are valid for a dictionary in a single index; the changes do not affect the shard until the dictionary is set back. For information about working with dictionaries, see the Managing dictionaries section.
After setting up the dictionary, return it to the shard using the SetDictionary method of the Indexer class, specifying the index of the desired shard. Alternatively, you can set the dictionary to all shards by calling the SetDictionary method with one parameter, without specifying the shard index. The SetDictionary method replaces the whole content of the dictionary of a shard with the content of the passed dictionary.
Note
The alphabet, the tokenization dictionary, the stop word dictionary and the character replacement dictionary define how the text of documents is divided into terms. Therefore, a shard accepts another content of such a dictionary only while its index contains no documents and is not performing an operation. A shard that does not accept the dictionary does not throw an exception: it keeps its own dictionary and reports the reason as an error to the log of the search network and by the ErrorOccurred event of its node. Configure these dictionaries before adding the first documents to the search network. The other dictionaries can be changed at any time. See also the Index format and compatibility page.
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 adding a group of synonyms to the synonym dictionary of all shards.
C#
string[]group=newstring[]{"achieve","accomplish","attain","reach"};boolclearBeforeAdding=false;// Specifies whether to remove the existing synonymsConsole.WriteLine("Adding synonyms");Indexerindexer=node.Indexer;// Getting the synonym dictionary of the first shardint[]indices=node.GetShardIndices();SynonymDictionarydictionary=indexer.GetSynonymDictionary(indices[0]);if(clearBeforeAdding){dictionary.Clear();}dictionary.AddRange(newstring[][]{group});// Setting the dictionary to all shardsindexer.SetDictionary(dictionary);
The following code example, which continues the code that creates the master node, demonstrates setting the tokenization dictionary of all shards before adding documents to the search network.
C#
Indexerindexer=node.Indexer;// Getting the tokenization dictionary of the first shardint[]indices=node.GetShardIndices();AlphabettokenizationDictionary=indexer.GetTokenizationDictionary(indices[0]);// Setting the Letter type for Hiragana and Katakana charactersList<int>codePoints=newList<int>();for(intcodePoint=0x3040;codePoint<=0x30FF;codePoint++){codePoints.Add(codePoint);}tokenizationDictionary.SetRange(codePoints.ToArray(),CharacterType.Letter);// Setting the dictionary to all shards; a shard whose index contains documents keeps its own dictionaryindexer.SetDictionary(tokenizationDictionary);