FileDocCategorySizeDatePackage
TextDocument.javaAPI DocApache Lucene 2.1.02991Wed Feb 14 10:45:44 GMT 2007org.apache.lucene.ant

TextDocument

public class TextDocument extends Object
A utility for making Lucene Documents from a File.
author
Erik Hatcher
created
December 6, 2001
todo
Fix JavaDoc comments here

Fields Summary
private String
contents
Constructors Summary
public TextDocument(File file)
Constructor for the TextDocument object

param
file Description of Parameter
exception
IOException Description of Exception

        BufferedReader br =
                new BufferedReader(new FileReader(file));
        StringWriter sw = new StringWriter();

        String line = br.readLine();
        while (line != null) {
            sw.write(line);
            line = br.readLine();
        }
        br.close();

        contents = sw.toString();
        sw.close();
    
Methods Summary
public static org.apache.lucene.document.DocumentDocument(java.io.File f)
Makes a document for a File.

The document has a single field:

  • contents--containing the full contents of the file, as a Text field;

    param
    f Description of Parameter
    return
    Description of the Returned Value
    exception
    IOException Description of Exception

    
            TextDocument textDoc = new TextDocument(f);
            // make a new, empty document
            Document doc = new Document();
    
            doc.add(new Field("title", f.getName(), Field.Store.YES, Field.Index.TOKENIZED));
            doc.add(new Field("contents", textDoc.getContents(), Field.Store.YES, Field.Index.TOKENIZED));
            doc.add(new Field("rawcontents", textDoc.getContents(), Field.Store.YES, Field.Index.NO));
    
            // return the document
            return doc;
        
public java.lang.StringgetContents()

return
The contents value
todo
finish this method

        return contents;