Output adapters are used to output generated HTML or plain text to various output objects. The following output adapters are currently supported:
FileOutputAdapter is an output adapter that is used to output text to a file. The path to a file is specified in the constructor of the adapter.
StreamOutputAdapter is an output adapter that is used to output text to a stream. The stream is specified in the constructor of the adapter.
StringOutputAdapter is an output adapter that is used to output text to a string. The resulting string can be accessed through the GetResult method of the adapter class.
StructureOutputAdapter is an output adapter that is used to output the text of each field of the document separately. The resulting array of fields can be accessed through the GetResult method of the adapter class.
The example below demonstates how to use adapters of different types.
C#
stringindexFolder=@"c:\MyIndex\";stringdocumentsFolder=@"c:\MyDocuments\";// Creating an index settings instanceIndexSettingssettings=newIndexSettings();settings.TextStorageSettings=newTextStorageSettings(Compression.High);// Enabling storage of extracted text in the index// Creating an index in the specified folderIndexindex=newIndex(indexFolder,settings);// Indexing documents from the specified folderindex.Add(documentsFolder);// Getting list of indexed documentsDocumentInfo[]documents=index.GetIndexedDocuments();// Getting a document textif(documents.Length>0){DocumentInfodocument=documents[0];// Output to a fileFileOutputAdapterfileOutputAdapter=newFileOutputAdapter(OutputFormat.Html,@"C:\Text.html");index.GetDocumentText(document,fileOutputAdapter);// Output to a streamusing(Streamstream=newMemoryStream()){StreamOutputAdapterstreamOutputAdapter=newStreamOutputAdapter(OutputFormat.Html,stream);index.GetDocumentText(document,streamOutputAdapter);}// Output to a stringStringOutputAdapterstringOutputAdapter=newStringOutputAdapter(OutputFormat.Html);index.GetDocumentText(document,stringOutputAdapter);stringhtmlText=stringOutputAdapter.GetResult();Console.WriteLine(htmlText);// Output to a structureStructureOutputAdapterstructureOutputAdapter=newStructureOutputAdapter(OutputFormat.PlainText);index.GetDocumentText(document,structureOutputAdapter);DocumentField[]fields=structureOutputAdapter.GetResult();Console.WriteLine(document.ToString());for(inti=0;i<fields.Length;i++){DocumentFieldfield=fields[i];Console.WriteLine("\t"+field.Name);}}
More resources
GitHub examples
You may easily run the code from documentation articles and see the features in action in our GitHub examples: