Skip to content

Commit

Permalink
Fulltext Index: Only index local pdf files (#7980)
Browse files Browse the repository at this point in the history
  • Loading branch information
btut authored Aug 12, 2021
1 parent a7bd8b7 commit 025c099
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import javafx.collections.ObservableList;

import org.jabref.gui.LibraryTab;
import org.jabref.logic.util.StandardFileType;
import org.jabref.model.database.BibDatabase;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
Expand Down Expand Up @@ -188,6 +189,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<Path> resolvedPath = linkedFile.findIn(databaseContext, filePreferences);
if (resolvedPath.isEmpty()) {
LOGGER.warn("Could not find {}", linkedFile.getLink());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 025c099

Please sign in to comment.