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

Implement test cases for search #10193

Merged
merged 74 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from 65 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
c93a22b
Move search folder to logic
Luggas4you Aug 20, 2023
d789dd3
Add testEmptyLibrarySearch
Luggas4you Aug 20, 2023
2688d17
Add initializeDatabaseFromPath
Luggas4you Aug 20, 2023
ab36944
Add TestLibraryA & testUpperAndLowerWordSearch
Luggas4you Aug 20, 2023
2383a15
Add testSimpleSingleFieldSearch
Luggas4you Aug 20, 2023
032ea25
Add testSimpleMultipleFieldSearch
Luggas4you Aug 20, 2023
97d2b82
Add testSensitiveWordSearch
Luggas4you Aug 20, 2023
0b2cc9b
Add testSensitiveMutipleFieldSearch
Luggas4you Aug 20, 2023
5ac3848
Add BibEntries for test-library-B
Luggas4you Aug 20, 2023
7a3012e
Add testSimpleRegularExpression
Luggas4you Aug 20, 2023
461b1d3
Add testSensitiveRegularExpression
Luggas4you Aug 20, 2023
e448d65
SimplePDFFulltextSearch WIP
Luggas4you Aug 25, 2023
7e73fcb
Change set.Files to add.File
Luggas4you Aug 28, 2023
7c28794
Add testSimplePDFNoteFulltextSearch WIP
Luggas4you Aug 30, 2023
d1a9c84
Move indexer
Luggas4you Aug 30, 2023
d9d84a2
Add missing @Tests to SearchFunctionalityTest.java WIP
Luggas4you Sep 30, 2023
dbcf01d
WIP
Luggas4you Oct 1, 2023
c34d308
Exclude non-functional @Tests
Luggas4you Oct 6, 2023
ec9d961
Merge branch 'main' into searchtestcases
koppor Jan 2, 2024
0612d31
Add withFiles
koppor Jan 2, 2024
2ea65a6
Remove empty lines
koppor Jan 2, 2024
f38e39d
@NullMarked for LinkedFile
koppor Jan 2, 2024
6e42ece
Fix Logger parameter
koppor Jan 2, 2024
e1844fd
Streamline tests
koppor Jan 3, 2024
df9c069
Fix checkstyle
koppor Jan 3, 2024
ebaaf4a
Refine tests
koppor Jan 6, 2024
1d8b17c
Get rid of missing "identity" formatter
koppor Jan 6, 2024
06cebdf
Minimize test files
koppor Jan 6, 2024
40d8022
Remove obsolete method (and make indexer class variable to speedup)
koppor Jan 6, 2024
c475550
Fix filenames
koppor Jan 7, 2024
d92b425
Some refactorings
koppor Jan 7, 2024
e081044
Revert global indexer mapping (does not work)
koppor Jan 7, 2024
3a0dde6
Revert "Revert global indexer mapping (does not work)"
koppor Jan 7, 2024
9e81a9a
Small code updates
koppor Jan 7, 2024
7e49053
Rename test files
koppor Jan 7, 2024
d888e6f
Some more logging
koppor Jan 7, 2024
f9f368b
Refine transaction boundaries (and some minor tweaks)
koppor Jan 7, 2024
4cbcf9b
Add TODO
koppor Jan 7, 2024
660f31c
Fix off-by-one error
koppor Jan 7, 2024
06e49ba
Remove non-used .bib file
koppor Jan 7, 2024
5e6213b
Refine comments
koppor Jan 7, 2024
b682b90
Fix variable assignment
koppor Jan 7, 2024
dd065e3
test-library-A -> test-library-title-casing
koppor Jan 7, 2024
407308e
Merge test cases of library-B.bib into title-casing.bib
koppor Jan 7, 2024
825e219
Merge branch 'main' into searchtestcases
koppor Jan 7, 2024
ac0ae7d
Increase transaction boundary for index addition/removal
koppor Jan 7, 2024
5ab3b37
Merge branch 'searchtestcases' of https://github.com/Luggas4you/jabre…
koppor Jan 7, 2024
dce3b9e
More readable directory names for index directory
koppor Jan 7, 2024
603ec36
WIP: Introduce PdfIndexerManager
koppor Jan 7, 2024
4497943
Preparation for "fulltext search not checking all attached files upon…
koppor Jan 8, 2024
c2b4f16
Use "right" factory (and rename factor getter)
koppor Jan 8, 2024
1c1a1b3
Fix FullTextSeachRule (refactoring introduced a bug)
koppor Jan 8, 2024
f102b21
Revert property for recheck of attached files
koppor Jan 8, 2024
0cce22c
Fix linting issues
koppor Jan 8, 2024
9672c48
Fix Formatters optimization
koppor Jan 8, 2024
4455dc4
Merge branch 'main' into searchtestcases
koppor Jan 8, 2024
5374efd
Fix test
koppor Jan 8, 2024
ff24c3d
Exception for architecture
koppor Jan 8, 2024
7e2e738
Refine .gitignore
koppor Jan 8, 2024
2b2bc64
Add missing }
koppor Jan 8, 2024
2386718
Merge remote-tracking branch 'upstream/main' into searchtestcases
koppor Jan 8, 2024
a1ef7fd
Do not search for PDF files in case of an exception of a search
koppor Jan 8, 2024
be63cdc
Remove duplicate code (and unneccsary pre-fetch of search results)
koppor Jan 8, 2024
ad9fb68
Add exception for test
koppor Jan 8, 2024
4a325c0
Merge branch 'main' into searchtestcases
koppor Jan 8, 2024
8da2b33
Remove ".getMessage()"
koppor Jan 8, 2024
2cd8184
Move comment and remove obsolete variable
koppor Jan 8, 2024
1bd6402
Fix typo
koppor Jan 8, 2024
f4cbbf7
Fix name
koppor Jan 8, 2024
f15f2be
Add dot
koppor Jan 8, 2024
807ce2f
Add comment
koppor Jan 8, 2024
e597a17
Call splitting method
koppor Jan 8, 2024
751c4b4
Add JavaDocComment
koppor Jan 8, 2024
af10895
Revert lambdas
koppor Jan 8, 2024
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
### Changed

