-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -55,13 +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 PseudoClass CLASS_NO_RESULTS = PseudoClass.getPseudoClass("emptyResult"); | ||
private static final PseudoClass CLASS_RESULTS_FOUND = PseudoClass.getPseudoClass("emptyResult"); | ||
private static final Logger LOGGER = LoggerFactory.getLogger(GlobalSearchBar.class); | ||
|
||
private final JabRefFrame frame; | ||
|
||
|
@@ -80,7 +85,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 | ||
|
@@ -186,7 +191,13 @@ public void actionPerformed(ActionEvent e) { | |
updateSearchModeButtonText(); | ||
searchModeButton.addActionListener(event -> toggleSearchModeAndSearch()); | ||
|
||
EasyBind.subscribe(searchField.textProperty(), searchText -> performSearch()); | ||
//Add a delay of 400 milliseconds before starting search | ||
Timer searchTask = FxTimer.create(Duration.ofMillis(400), () -> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe extract the search delay as a constant |
||
LOGGER.debug("Run search " + searchField.getText()); | ||
performSearch(); | ||
}); | ||
searchField.textProperty().addListener((observable, oldValue, newValue) -> searchTask.restart()); | ||
|
||
|
||
container = CustomJFXPanel.create(); | ||
DefaultTaskExecutor.runInJavaFXThread(() -> { | ||
|
@@ -246,7 +257,10 @@ 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() | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logger should be first attribute in the class