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

Improve search performance #3950

Merged
merged 3 commits into from
Apr 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ The new default removes the linked file from the entry instead of deleting the f
- We changed the metadata reading and writing. DublinCore is now the only metadata format, JabRef supports. (https://github.com/JabRef/jabref/pull/3710)
- We added another CLI functionality for reading and writing metadata to pdfs. (see https://github.com/JabRef/jabref/pull/3756 and see http://help.jabref.org/en/CommandLine)
- We no longer print errors in field values during autosave into the log [#3811](https://github.com/JabRef/jabref/issues/3811)
- We improved the search performance by adding a short delay before starting to display search results [Bug report in the forum](http://discourse.jabref.org/t/poor-performance-of-jabref-4/1110/2)

### Fixed
- We fixed several performance problems with the management of journal abbreviations [#3323](https://github.com/JabRef/jabref/issues/3323)
Expand Down
29 changes: 23 additions & 6 deletions src/main/java/org/jabref/gui/search/GlobalSearchBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import java.awt.event.ActionEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.io.File;
import java.nio.file.Path;
import java.time.Duration;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -55,11 +56,17 @@
import org.jabref.model.entry.BibEntry;
import org.jabref.preferences.SearchPreferences;

import org.fxmisc.easybind.EasyBind;
import org.reactfx.util.FxTimer;
import org.reactfx.util.Timer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@SuppressWarnings("Duplicates")
public class GlobalSearchBar extends JPanel {

private static final Logger LOGGER = LoggerFactory.getLogger(GlobalSearchBar.class);

private static final int SEARCH_DELAY = 400;
private static final PseudoClass CLASS_NO_RESULTS = PseudoClass.getPseudoClass("emptyResult");
private static final PseudoClass CLASS_RESULTS_FOUND = PseudoClass.getPseudoClass("emptyResult");

Expand All @@ -80,7 +87,7 @@ public class GlobalSearchBar extends JPanel {

private SearchDisplayMode searchDisplayMode;

private JLabel searchIcon = new JLabel(IconTheme.JabRefIcon.SEARCH.getIcon());
private final JLabel searchIcon = new JLabel(IconTheme.JabRefIcon.SEARCH.getIcon());

/**
* if this flag is set the searchbar won't be selected after the next search
Expand Down Expand Up @@ -186,7 +193,12 @@ public void actionPerformed(ActionEvent e) {
updateSearchModeButtonText();
searchModeButton.addActionListener(event -> toggleSearchModeAndSearch());

EasyBind.subscribe(searchField.textProperty(), searchText -> performSearch());
//Add a delay of SEARCH_DELAY milliseconds before starting search
Timer searchTask = FxTimer.create(Duration.ofMillis(SEARCH_DELAY), () -> {
LOGGER.debug("Run search " + searchField.getText());
performSearch();
});
searchField.textProperty().addListener((observable, oldValue, newValue) -> searchTask.restart());

container = CustomJFXPanel.create();
DefaultTaskExecutor.runInJavaFXThread(() -> {
Expand Down Expand Up @@ -246,10 +258,15 @@ private void openLocalFindingsInExternalPanel() {

SearchResultFrame searchDialog = new SearchResultFrame(currentBasePanel.frame(),
Localization.lang("Search results in library %0 for %1", currentBasePanel.getBibDatabaseContext()
.getDatabaseFile().map(File::getName).orElse(GUIGlobals.UNTITLED_TITLE),
.getDatabasePath()
.map(Path::getFileName)
.map(Path::toString)
.orElse(GUIGlobals.UNTITLED_TITLE),
this.getSearchQuery().localize()),
getSearchQuery(), false);
List<BibEntry> entries = currentBasePanel.getDatabase().getEntries().stream()
List<BibEntry> entries = currentBasePanel.getDatabase()
.getEntries()
.stream()
.filter(BibEntry::isSearchHit)
.collect(Collectors.toList());
searchDialog.addEntries(entries, currentBasePanel);
Expand Down