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.
constindexFolder='c:/MyIndex/';constdocumentsFolder='c:/MyDocuments/';// Creating an index settings instance
constsettings=newgroupdocs.search.IndexSettings();settings.setTextStorageSettings(newgroupdocs.search.TextStorageSettings(groupdocs.search.Compression.High));// Enabling the storage of extracted text in the index
// Creating an index in the specified folder
constindex=newgroupdocs.search.Index(indexFolder,settings);// Indexing documents from the specified folder
index.add(documentsFolder);// Getting list of indexed documents
constdocuments=index.getIndexedDocuments();// Getting a document text
if(documents.length>0){constdocument=documents[0];// Output to a file
constfileOutputAdapter=newgroupdocs.search.FileOutputAdapter(groupdocs.search.OutputFormat.Html,'c:/Result.html/');index.getDocumentText(document,fileOutputAdapter);// Output to a stream
conststream=java.newInstanceSync('java.io.ByteArrayOutputStream');conststreamOutputAdapter=newgroupdocs.search.StreamOutputAdapter(groupdocs.search.OutputFormat.Html,stream);index.getDocumentText(document,streamOutputAdapter);// Output to a string
conststringOutputAdapter=newgroupdocs.search.StringOutputAdapter(groupdocs.search.OutputFormat.Html);index.getDocumentText(document,stringOutputAdapter);constresult=stringOutputAdapter.getResult();//console.log(result);
// Output to a structure
conststructureOutputAdapter=newgroupdocs.search.StructureOutputAdapter(groupdocs.search.OutputFormat.PlainText);index.getDocumentText(document,structureOutputAdapter);constfields=structureOutputAdapter.getResult();console.log(document.toString());for(constfieldoffields){console.log('\t'+field.getName());}}
More resources
GitHub examples
You may easily run the code from documentation articles and see the features in action in our GitHub examples: