@@ -83,18 +83,17 @@ public List<SearchResult> search(final String text, final boolean fuzzy) {
8383
8484 // First, add modules where title starts with the text.
8585 modules .stream () //
86- .filter (info -> title ( info ). toLowerCase (). startsWith (textLower )) //
86+ .filter (info -> startsWith (info , textLower ) ) //
8787 .forEach (matches ::add );
8888
8989 // Next, add modules where title has text inside somewhere.
9090 modules .stream () //
91- .filter (info -> matches ( title ( info ). toLowerCase () , textLower )) //
91+ .filter (info -> hasSubstring ( info , textLower )) //
9292 .forEach (matches ::add );
9393
9494 // Finally, add modules where menu path has text inside somewhere.
9595 modules .stream () //
96- .filter (info -> matches (info .getMenuPath ().toString ().toLowerCase (),
97- textLower )) //
96+ .filter (info -> hasSubstring (info , textLower )) //
9897 .forEach (matches ::add );
9998
10099 // Wrap each matching ModuleInfo in a ModuleSearchResult.
@@ -157,9 +156,16 @@ private boolean isGoodModule(final ModuleInfo info) {
157156 title (info ) != null ;
158157 }
159158
160- private boolean matches (final String actual , final String desired ) {
161- // TODO: Implement fuzzy matching option, and maybe case sensitive option.
162- // Probably put it in the SearchService itself, and make an API toggle.
163- return actual .matches (".*" + desired + ".*" );
159+ private boolean startsWith (final ModuleInfo info , final String desiredLower ) {
160+ final String title = title (info );
161+ return title != null && title .toLowerCase ().startsWith (desiredLower );
162+ }
163+
164+ private boolean hasSubstring (final ModuleInfo info ,
165+ final String desiredLower )
166+ {
167+ final String title = title (info );
168+ return title != null && //
169+ title .toLowerCase ().matches (".*" + desiredLower + ".*" );
164170 }
165171}
0 commit comments