Getting document text in network

To obtain the extracted text of indexed documents in the search network, the GetDocumentText method of the Searcher class is used.

The first parameter of the GetDocumentText method is a document represented by the NetworkDocumentInfo class. A list of all indexed documents in the search network can be obtained using the GetIndexedDocuments method of the Searcher class.

The second parameter of the GetDocumentText 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 article Output adapters.

The following code example demonstrates retrieving the text of documents indexed in the search network, as well as outputting the resulting data to the console.

C#

Searcher searcher = node.Searcher;

List<NetworkDocumentInfo> documents = new List<NetworkDocumentInfo>();
int[] shardIndices = node.GetShardIndices();
for (int i = 0; i < shardIndices.Length; i++)
{
    int shardIndex = shardIndices[i];
    NetworkDocumentInfo[] infos = searcher.GetIndexedDocuments(shardIndex);
    documents.AddRange(infos);
    for (int j = 0; j < infos.Length; j++)
    {
        NetworkDocumentInfo info = infos[j];
        NetworkDocumentInfo[] items = searcher.GetIndexedDocumentItems(info);
        documents.AddRange(items);
    }
}

for (int i = 0; i < documents.Count; i++)
{
    NetworkDocumentInfo document = documents[i];
    if (document.DocumentInfo.ToString().Contains(containsInPath))
    {
        Console.WriteLine();
        Console.WriteLine(document.DocumentInfo.ToString());

        StringOutputAdapter outputAdapter = new StringOutputAdapter(OutputFormat.PlainText);
        searcher.GetDocumentText(document, outputAdapter);

        Console.WriteLine(outputAdapter.GetResult());
        break;
    }
}

More resources

GitHub examples

You may easily run the code from documentation articles and see the features in action in our GitHub examples:

Free online document search App

Along with full featured .NET library we provide simple, but powerful free Apps.

You are welcome to search over your PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX and more with our free online Free Online Document Search App.