Top Description Fields Constructors Methods
org.apache.pdfbox.examples.lucene

public Class LucenePDFDocument

extends Object
Class Inheritance
Imports
java.io.File, .IOException, .Reader, .StringReader, .StringWriter, java.net.URL, .URLConnection, java.nio.file.FileSystems, java.util.Calendar, .Date, org.apache.lucene.document.DateTools, org.apache.lucene.document.Document, org.apache.lucene.document.Field, org.apache.lucene.document.FieldType, org.apache.lucene.document.StringField, org.apache.lucene.document.TextField, org.apache.lucene.index.IndexOptions, org.apache.pdfbox.Loader, org.apache.pdfbox.io.RandomAccessRead, .RandomAccessReadBuffer, .RandomAccessReadBufferedFile, org.apache.pdfbox.pdmodel.PDDocument, .PDDocumentInformation, org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException, org.apache.pdfbox.text.PDFTextStripper

This class is used to create a document for the lucene search engine. This should easily plug into the IndexPDFFiles that comes with the lucene project. This class will populate the following fields.
Lucene Field Name Description
path File system path if loaded from a file
url URL to PDF document
contents Entire contents of PDF document, indexed but not stored
summary First 500 characters of content
modified The modified date/time according to the url or path
uid A unique identifier for the Lucene document.
CreationDate From PDF meta-data if available
Creator From PDF meta-data if available
Keywords From PDF meta-data if available
ModificationDate From PDF meta-data if available
Producer From PDF meta-data if available
Subject From PDF meta-data if available
Trapped From PDF meta-data if available
Author
Ben Litchfield

Field Summary

Modifier and TypeField and Description
private static final org.apache.lucene.document.DateTools.Resolution
private static final char
private PDFTextStripper
public static final org.apache.lucene.document.FieldType
TYPE_STORED_NOT_INDEXED

not Indexed, tokenized, stored.

Constructor Summary

AccessConstructor and Description
public
LucenePDFDocument()

Constructor.

Method Summary

Modifier and TypeMethod and Description
private void
addContent(org.apache.lucene.document.Document
The document to add the contents to.
document
,
RandomAccessRead
The source to get the content from.
source
,
String
The location of the document, used just for debug messages.
documentLocation
)

This will add the contents to the lucene document.

private void
addKeywordField(org.apache.lucene.document.Document document, String name, String value)

private void
addTextField(org.apache.lucene.document.Document document, String name, Reader value)

private void
addTextField(org.apache.lucene.document.Document document, String name, String value)

private void
addTextField(org.apache.lucene.document.Document document, String name, Date value)

private void
addTextField(org.apache.lucene.document.Document document, String name, Calendar value)

private static void
addUnindexedField(org.apache.lucene.document.Document document, String name, String value)

private void
addUnstoredKeywordField(org.apache.lucene.document.Document document, String name, String value)

public org.apache.lucene.document.Document

Returns:

The converted lucene document.
convertDocument
(File
A reference to a PDF document.
file
)

This will take a reference to a PDF document and create a lucene document.

public org.apache.lucene.document.Document

Returns:

The PDF converted to a lucene document.
convertDocument
(URL
A url to a PDF document.
url
)

Convert the document from a PDF to a lucene document.

public static String

Returns:

the created UID
createUID
(URL
the file we have to create an UID for
url
,
long
the time to used to the UID
time
)

Create an UID for the given file using the given time.

public static String

Returns:

the created UID
createUID
(File
the file we have to create an UID for
file
)

Create an UID for the given file.

public static org.apache.lucene.document.Document

Returns:

The lucene document.
getDocument
(File
The file to get the document for.
file
)

This will get a lucene document from a PDF file.

public static org.apache.lucene.document.Document

Returns:

The lucene document.
getDocument
(URL
The file to get the document for.
url
)

This will get a lucene document from a PDF file.

public void
setTextStripper(PDFTextStripper
The new pdf text stripper.
aStripper
)

Set the text stripper that will be used during extraction.

private static String
timeToString(long time)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DATE_TIME_RESback to summary
private static final org.apache.lucene.document.DateTools.Resolution DATE_TIME_RES
FILE_SEPARATORback to summary
private static final char FILE_SEPARATOR
stripperback to summary
private PDFTextStripper stripper
TYPE_STORED_NOT_INDEXEDback to summary
public static final org.apache.lucene.document.FieldType TYPE_STORED_NOT_INDEXED

not Indexed, tokenized, stored.

Constructor Detail

LucenePDFDocumentback to summary
public LucenePDFDocument()

Constructor.

Method Detail

addContentback to summary
private void addContent(org.apache.lucene.document.Document document, RandomAccessRead source, String documentLocation) throws IOException

This will add the contents to the lucene document.

Parameters
document:org.apache.lucene.document.Document

The document to add the contents to.

source:RandomAccessRead

The source to get the content from.

documentLocation:String

The location of the document, used just for debug messages.

Exceptions
IOException:
If there is an error parsing the document.
addKeywordFieldback to summary
private void addKeywordField(org.apache.lucene.document.Document document, String name, String value)
addTextFieldback to summary
private void addTextField(org.apache.lucene.document.Document document, String name, Reader value)
addTextFieldback to summary
private void addTextField(org.apache.lucene.document.Document document, String name, String value)
addTextFieldback to summary
private void addTextField(org.apache.lucene.document.Document document, String name, Date value)
addTextFieldback to summary
private void addTextField(org.apache.lucene.document.Document document, String name, Calendar value)
addUnindexedFieldback to summary
private static void addUnindexedField(org.apache.lucene.document.Document document, String name, String value)
addUnstoredKeywordFieldback to summary
private void addUnstoredKeywordField(org.apache.lucene.document.Document document, String name, String value)
convertDocumentback to summary
public org.apache.lucene.document.Document convertDocument(File file) throws IOException

This will take a reference to a PDF document and create a lucene document.

Parameters
file:File

A reference to a PDF document.

Returns:org.apache.lucene.document.Document

The converted lucene document.

Exceptions
IOException:
If there is an exception while converting the document.
convertDocumentback to summary
public org.apache.lucene.document.Document convertDocument(URL url) throws IOException

Convert the document from a PDF to a lucene document.

Parameters
url:URL

A url to a PDF document.

Returns:org.apache.lucene.document.Document

The PDF converted to a lucene document.

Exceptions
IOException:
If there is an error while converting the document.
createUIDback to summary
public static String createUID(URL url, long time)

Create an UID for the given file using the given time.

Parameters
url:URL

the file we have to create an UID for

time:long

the time to used to the UID

Returns:String

the created UID

createUIDback to summary
public static String createUID(File file)

Create an UID for the given file.

Parameters
file:File

the file we have to create an UID for

Returns:String

the created UID

getDocumentback to summary
public static org.apache.lucene.document.Document getDocument(File file) throws IOException

This will get a lucene document from a PDF file.

Parameters
file:File

The file to get the document for.

Returns:org.apache.lucene.document.Document

The lucene document.

Exceptions
IOException:
If there is an error parsing or indexing the document.
getDocumentback to summary
public static org.apache.lucene.document.Document getDocument(URL url) throws IOException

This will get a lucene document from a PDF file.

Parameters
url:URL

The file to get the document for.

Returns:org.apache.lucene.document.Document

The lucene document.

Exceptions
IOException:
If there is an error parsing or indexing the document.
setTextStripperback to summary
public void setTextStripper(PDFTextStripper aStripper)

Set the text stripper that will be used during extraction.

Parameters
aStripper:PDFTextStripper

The new pdf text stripper.

timeToStringback to summary
private static String timeToString(long time)