@@ -429,8 +429,14 @@ private void rebuild() {
429429 // Build the new list model.
430430 DefaultListModel <SearchResult > listModel = new DefaultListModel <>();
431431 for (final Searcher searcher : searchers ) {
432- final List <SearchResult > results = results (searcher );
433- if (results .isEmpty ()) continue ;
432+ // Look up the results list.
433+ final List <SearchResult > completeResults = //
434+ allResults .get (searcher .getClass ()).results ();
435+ if (completeResults .isEmpty ()) continue ;
436+
437+ // Limit to the top MAX_RESULTS matches only.
438+ final List <SearchResult > results = completeResults .stream () //
439+ .limit (MAX_RESULTS ).collect (Collectors .toList ());
434440
435441 // Add section header.
436442 listModel .addElement (new SearchResultHeader (searcher .title ()));
@@ -447,12 +453,6 @@ private void rebuild() {
447453 else resultsList .setSelectedValue (previous , true );
448454 }
449455
450- private List <SearchResult > results (final Searcher searcher ) {
451- assertDispatchThread ();
452- return allResults .get (searcher .getClass ()).results ().stream ().limit (
453- MAX_RESULTS ).collect (Collectors .toList ());
454- }
455-
456456 private Component icon (final String iconPath ) {
457457 // TODO make icon() return URL, not String.
458458 if (iconPath == null || iconPath .isEmpty ()) return emptyIcon ();
0 commit comments