103103public class SwingSearchBar extends JTextField {
104104
105105 private static final String DEFAULT_MESSAGE = "Click here to search" ;
106- private static final int MAX_RESULTS = 8 ;
107106
108107 private static final Color SEARCHBAR_FONT_COLOR = new Color (0 , 0 , 0 );
109108 private static final Color SEARCHBAR_FONT_DEFAULT_COLOR = new Color (150 , 150 ,
@@ -128,6 +127,9 @@ public class SwingSearchBar extends JTextField {
128127
129128 private final JButton exitButton ;
130129
130+ /** The maximum number of results per search category. */
131+ private int resultLimit = 8 ;
132+
131133 private String searchTerm ;
132134
133135 public SwingSearchBar (final Context context ) {
@@ -194,6 +196,19 @@ public void activate() {
194196 });
195197 }
196198
199+ /** Gets the maximum number of results per search category. */
200+ public int getResultLimit () {
201+ return resultLimit ;
202+ }
203+
204+ /** Sets the maximum number of results per search category. */
205+ public void setResultLimit (final int resultLimit ) {
206+ if (resultLimit <= 0 ) {
207+ throw new IllegalArgumentException ("Limit must be positive" );
208+ }
209+ this .resultLimit = resultLimit ;
210+ }
211+
197212 // -- Utility methods --
198213
199214 // TODO: Move this method to PluginService.
@@ -615,9 +630,9 @@ private void rebuild() {
615630
616631 if (completeResults .isEmpty ()) continue ;
617632
618- // Limit to the top MAX_RESULTS matches only.
633+ // Limit to the top matches only.
619634 final List <SearchResult > results = completeResults .stream () //
620- .limit (MAX_RESULTS ).collect (Collectors .toList ());
635+ .limit (resultLimit ).collect (Collectors .toList ());
621636
622637 // Add results as entries.
623638 for (final SearchResult result : results ) {
0 commit comments