Text attributes of documents are changed without the need to re-index documents in the search network.
To change document attributes, use the change_attributes method of the Indexer class. The changes are described by an AttributeChangeBatch object, in which documents are specified by their keys. The attributes are passed to the methods of the batch as a list of strings.
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. The examples that follow continue this code in the same Python process.
fromgroupdocs.search.commonimportFileLoggerfromgroupdocs.search.scalingimportSearchNetworkNodefromgroupdocs.search.scaling.configuringimportConfiguration,TcpSettingsbase_path="./SearchNetwork/"base_port=49100# Loading the search network configuration from a fileconfiguration=Configuration.load(base_path+"Configuration.xml")# Creating, configuring and starting the master node; the timeouts are specified in millisecondsnode=SearchNetworkNode.create_master_node(0,base_path+"Node0",TcpSettings(base_port,3000,3000,3000,1000),FileLogger(base_path+"Log.txt",4.0),configuration)node.configure_all_nodes()node.start()
The following code example, which continues the previous one, demonstrates changing document attributes on the search network.
fromgroupdocs.search.commonimportAttributeChangeBatchfromgroupdocs.search.optionsimportChangeAttributesOptionsdocument_key="archive-catalogue.pdf"# The key of an indexed documentattribute="important"print("Adding attribute: "+attribute)indexer=node.indexerbatch=AttributeChangeBatch()batch.add(document_key,[attribute])options=ChangeAttributesOptions()indexer.change_attributes(batch,options)
To get all the attributes of a document, use the get_attributes 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.