Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/main/java/org/jabref/logic/pdf/search/PdfIndexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public void addToIndex(BibEntry entry, Collection<LinkedFile> linkedFiles, boole

private void doCommit() {
try {
getIndexWriter().ifPresent(Unchecked.consumer(writer -> writer.commit()));
getIndexWriter().ifPresent(Unchecked.consumer(IndexWriter::commit));
} catch (UncheckedIOException e) {
LOGGER.warn("Could not commit changes to the index.", e);
}
Expand Down Expand Up @@ -274,7 +274,6 @@ private void addToIndex(BibEntry entry, LinkedFile linkedFile, boolean shouldCom
LOGGER.debug("Could not find {}", linkedFile.getLink());
return;
}
LOGGER.debug("Adding {} to index", linkedFile.getLink());
try {
// Check if a document with this path is already in the index
try {
Expand All @@ -283,17 +282,21 @@ private void addToIndex(BibEntry entry, LinkedFile linkedFile, boolean shouldCom
TopDocs topDocs = searcher.search(query, 1);
// If a document was found, check if is less current than the one in the FS
if (topDocs.scoreDocs.length > 0) {
Document doc = reader.document(topDocs.scoreDocs[0].doc);
Document doc = reader.storedFields().document(topDocs.scoreDocs[0].doc);
long indexModificationTime = Long.parseLong(doc.getField(SearchFieldConstants.MODIFIED).stringValue());
BasicFileAttributes attributes = Files.readAttributes(resolvedPath.get(), BasicFileAttributes.class);
if (indexModificationTime >= attributes.lastModifiedTime().to(TimeUnit.SECONDS)) {
LOGGER.debug("File {} is already indexed", linkedFile.getLink());
LOGGER.debug("File {} is already indexed and up-to-date.", linkedFile.getLink());
return;
} else {
LOGGER.debug("File {} is already indexed but outdated. Removing from index.", linkedFile.getLink());
removeFromIndex(linkedFile.getLink());
}
}
} catch (IndexNotFoundException e) {
LOGGER.debug("Index not found. Continuing.", e);
}
LOGGER.debug("Adding {} to index", linkedFile.getLink());
// If no document was found, add the new one
Optional<List<Document>> pages = new DocumentReader(entry, filePreferences).readLinkedPdf(this.databaseContext, linkedFile);
if (pages.isPresent()) {
Expand Down Expand Up @@ -328,7 +331,7 @@ public Set<String> getListOfFilePaths() {
MatchAllDocsQuery query = new MatchAllDocsQuery();
TopDocs allDocs = searcher.search(query, Integer.MAX_VALUE);
for (ScoreDoc scoreDoc : allDocs.scoreDocs) {
Document doc = reader.document(scoreDoc.doc);
Document doc = reader.storedFields().document(scoreDoc.doc);
paths.add(doc.getField(SearchFieldConstants.PATH).stringValue());
}
} catch (IOException e) {
Expand Down