From d0099ba3ec5f650e0a8a1ea16b4906ead011ee8c Mon Sep 17 00:00:00 2001 From: Benedikt Tutzer Date: Wed, 11 Aug 2021 07:50:50 +0200 Subject: [PATCH 1/2] Only index local pdf files No online links, no other file types --- .../logic/pdf/search/indexing/PdfIndexer.java | 5 +++ .../pdf/search/indexing/PdfIndexerTest.java | 32 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/main/java/org/jabref/logic/pdf/search/indexing/PdfIndexer.java b/src/main/java/org/jabref/logic/pdf/search/indexing/PdfIndexer.java index a28784cb73b..4a649df278a 100644 --- a/src/main/java/org/jabref/logic/pdf/search/indexing/PdfIndexer.java +++ b/src/main/java/org/jabref/logic/pdf/search/indexing/PdfIndexer.java @@ -11,6 +11,8 @@ import javafx.collections.ObservableList; import org.jabref.gui.LibraryTab; +import org.jabref.logic.util.FileType; +import org.jabref.logic.util.StandardFileType; import org.jabref.model.database.BibDatabase; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; @@ -188,6 +190,9 @@ private void writeToIndex(BibEntry entry) { * @param linkedFile the file to write to the index */ private void writeToIndex(BibEntry entry, LinkedFile linkedFile) { + if (linkedFile.isOnlineLink() || !StandardFileType.PDF.getName().equals(linkedFile.getFileType())) { + return; + } Optional resolvedPath = linkedFile.findIn(databaseContext, filePreferences); if (resolvedPath.isEmpty()) { LOGGER.warn("Could not find {}", linkedFile.getLink()); diff --git a/src/test/java/org/jabref/logic/pdf/search/indexing/PdfIndexerTest.java b/src/test/java/org/jabref/logic/pdf/search/indexing/PdfIndexerTest.java index 9dc45525ac8..82f220df784 100644 --- a/src/test/java/org/jabref/logic/pdf/search/indexing/PdfIndexerTest.java +++ b/src/test/java/org/jabref/logic/pdf/search/indexing/PdfIndexerTest.java @@ -60,6 +60,38 @@ public void exampleThesisIndex() throws IOException { } } + @Test + public void dontIndexNonPdf() throws IOException { + // given + BibEntry entry = new BibEntry(StandardEntryType.PhdThesis); + entry.setFiles(Collections.singletonList(new LinkedFile("Example Thesis", "thesis-example.pdf", StandardFileType.AUX.getName()))); + database.insertEntry(entry); + + // when + indexer.createIndex(database, context); + + // then + try (IndexReader reader = DirectoryReader.open(new NIOFSDirectory(context.getFulltextIndexPath()))) { + assertEquals(0, reader.numDocs()); + } + } + + @Test + public void dontIndexOnlineLinks() throws IOException { + // given + BibEntry entry = new BibEntry(StandardEntryType.PhdThesis); + entry.setFiles(Collections.singletonList(new LinkedFile("Example Thesis", "https://raw.githubusercontent.com/JabRef/jabref/main/src/test/resources/pdfs/thesis-example.pdf", StandardFileType.PDF.getName()))); + database.insertEntry(entry); + + // when + indexer.createIndex(database, context); + + // then + try (IndexReader reader = DirectoryReader.open(new NIOFSDirectory(context.getFulltextIndexPath()))) { + assertEquals(0, reader.numDocs()); + } + } + @Test public void exampleThesisIndexWithKey() throws IOException { // given From 314caa8b26a9de6642287bbb1a75b7cc37af376f Mon Sep 17 00:00:00 2001 From: Benedikt Tutzer Date: Wed, 11 Aug 2021 16:30:26 +0200 Subject: [PATCH 2/2] Checkstyle --- .../java/org/jabref/logic/pdf/search/indexing/PdfIndexer.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/jabref/logic/pdf/search/indexing/PdfIndexer.java b/src/main/java/org/jabref/logic/pdf/search/indexing/PdfIndexer.java index 4a649df278a..2c0d2cf605e 100644 --- a/src/main/java/org/jabref/logic/pdf/search/indexing/PdfIndexer.java +++ b/src/main/java/org/jabref/logic/pdf/search/indexing/PdfIndexer.java @@ -11,7 +11,6 @@ import javafx.collections.ObservableList; import org.jabref.gui.LibraryTab; -import org.jabref.logic.util.FileType; import org.jabref.logic.util.StandardFileType; import org.jabref.model.database.BibDatabase; import org.jabref.model.database.BibDatabaseContext;