Top Description Fields Constructors Methods
org.jabref.logic.pdf.search

public Class PdfIndexer

extends Object
Class Inheritance
Imports
java.io.IOException, .UncheckedIOException, java.nio.file.Files, .Path, java.nio.file.attribute.BasicFileAttributes, java.util.Collection, .HashSet, .List, .Optional, .Set, java.util.concurrent.TimeUnit, org.jabref.logic.util.StandardFileType, org.jabref.model.database.BibDatabaseContext, org.jabref.model.entry.BibEntry, .LinkedFile, org.jabref.model.pdf.search.SearchFieldConstants, org.jabref.preferences.FilePreferences, com.google.common.annotations.VisibleForTesting, org.apache.lucene.analysis.en.EnglishAnalyzer, org.apache.lucene.document.Document, org.apache.lucene.index.DirectoryReader, org.apache.lucene.index.IndexNotFoundException, org.apache.lucene.index.IndexReader, org.apache.lucene.index.IndexWriter, org.apache.lucene.index.IndexWriterConfig, org.apache.lucene.index.Term, org.apache.lucene.search.IndexSearcher, org.apache.lucene.search.MatchAllDocsQuery, org.apache.lucene.search.ScoreDoc, org.apache.lucene.search.TermQuery, org.apache.lucene.search.TopDocs, org.apache.lucene.store.Directory, org.apache.lucene.store.NIOFSDirectory, org.jooq.lambda.Unchecked, org.jspecify.annotations.Nullable, org.slf4j.Logger, .LoggerFactory

Indexes the text of PDF files and adds it into the lucene search index.

Field Summary

Modifier and TypeField and Description
private final BibDatabaseContext
private final FilePreferences
private final @Nullable org.apache.lucene.store.Directory
pack-priv @Nullable org.apache.lucene.index.IndexWriter
private static final Logger
private org.apache.lucene.index.IndexReader

Constructor Summary

AccessConstructor and Description
private
PdfIndexer(BibDatabaseContext databaseContext, org.apache.lucene.store.Directory indexDirectory, FilePreferences filePreferences)

Method Summary

Modifier and TypeMethod and Description
public void
public void
addToIndex(BibEntry
a bibtex entry to link the pdf files to
entry
)

Adds all PDF files linked to one entry in the database to an existing (or new) Lucene search index

private void
addToIndex(BibEntry entry, boolean shouldCommit)

public void
addToIndex(BibEntry
a bibtex entry to link the pdf files to
entry
,
Collection<LinkedFile> linkedFiles)

Adds a list of pdf files linked to one entry in the database to an existing (or new) Lucene search index

public void
addToIndex(BibEntry entry, Collection<LinkedFile> linkedFiles, boolean shouldCommit)

public void
addToIndex(BibEntry
the entry associated with the file
entry
,
LinkedFile
the file to write to the index
linkedFile
)

Writes the file to the index if the file is not yet in the index or the file on the fs is newer than the one in the index.

private void
addToIndex(BibEntry entry, LinkedFile linkedFile, boolean shouldCommit)

public void
public void
createIndex()

Creates (and thus resets) the PDF index.

private void
pack-priv Optional<org.apache.lucene.index.IndexWriter>
getIndexWriter()

Needs to be accessed by PdfSearcher

public Set<String>

Returns:

all file paths
getListOfFilePaths
()

Lists the paths of all the files that are stored in the index

private void
initializeIndexWriterAndReader(org.apache.lucene.index.IndexWriterConfig.OpenMode mode)

public static PdfIndexer
of(BibDatabaseContext databaseContext, Path indexDirectory, FilePreferences filePreferences)

Method is public, because DatabaseSearcherWithBibFilesTest resides in another package

public static PdfIndexer
of(BibDatabaseContext databaseContext, FilePreferences filePreferences)

Method is public, because DatabaseSearcherWithBibFilesTest resides in another package

public void
rebuildIndex()

Rebuilds the PDF index.

public void
removeFromIndex(String
the path to the file to be removed
linkedFilePath
)

Removes a pdf file identified by its path from the index

public void
removeFromIndex(BibEntry
the entry documents are linked to
entry
)

