Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fulltext Index: Only index local pdf files #7980

Merged
merged 2 commits into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<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