class FileIndexer {

    public void indexFile(final File file) {
        FileInputStream fis = getInputStream(file);
        Document doc = documentFactory.createDocument();
        // Add the path of the file as a field named "path". Use a field that is indexed (i.e. searchable), but don't tokenize
        // the field into separate words and don't index term frequency or positional information:
        Field pathField = new StringField(fieldName, file.getAbsolutePath(), Field.Store.YES);
        doc.add(pathField);

        // Add the last modified date of the file a field named "modified".
        // Use a LongField that is indexed (i.e. efficiently filterable with NumericRangeFilter).
        doc.add(new LongField("modified", file.lastModified(), Field.Store.NO));

        // Add the contents of the file to a field named "contents".
        // If that's not the case searching for special characters will fail.
        BufferedReader bufferedReader;
        try {
            bufferedReader = bufferedReaderFactory.createReader(fis);
            doc.add(new Field("contents", bufferedReader, TextField.TYPE_NOT_STORED));
            addDocument(file, doc);
            fis.close();
        } catch (IOException e) {
            logger.error(" caught a " + e.getClass() + "\n with message: " + e.getMessage());
        }
    }

}