Removes all files linked to a bib-entry from the index

public void
removeFromIndex(Collection<LinkedFile> linkedFiles)

Removes a list of files linked to a bib-entry from the index

public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

databaseContextback to summary
private final BibDatabaseContext databaseContext
filePreferencesback to summary
private final FilePreferences filePreferences
indexDirectoryback to summary
private final @Nullable org.apache.lucene.store.Directory indexDirectory
indexWriterback to summary
pack-priv @Nullable org.apache.lucene.index.IndexWriter indexWriter
Annotations
@VisibleForTesting
LOGGERback to summary
private static final Logger LOGGER
readerback to summary
private org.apache.lucene.index.IndexReader reader

Constructor Detail

PdfIndexerback to summary
private PdfIndexer(BibDatabaseContext databaseContext, org.apache.lucene.store.Directory indexDirectory, FilePreferences filePreferences)

Method Detail

addToIndexback to summary
public void addToIndex(List<BibEntry> entries)
addToIndexback to summary
public void addToIndex(BibEntry entry)

Adds all PDF files linked to one entry in the database to an existing (or new) Lucene search index

Parameters
entry:BibEntry

a bibtex entry to link the pdf files to

addToIndexback to summary
private void addToIndex(BibEntry entry, boolean shouldCommit)
addToIndexback to summary
public void addToIndex(BibEntry entry, Collection<LinkedFile> linkedFiles)

Adds a list of pdf files linked to one entry in the database to an existing (or new) Lucene search index

Parameters
entry:BibEntry

a bibtex entry to link the pdf files to

addToIndexback to summary
public void addToIndex(BibEntry entry, Collection<LinkedFile> linkedFiles, boolean shouldCommit)
addToIndexback to summary
public void addToIndex(BibEntry entry, LinkedFile linkedFile)

Writes the file to the index if the file is not yet in the index or the file on the fs is newer than the one in the index.

Parameters
entry:BibEntry

the entry associated with the file

linkedFile:LinkedFile

the file to write to the index

addToIndexback to summary
private void addToIndex(BibEntry entry, LinkedFile linkedFile, boolean shouldCommit)
closeback to summary
public void close() throws IOException
createIndexback to summary
public void createIndex()

Creates (and thus resets) the PDF index. No re-indexing will be done. Any previous state of the Lucene search is deleted.

doCommitback to summary
private void doCommit()
getIndexWriterback to summary
pack-priv Optional<org.apache.lucene.index.IndexWriter> getIndexWriter()

Needs to be accessed by PdfSearcher

getListOfFilePathsback to summary
public Set<String> getListOfFilePaths()

Lists the paths of all the files that are stored in the index

Returns:Set<String>

all file paths

initializeIndexWriterAndReaderback to summary
private void initializeIndexWriterAndReader(org.apache.lucene.index.IndexWriterConfig.OpenMode mode)
ofback to summary
public static PdfIndexer of(BibDatabaseContext databaseContext, Path indexDirectory, FilePreferences filePreferences) throws IOException

Method is public, because DatabaseSearcherWithBibFilesTest resides in another package

Annotations
@VisibleForTesting
ofback to summary
public static PdfIndexer of(BibDatabaseContext databaseContext, FilePreferences filePreferences) throws IOException

Method is public, because DatabaseSearcherWithBibFilesTest resides in another package

rebuildIndexback to summary
public void rebuildIndex()

Rebuilds the PDF index. All PDF files linked to entries in the database will be re-indexed.

removeFromIndexback to summary
public void removeFromIndex(String linkedFilePath)

Removes a pdf file identified by its path from the index

Parameters
linkedFilePath:String

the path to the file to be removed

removeFromIndexback to summary
public void removeFromIndex(BibEntry entry)

Removes all files linked to a bib-entry from the index

Parameters
entry:BibEntry

the entry documents are linked to

removeFromIndexback to summary
public void removeFromIndex(Collection<LinkedFile> linkedFiles)

Removes a list of files linked to a bib-entry from the index

removePathsFromIndexback to summary
public void removePathsFromIndex(Collection<String> linkedFiles)