Text attributes of documents are changed without the need to re-index documents in the search network.
To change document attributes, use the ChangeAttributes method of the Indexer class. The changes are described by an AttributeChangeBatch object, in which documents are specified by their keys.
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 changing document attributes on the search network.
C#
stringdocumentKey="Lorem ipsum.pdf";// The key of an indexed documentstringattribute="important";Console.WriteLine("Adding attribute: "+attribute);Indexerindexer=node.Indexer;AttributeChangeBatchbatch=newAttributeChangeBatch();batch.Add(documentKey,attribute);ChangeAttributesOptionsoptions=newChangeAttributesOptions();indexer.ChangeAttributes(batch,options);
To get all the attributes of a document, use the GetAttributes method of the Indexer class. You must pass the document key as a parameter.
The following code example, which continues the code that creates the master node, demonstrates retrieving document attributes from the search network.