The second parameter of the get_document_text method is the result output adapter. In this operation, the same output adapter classes are used as those used in similar operations of a single index. For information about output adapters, see the Output adapters page. The text is available only if the text storage is enabled in the configuration of the search network; otherwise, the output adapter receives no text, and the log of the search network reports the error.
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 retrieving the text of a document indexed in the search network, as well as outputting the resulting data to the console.
fromgroupdocs.search.commonimportStringOutputAdapterfromgroupdocs.search.optionsimportOutputFormatfile_name="archive-catalogue.pdf"# The name of the document to get the text ofsearcher=node.searcherdocuments=[]shard_indices=node.get_shard_indices()forshard_indexinshard_indices:infos=searcher.get_indexed_documents(shard_index)documents.extend(infos)forinfoininfos:items=searcher.get_indexed_document_items(info)documents.extend(items)fordocumentindocuments:iffile_nameinstr(document.document_info):print()print(document.document_info)output_adapter=StringOutputAdapter(OutputFormat.PLAIN_TEXT)searcher.get_document_text(document,output_adapter)print(output_adapter.get_result())break
More resources
GitHub examples
You may easily run the code from documentation articles and see the features in action in our GitHub examples: