Skip to content

Commit 2cd5824

Browse files
committed
ModuleSearcher: Fix menu search
1 parent d6a4ccb commit 2cd5824

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/main/java/org/scijava/search/module/ModuleSearcher.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ public List<SearchResult> search(final String text, final boolean fuzzy) {
8888

8989
// Next, add modules where title has text inside somewhere.
9090
modules.stream() //
91-
.filter(info -> hasSubstring(info, textLower)) //
91+
.filter(info -> hasSubstringInTitle(info, textLower)) //
9292
.forEach(matches::add);
9393

9494
// Finally, add modules where menu path has text inside somewhere.
9595
modules.stream() //
96-
.filter(info -> hasSubstring(info, textLower)) //
96+
.filter(info -> hasSubstringInMenu(info, textLower)) //
9797
.forEach(matches::add);
9898

9999
// Wrap each matching ModuleInfo in a ModuleSearchResult.
@@ -160,11 +160,19 @@ private boolean startsWith(final ModuleInfo info, final String desiredLower) {
160160
return title != null && title.toLowerCase().startsWith(desiredLower);
161161
}
162162

163-
private boolean hasSubstring(final ModuleInfo info,
164-
final String desiredLower)
163+
private boolean hasSubstringInTitle(final ModuleInfo info,
164+
final String desiredLower)
165165
{
166166
final String title = title(info);
167167
return title != null && //
168168
title.toLowerCase().matches(".*" + desiredLower + ".*");
169169
}
170+
171+
private boolean hasSubstringInMenu(final ModuleInfo info,
172+
final String desiredLower)
173+
{
174+
MenuPath menuPath = info.getMenuPath();
175+
if(menuPath == null) return false;
176+
return menuPath.stream().anyMatch(entry -> entry.getName().toLowerCase().contains(desiredLower));
177+
}
170178
}

0 commit comments

Comments
 (0)