- The Custom export format now uses the custom DOI base URI in the preferences for the `DOICheck`, if activated [forum#4084](https://discourse.jabref.org/t/export-html-disregards-custom-doi-base-uri/4084)
- The index directories for full text search have now more readable names to increase debugging possibilities using Apache Lucense's Lurk. [#10193](https://github.com/JabRef/jabref/issues/10193)
- The fulltext search also indexes files ending with .pdf (but do not having an explicit file type set). [#10193](https://github.com/JabRef/jabref/issues/10193)
- We changed the order of the lists in the "Citation relations" tab. `Cites` are now on the left and `Cited by` on the right [#10572](https://github.com/JabRef/jabref/pull/10752)

### Fixed

- We fixed an issue where attempting to cancel the importing/generation of an entry from id is ignored. [#10508](https://github.com/JabRef/jabref/issues/10508)
- We fixed an issue where the preview panel showing the wrong entry (an entry that is not selected in the entry table). [#9172](https://github.com/JabRef/jabref/issues/9172)
- The last page of a PDF is now indexed by the full text search. [#10193](https://github.com/JabRef/jabref/issues/10193)
- We fixed an issue where the duplicate check did not take umlauts or other LaTeX-encoded characters into account. [#10744](https://github.com/JabRef/jabref/pull/10744)
- We fixed the colors of the icon on hover for unset special fields. [#10431](https://github.com/JabRef/jabref/issues/10431)

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/jabref/gui/JabRefExecutorService.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

import org.jabref.logic.pdf.search.PdfIndexerManager;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -146,6 +148,8 @@ public void shutdownEverything() {
gracefullyShutdown(this.executorService);
gracefullyShutdown(this.lowPriorityExecutorService);

PdfIndexerManager.shutdownAllIndexers();

timer.cancel();
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.jabref.logic.importer.ImportCleanup;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.pdf.search.PdfIndexerManager;
import org.jabref.logic.shared.DatabaseLocation;
import org.jabref.logic.undo.AddUndoableActionEvent;
import org.jabref.logic.undo.UndoChangeEvent;
Expand Down Expand Up @@ -862,6 +863,7 @@ public void closeTab(LibraryTab libraryTab) {
}
AutosaveManager.shutdown(context);
BackupManager.shutdown(context, prefs.getFilePreferences().getBackupDirectory(), prefs.getFilePreferences().shouldCreateBackup());
PdfIndexerManager.shutdownAllIndexers();
}

private void removeTab(LibraryTab libraryTab) {
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/org/jabref/gui/LibraryTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@
import org.jabref.logic.importer.util.FileFieldParser;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.pdf.FileAnnotationCache;
import org.jabref.logic.pdf.search.indexing.IndexingTaskManager;
import org.jabref.logic.pdf.search.indexing.PdfIndexer;
import org.jabref.logic.pdf.search.IndexingTaskManager;
import org.jabref.logic.pdf.search.PdfIndexer;
import org.jabref.logic.pdf.search.PdfIndexerManager;
import org.jabref.logic.search.SearchQuery;
import org.jabref.logic.shared.DatabaseLocation;
import org.jabref.logic.util.UpdateField;
Expand Down Expand Up @@ -233,7 +234,7 @@ public void onDatabaseLoadingSucceed(ParserResult result) {

if (preferencesService.getFilePreferences().shouldFulltextIndexLinkedFiles()) {
try {
indexingTaskManager.updateIndex(PdfIndexer.of(bibDatabaseContext, preferencesService.getFilePreferences()), bibDatabaseContext);
indexingTaskManager.updateIndex(PdfIndexerManager.getIndexer(bibDatabaseContext, preferencesService.getFilePreferences()), bibDatabaseContext);
} catch (IOException e) {
LOGGER.error("Cannot access lucene index", e);
}
Expand Down Expand Up @@ -912,10 +913,8 @@ private class IndexUpdateListener {
public void listen(EntriesAddedEvent addedEntryEvent) {
if (preferencesService.getFilePreferences().shouldFulltextIndexLinkedFiles()) {
try {
PdfIndexer pdfIndexer = PdfIndexer.of(bibDatabaseContext, preferencesService.getFilePreferences());
for (BibEntry addedEntry : addedEntryEvent.getBibEntries()) {
indexingTaskManager.addToIndex(pdfIndexer, addedEntry, bibDatabaseContext);
}
PdfIndexer pdfIndexer = PdfIndexerManager.getIndexer(bibDatabaseContext, preferencesService.getFilePreferences());
indexingTaskManager.addToIndex(pdfIndexer, addedEntryEvent.getBibEntries());
} catch (IOException e) {
LOGGER.error("Cannot access lucene index", e);
}
Expand All @@ -926,7 +925,7 @@ public void listen(EntriesAddedEvent addedEntryEvent) {
public void listen(EntriesRemovedEvent removedEntriesEvent) {
if (preferencesService.getFilePreferences().shouldFulltextIndexLinkedFiles()) {
try {
PdfIndexer pdfIndexer = PdfIndexer.of(bibDatabaseContext, preferencesService.getFilePreferences());
PdfIndexer pdfIndexer = PdfIndexerManager.getIndexer(bibDatabaseContext, preferencesService.getFilePreferences());
for (BibEntry removedEntry : removedEntriesEvent.getBibEntries()) {
indexingTaskManager.removeFromIndex(pdfIndexer, removedEntry);
}
Expand All @@ -949,8 +948,9 @@ public void listen(FieldChangedEvent fieldChangedEvent) {
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);
PdfIndexer indexer = PdfIndexerManager.getIndexer(bibDatabaseContext, preferencesService.getFilePreferences());
indexingTaskManager.addToIndex(indexer, fieldChangedEvent.getBibEntry(), addedFiles);
indexingTaskManager.removeFromIndex(indexer, removedFiles);
} catch (IOException e) {
LOGGER.warn("I/O error when writing lucene index", e);
}
Expand Down
7 changes: 0 additions & 7 deletions src/main/java/org/jabref/gui/StateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;

import javafx.beans.Observable;
import javafx.beans.binding.Bindings;
Expand All @@ -31,7 +30,6 @@
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.groups.GroupTreeNode;
import org.jabref.model.util.OptionalUtil;

import com.tobiasdiez.easybind.EasyBind;
import com.tobiasdiez.easybind.EasyBinding;
Expand Down Expand Up @@ -144,11 +142,6 @@ public void setActiveDatabase(BibDatabaseContext database) {
}
}

public List<BibEntry> getEntriesInCurrentDatabase() {
return OptionalUtil.flatMap(activeDatabase.get(), BibDatabaseContext::getEntries)
.collect(Collectors.toList());
}

public void clearSearchQuery() {
activeSearchQuery.setValue(Optional.empty());
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/entryeditor/CommentsTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.pdf.search.indexing.IndexingTaskManager;
import org.jabref.logic.pdf.search.IndexingTaskManager;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.Field;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.pdf.search.indexing.IndexingTaskManager;
import org.jabref.logic.pdf.search.IndexingTaskManager;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.database.BibDatabaseMode;
import org.jabref.model.entry.BibEntry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import org.jabref.gui.theme.ThemeManager;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.pdf.search.indexing.IndexingTaskManager;
import org.jabref.logic.pdf.search.IndexingTaskManager;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.Field;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.pdf.search.indexing.IndexingTaskManager;
import org.jabref.logic.pdf.search.IndexingTaskManager;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.preferences.PreferencesService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.pdf.search.indexing.IndexingTaskManager;
import org.jabref.logic.pdf.search.IndexingTaskManager;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.preferences.PreferencesService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.pdf.search.indexing.IndexingTaskManager;
import org.jabref.logic.pdf.search.IndexingTaskManager;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.database.BibDatabaseMode;
import org.jabref.model.entry.BibEntry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.pdf.search.indexing.IndexingTaskManager;
import org.jabref.logic.pdf.search.IndexingTaskManager;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.database.BibDatabaseMode;
import org.jabref.model.entry.BibEntry;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/entryeditor/PreviewTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.jabref.gui.theme.ThemeManager;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.pdf.search.indexing.IndexingTaskManager;
import org.jabref.logic.pdf.search.IndexingTaskManager;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.preferences.PreferencesService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.pdf.search.indexing.IndexingTaskManager;
import org.jabref.logic.pdf.search.IndexingTaskManager;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.BibEntryType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.jabref.gui.theme.ThemeManager;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.pdf.search.indexing.IndexingTaskManager;
import org.jabref.logic.pdf.search.IndexingTaskManager;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.Field;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.jabref.logic.exporter.SelfContainedSaveConfiguration;
import org.jabref.logic.l10n.Encodings;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.pdf.search.PdfIndexerManager;
import org.jabref.logic.shared.DatabaseLocation;
import org.jabref.logic.shared.prefs.SharedDatabasePreferences;
import org.jabref.logic.util.StandardFileType;
Expand Down Expand Up @@ -141,9 +142,9 @@ boolean saveAs(Path file, SaveDatabaseMode mode) {
Optional<Path> databasePath = context.getDatabasePath();
if (databasePath.isPresent()) {
final Path oldFile = databasePath.get();
context.setDatabasePath(oldFile);
AutosaveManager.shutdown(context);
BackupManager.shutdown(context, this.preferences.getFilePreferences().getBackupDirectory(), preferences.getFilePreferences().shouldCreateBackup());
PdfIndexerManager.shutdownIndexer(context);
}

// Set new location
Expand All @@ -164,6 +165,7 @@ boolean saveAs(Path file, SaveDatabaseMode mode) {
// Reset (here: uninstall and install again) AutosaveManager and BackupManager for the new file name
libraryTab.resetChangeMonitor();
libraryTab.installAutosaveManagerAndBackupManager();
// PdfIndexerManager does not need to be called; the method {@link org.jabref.logic.pdf.search.PdfIndexerManager.get()} is called if a new indexer is needed

preferences.getGuiPreferences().getFileHistory().newFile(file);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import org.jabref.logic.cleanup.MoveFilesCleanup;
import org.jabref.logic.cleanup.RenamePdfCleanup;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.pdf.search.indexing.IndexingTaskManager;
import org.jabref.logic.pdf.search.indexing.PdfIndexer;
import org.jabref.logic.pdf.search.IndexingTaskManager;
import org.jabref.logic.pdf.search.PdfIndexerManager;
import org.jabref.logic.util.io.FileNameCleaner;
import org.jabref.logic.util.io.FileUtil;
import org.jabref.model.database.BibDatabaseContext;
Expand Down Expand Up @@ -87,7 +87,7 @@ public void moveFilesToFileDirRenameAndAddToEntry(BibEntry entry, List<Path> fil
}

try {
indexingTaskManager.addToIndex(PdfIndexer.of(bibDatabaseContext, filePreferences), entry, bibDatabaseContext);
indexingTaskManager.addToIndex(PdfIndexerManager.getIndexer(bibDatabaseContext, filePreferences), entry);
} catch (IOException e) {
LOGGER.error("Could not access Fulltext-Index", e);
}
Expand All @@ -105,9 +105,9 @@ public void copyFilesToFileDirAndAddToEntry(BibEntry entry, List<Path> files, In
}

try {
indexingTaskManager.addToIndex(PdfIndexer.of(bibDatabaseContext, filePreferences), entry, bibDatabaseContext);
indexingTaskManager.addToIndex(PdfIndexerManager.getIndexer(bibDatabaseContext, filePreferences), entry);
} catch (IOException e) {
LOGGER.error("Could not access Fulltext-Index", e);
LOGGER.error("Could not access fulltext index", e);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/preview/PreviewPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.jabref.gui.theme.ThemeManager;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.pdf.search.indexing.IndexingTaskManager;
import org.jabref.logic.pdf.search.IndexingTaskManager;
import org.jabref.logic.preview.PreviewLayout;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import org.jabref.gui.util.BackgroundTask;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.pdf.search.indexing.PdfIndexer;
import org.jabref.logic.pdf.search.PdfIndexer;
import org.jabref.logic.pdf.search.PdfIndexerManager;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.preferences.FilePreferences;

Expand Down Expand Up @@ -74,8 +75,8 @@ private void rebuildIndex() {
return;
}
try {
currentLibraryTab.get().getIndexingTaskManager().createIndex(PdfIndexer.of(databaseContext, filePreferences));
currentLibraryTab.get().getIndexingTaskManager().updateIndex(PdfIndexer.of(databaseContext, filePreferences), databaseContext);
PdfIndexer indexer = PdfIndexerManager.getIndexer(databaseContext, filePreferences);
currentLibraryTab.get().getIndexingTaskManager().rebuildIndex(indexer);
} catch (IOException e) {
dialogService.notify(Localization.lang("Failed to access fulltext search index"));
LOGGER.error("Failed to access fulltext search index", e);
Expand Down
17 changes: 10 additions & 7 deletions src/main/java/org/jabref/logic/cleanup/FieldFormatterCleanups.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,16 @@ public static FieldFormatterCleanups parse(List<String> formatterMetaList) {
}

static Formatter getFormatterFromString(String formatterName) {
for (Formatter formatter : Formatters.getAll()) {
if (formatterName.equals(formatter.getKey())) {
return formatter;
}
}
LOGGER.info("Formatter {} not found.", formatterName);
return new IdentityFormatter();
return Formatters
.getFormatterForName(formatterName)
.orElseGet(() -> {
if (!"identity".equals(formatterName)) {
// The identity formatter is not listed in the formatters list, but is still valid
// Therefor, we log errors in other cases only
LOGGER.info("Formatter {} not found.", formatterName);
}
return new IdentityFormatter();
});
}

@Override
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/org/jabref/logic/formatter/Formatters.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import org.jabref.logic.cleanup.Formatter;
import org.jabref.logic.formatter.bibtexfields.CleanupUrlFormatter;
Expand Down Expand Up @@ -40,6 +42,12 @@
public class Formatters {
private static final Pattern TRUNCATE_PATTERN = Pattern.compile("\\Atruncate\\d+\\z");

private static Map<String, Formatter> keyToFormatterMap;

static {
keyToFormatterMap = getAll().stream().collect(Collectors.toMap(Formatter::getKey, f -> f));
}

private Formatters() {
}

Expand Down Expand Up @@ -92,6 +100,11 @@ public static List<Formatter> getAll() {
return all;
}

public static Optional<Formatter> getFormatterForName(String name) {
Objects.requireNonNull(name);
return keyToFormatterMap.containsKey(name) ? Optional.of(keyToFormatterMap.get(name)) : Optional.empty();
}

public static Optional<Formatter> getFormatterForModifier(String modifier) {
Objects.requireNonNull(modifier);

Expand All @@ -115,7 +128,7 @@ public static Optional<Formatter> getFormatterForModifier(String modifier) {
int truncateAfter = Integer.parseInt(modifier.substring(8));
return Optional.of(new TruncateFormatter(truncateAfter));
} else {
return getAll().stream().filter(f -> f.getKey().equals(modifier)).findAny();
return getFormatterForName(modifier);
}
}
}
Loading
Loading