Skip to content

Commit

Permalink
Introduce preference to disable fulltext indexing (JabRef#8478)
Browse files Browse the repository at this point in the history
* Introduce preference to disable fulltext indexing

Fixes JabRef#8468

* Improve l10n

* fix l10n

Co-authored-by: Oliver Kopp <[email protected]>
Co-authored-by: Siedlerchr <[email protected]>
  • Loading branch information
3 people authored Jan 31, 2022
1 parent a8a6129 commit c1c79a0
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 31 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve

- The CSL preview styles now also support displaying data from cross references entries that are linked via the `crossref` field [#7378](https://github.com/JabRef/jabref/issues/7378)
- We made the Search button in Web Search wider. We also skewed the panel titles to the left [#8397](https://github.com/JabRef/jabref/issues/8397)
- We introduced a preference to disable fulltext indexing [#8468](https://github.com/JabRef/jabref/issues/8468)

### Fixed

Expand Down
72 changes: 41 additions & 31 deletions src/main/java/org/jabref/gui/LibraryTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,9 @@ public void updateTabTitle(boolean isChanged) {
setTooltip(new Tooltip(toolTipText.toString()));
});

indexingTaskManager.updateDatabaseName(tabTitle.toString());
if (preferencesService.getFilePreferences().shouldFulltextIndexLinkedFiles()) {
indexingTaskManager.updateDatabaseName(tabTitle.toString());
}
}

private List<String> collectAllDatabasePaths() {
Expand Down Expand Up @@ -855,53 +857,61 @@ public void listen(EntriesRemovedEvent removedEntriesEvent) {
private class IndexUpdateListener {

public IndexUpdateListener() {
try {
indexingTaskManager.addToIndex(PdfIndexer.of(bibDatabaseContext, preferencesService.getFilePreferences()), bibDatabaseContext);
} catch (IOException e) {
LOGGER.error("Cannot access lucene index", e);
if (preferencesService.getFilePreferences().shouldFulltextIndexLinkedFiles()) {
try {
indexingTaskManager.addToIndex(PdfIndexer.of(bibDatabaseContext, preferencesService.getFilePreferences()), bibDatabaseContext);
} catch (IOException e) {
LOGGER.error("Cannot access lucene index", e);
}
}
}

@Subscribe
public void listen(EntriesAddedEvent addedEntryEvent) {
try {
PdfIndexer pdfIndexer = PdfIndexer.of(bibDatabaseContext, preferencesService.getFilePreferences());
for (BibEntry addedEntry : addedEntryEvent.getBibEntries()) {
indexingTaskManager.addToIndex(pdfIndexer, addedEntry, bibDatabaseContext);
if (preferencesService.getFilePreferences().shouldFulltextIndexLinkedFiles()) {
try {
PdfIndexer pdfIndexer = PdfIndexer.of(bibDatabaseContext, preferencesService.getFilePreferences());
for (BibEntry addedEntry : addedEntryEvent.getBibEntries()) {
indexingTaskManager.addToIndex(pdfIndexer, addedEntry, bibDatabaseContext);
}
} catch (IOException e) {
LOGGER.error("Cannot access lucene index", e);
}
} catch (IOException e) {
LOGGER.error("Cannot access lucene index", e);
}
}

@Subscribe
public void listen(EntriesRemovedEvent removedEntriesEvent) {
try {
PdfIndexer pdfIndexer = PdfIndexer.of(bibDatabaseContext, preferencesService.getFilePreferences());
for (BibEntry removedEntry : removedEntriesEvent.getBibEntries()) {
indexingTaskManager.removeFromIndex(pdfIndexer, removedEntry);
if (preferencesService.getFilePreferences().shouldFulltextIndexLinkedFiles()) {
try {
PdfIndexer pdfIndexer = PdfIndexer.of(bibDatabaseContext, preferencesService.getFilePreferences());
for (BibEntry removedEntry : removedEntriesEvent.getBibEntries()) {
indexingTaskManager.removeFromIndex(pdfIndexer, removedEntry);
}
} catch (IOException e) {
LOGGER.error("Cannot access lucene index", e);
}
} catch (IOException e) {
LOGGER.error("Cannot access lucene index", e);
}
}

@Subscribe
public void listen(FieldChangedEvent fieldChangedEvent) {
if (fieldChangedEvent.getField().equals(StandardField.FILE)) {
List<LinkedFile> oldFileList = FileFieldParser.parse(fieldChangedEvent.getOldValue());
List<LinkedFile> newFileList = FileFieldParser.parse(fieldChangedEvent.getNewValue());

List<LinkedFile> addedFiles = new ArrayList<>(newFileList);
addedFiles.remove(oldFileList);
List<LinkedFile> removedFiles = new ArrayList<>(oldFileList);
removedFiles.remove(newFileList);

try {
indexingTaskManager.addToIndex(PdfIndexer.of(bibDatabaseContext, preferencesService.getFilePreferences()), fieldChangedEvent.getBibEntry(), addedFiles, bibDatabaseContext);
indexingTaskManager.removeFromIndex(PdfIndexer.of(bibDatabaseContext, preferencesService.getFilePreferences()), fieldChangedEvent.getBibEntry(), removedFiles);
} catch (IOException e) {
LOGGER.warn("I/O error when writing lucene index", e);
if (preferencesService.getFilePreferences().shouldFulltextIndexLinkedFiles()) {
if (fieldChangedEvent.getField().equals(StandardField.FILE)) {
List<LinkedFile> oldFileList = FileFieldParser.parse(fieldChangedEvent.getOldValue());
List<LinkedFile> newFileList = FileFieldParser.parse(fieldChangedEvent.getNewValue());

List<LinkedFile> addedFiles = new ArrayList<>(newFileList);
addedFiles.remove(oldFileList);
List<LinkedFile> removedFiles = new ArrayList<>(oldFileList);
removedFiles.remove(newFileList);

try {
indexingTaskManager.addToIndex(PdfIndexer.of(bibDatabaseContext, preferencesService.getFilePreferences()), fieldChangedEvent.getBibEntry(), addedFiles, bibDatabaseContext);
indexingTaskManager.removeFromIndex(PdfIndexer.of(bibDatabaseContext, preferencesService.getFilePreferences()), fieldChangedEvent.getBibEntry(), removedFiles);
} catch (IOException e) {
LOGGER.warn("I/O error when writing lucene index", e);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
<Button fx:id="autolinkRegexHelp"/>
</HBox>

<Label styleClass="sectionHeader" text="%Fulltext Index"/>
<CheckBox fx:id="fulltextIndex" text="%Automatically index all linked files for fulltext search"/>

<Label styleClass="sectionHeader" text="%Linked file name conventions"/>
<GridPane hgap="4.0" vgap="4.0">
<columnConstraints>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ComboBox;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
Expand Down Expand Up @@ -32,6 +33,8 @@ public class LinkedFilesTab extends AbstractPreferenceTabView<LinkedFilesTabView
@FXML private RadioButton autolinkUseRegex;
@FXML private TextField autolinkRegexKey;

@FXML private CheckBox fulltextIndex;

@FXML private ComboBox<String> fileNamePattern;
@FXML private TextField fileDirectoryPattern;

Expand Down Expand Up @@ -62,6 +65,7 @@ public void initialize() {
autolinkUseRegex.selectedProperty().bindBidirectional(viewModel.autolinkUseRegexProperty());
autolinkRegexKey.textProperty().bindBidirectional(viewModel.autolinkRegexKeyProperty());
autolinkRegexKey.disableProperty().bind(autolinkUseRegex.selectedProperty().not());
fulltextIndex.selectedProperty().bindBidirectional(viewModel.fulltextIndexProperty());
fileNamePattern.valueProperty().bindBidirectional(viewModel.fileNamePatternProperty());
fileNamePattern.itemsProperty().bind(viewModel.defaultFileNamePatternsProperty());
fileDirectoryPattern.textProperty().bindBidirectional(viewModel.fileDirectoryPatternProperty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class LinkedFilesTabViewModel implements PreferenceTabViewModel {
private final StringProperty autolinkRegexKeyProperty = new SimpleStringProperty("");
private final ListProperty<String> defaultFileNamePatternsProperty =
new SimpleListProperty<>(FXCollections.observableArrayList(FilePreferences.DEFAULT_FILENAME_PATTERNS));
private final BooleanProperty fulltextIndex = new SimpleBooleanProperty();
private final StringProperty fileNamePatternProperty = new SimpleStringProperty();
private final StringProperty fileDirectoryPatternProperty = new SimpleStringProperty();

Expand Down Expand Up @@ -76,6 +77,7 @@ public void setValues() {
mainFileDirectoryProperty.setValue(filePreferences.getFileDirectory().orElse(Path.of("")).toString());
useMainFileDirectoryProperty.setValue(!filePreferences.shouldStoreFilesRelativeToBibFile());
useBibLocationAsPrimaryProperty.setValue(filePreferences.shouldStoreFilesRelativeToBibFile());
fulltextIndex.setValue(filePreferences.shouldFulltextIndexLinkedFiles());
fileNamePatternProperty.setValue(filePreferences.getFileNamePattern());
fileDirectoryPatternProperty.setValue(filePreferences.getFileDirectoryPattern());

Expand All @@ -97,6 +99,7 @@ public void storeSettings() {
filePreferences.setFileNamePattern(fileNamePatternProperty.getValue());
filePreferences.setFileDirectoryPattern(fileDirectoryPatternProperty.getValue());
filePreferences.setDownloadLinkedFiles(filePreferences.shouldDownloadLinkedFiles()); // set in ImportEntriesViewModel
filePreferences.setFulltextIndexLinkedFiles(fulltextIndex.getValue());

// Autolink preferences
if (autolinkFileStartsBibtexProperty.getValue()) {
Expand Down Expand Up @@ -157,6 +160,10 @@ public StringProperty autolinkRegexKeyProperty() {
return autolinkRegexKeyProperty;
}

public BooleanProperty fulltextIndexProperty() {
return fulltextIndex;
}

public ListProperty<String> defaultFileNamePatternsProperty() {
return defaultFileNamePatternsProperty;
}
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/org/jabref/preferences/FilePreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class FilePreferences {
private final StringProperty fileNamePattern = new SimpleStringProperty();
private final StringProperty fileDirectoryPattern = new SimpleStringProperty();
private final BooleanProperty downloadLinkedFiles = new SimpleBooleanProperty();
private final BooleanProperty fulltextIndexLinkedFiles = new SimpleBooleanProperty();
private final ObjectProperty<Path> workingDirectory = new SimpleObjectProperty<>();

public FilePreferences(String user,
Expand All @@ -30,13 +31,15 @@ public FilePreferences(String user,
String fileNamePattern,
String fileDirectoryPattern,
boolean downloadLinkedFiles,
boolean fulltextIndexLinkedFiles,
Path workingDirectory) {
this.user.setValue(user);
this.mainFileDirectory.setValue(mainFileDirectory);
this.storeFilesRelativeToBibFile.setValue(storeFilesRelativeToBibFile);
this.fileNamePattern.setValue(fileNamePattern);
this.fileDirectoryPattern.setValue(fileDirectoryPattern);
this.downloadLinkedFiles.setValue(downloadLinkedFiles);
this.fulltextIndexLinkedFiles.setValue(fulltextIndexLinkedFiles);
this.workingDirectory.setValue(workingDirectory);
}

Expand Down Expand Up @@ -108,6 +111,18 @@ public void setDownloadLinkedFiles(boolean shouldDownloadLinkedFiles) {
this.downloadLinkedFiles.set(shouldDownloadLinkedFiles);
}

public boolean shouldFulltextIndexLinkedFiles() {
return fulltextIndexLinkedFiles.get();
}

public BooleanProperty fulltextIndexLinkedFilesProperty() {
return fulltextIndexLinkedFiles;
}

public void setFulltextIndexLinkedFiles(boolean shouldFulltextIndexLinkedFiles) {
this.fulltextIndexLinkedFiles.set(shouldFulltextIndexLinkedFiles);
}

public Path getWorkingDirectory() {
return workingDirectory.get();
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/jabref/preferences/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ public class JabRefPreferences implements PreferencesService {
// Dialog states
private static final String PREFS_EXPORT_PATH = "prefsExportPath";
private static final String DOWNLOAD_LINKED_FILES = "downloadLinkedFiles";
private static final String FULLTEXT_INDEX_LINKED_FILES = "fulltextIndexLinkedFiles";

// Helper string
private static final String USER_HOME = System.getProperty("user.home");
Expand Down Expand Up @@ -680,6 +681,8 @@ private JabRefPreferences() {
defaults.put(IMPORT_FILEDIRPATTERN, "");
// Download files by default
defaults.put(DOWNLOAD_LINKED_FILES, true);
// Create Fulltext-Index by default
defaults.put(FULLTEXT_INDEX_LINKED_FILES, true);

String defaultExpression = "**/.*[citationkey].*\\\\.[extension]";
defaults.put(AUTOLINK_REG_EXP_SEARCH_EXPRESSION_KEY, defaultExpression);
Expand Down Expand Up @@ -2180,6 +2183,7 @@ public FilePreferences getFilePreferences() {
get(IMPORT_FILENAMEPATTERN),
get(IMPORT_FILEDIRPATTERN),
getBoolean(DOWNLOAD_LINKED_FILES),
getBoolean(FULLTEXT_INDEX_LINKED_FILES),
Path.of(get(WORKING_DIRECTORY))
);

Expand All @@ -2188,6 +2192,7 @@ public FilePreferences getFilePreferences() {
EasyBind.listen(filePreferences.fileNamePatternProperty(), (obs, oldValue, newValue) -> put(IMPORT_FILENAMEPATTERN, newValue));
EasyBind.listen(filePreferences.fileDirectoryPatternProperty(), (obs, oldValue, newValue) -> put(IMPORT_FILEDIRPATTERN, newValue));
EasyBind.listen(filePreferences.downloadLinkedFilesProperty(), (obs, oldValue, newValue) -> putBoolean(DOWNLOAD_LINKED_FILES, newValue));
EasyBind.listen(filePreferences.fulltextIndexLinkedFilesProperty(), (obs, oldValue, newValue) -> putBoolean(FULLTEXT_INDEX_LINKED_FILES, newValue));
EasyBind.listen(filePreferences.workingDirectoryProperty(), (obs, oldValue, newValue) -> put(WORKING_DIRECTORY, newValue.toString()));

return filePreferences;
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2371,6 +2371,8 @@ Query=Query
Question=Question
Select\ directory=Select directory
Fulltext\ Index=Fulltext Index
Automatically\ index\ all\ linked\ files\ for\ fulltext\ search=Automatically index all linked files for fulltext search
Rebuild\ fulltext\ search\ index=Rebuild fulltext search index
Rebuild\ fulltext\ search\ index\ for\ current\ library?=Rebuild fulltext search index for current library?
Rebuilding\ fulltext\ search\ index...=Rebuilding fulltext search index...
Expand Down

0 comments on commit c1c79a0

Please sign in to comment.