Close
dtSearch Engine API for Java
FileConverter Class

FileConverter converts files to HTML, RTF, or text, optionally marking hits with caller-supplied tags.

File: FileConverter.java 

Package: com.dtsearch.engine 

Syntax
Java
public class FileConverter;

For general information on implementing hit highlighting and hit navigation, see: 

Highlighting Hits 

To convert a file, create a FileConverter, use the properties of the FileConverter to describe the conversion task you want to perform, and call the execute() method. 

When highlighting hits from search results, use setInputItem to initialize the FileConverter with information obtained from SearchResults

BeforeHit, AfterHit, Header, and Footer control the appearance of converted text. Header and Footer are inserted before and after the body of the document. The BeforeHit and AfterHit markers are inserted before and after each hit word. The BeforeHit and AfterHit markers can contain hypertext links. To facilitate creation of hit navigation markers, the strings "%%ThisHit%%", "%%NextHit%%", and "%%PrevHit%%" will be replaced with ordinals representing the current hit, the next hit, and the previous hit in the document.

// results: SearchResults from a previous search // whichDoc: integer from 0 to results.getCount()-1 identifying the document to display // Select the item to display results.getNthDoc(whichDoc); String f = results.getDocName(); com.dtsearch.engine.FileConverter fc = new com.dtsearch.engine.FileConverter(); // Set up FileConverter to use the selected item from search results fc.setInputItem(results, index); // If the file is HTML, this ensures that it has a BASE tag preserving relative links fc.setBaseHref(f); // Generate HTML output in a string fc.setOutputToString(true); fc.setOutputFormat(Constants.it_HTML); // Highlight hits by making them bold fc.setBeforeHit("<b>"); fc.setAfterHit("</b>"); // Perform the conversion fc.execute(); // Display the result setHtml(fc.getOutputString());
com.dtsearch.engine.FileConverter