This page contains information about the purpose and use of all search network events. The events are available through the events property of the SearchNetworkNode class, which returns an instance of the NodeEventHub class.
A handler is a function, a lambda or another callable that takes two arguments: the sender and the event arguments. Subscribe a handler with +=, for example node.events.indexing_completed += on_indexing_completed; -= removes the subscription, and clear() removes all the handlers of the event, for example node.events.indexing_completed.clear(). Most node events are raised on engine worker threads, several of them at the same time, so a handler that collects data must protect it, for example with a threading.Lock.
configuration_completed event
The configuration_completed event occurs when the search network configuration process is finished. It is raised on an engine worker thread and can arrive just after configure_all_nodes returns, so a script that ends right after that call may not see it.
indexing_completed event
The indexing_completed event occurs when indexing of all enqueued documents is finished.
The status_changed event occurs when the search network status changes.
data_extracted event
The data_extracted event occurs when the data have been extracted from a document. The extracted data are available through the data property of the event arguments.
document_indexed event
The document_indexed event occurs when a document has been indexed.
document_deleted event
The document_deleted event occurs when a document has been deleted.
error_occurred event
The error_occurred event of a node occurs when an error occurs on this node. The event arguments contain the indexes of the node and the service where the error occurred. The errors of all nodes are also written to the logger of the master node.
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 subscribing to the search network events. The handlers print their messages when the operations described on the next pages of this section run, for example, indexing, deleting or optimizing.