diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/config/PluginHubPanel.java b/runelite-client/src/main/java/net/runelite/client/plugins/config/PluginHubPanel.java index a94c94a592..269cfe574f 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/config/PluginHubPanel.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/config/PluginHubPanel.java @@ -37,7 +37,9 @@ import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; import java.awt.image.BufferedImage; import java.io.IOException; +import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.Comparator; import java.util.HashSet; import java.util.List; @@ -45,7 +47,6 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ScheduledExecutorService; import java.util.function.Function; -import java.util.function.ToDoubleFunction; import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -85,8 +86,8 @@ import net.runelite.client.ui.components.IconTextField; import net.runelite.client.util.ImageUtil; import net.runelite.client.util.LinkBrowser; import net.runelite.client.util.SwingUtil; +import net.runelite.client.util.Text; import net.runelite.client.util.VerificationException; -import org.apache.commons.text.similarity.JaroWinklerDistance; @Slf4j @Singleton @@ -98,7 +99,6 @@ class PluginHubPanel extends PluginPanel private static final ImageIcon CONFIGURE_ICON; private static final ImageIcon CONFIGURE_ICON_HOVER; private static final Pattern SPACES = Pattern.compile(" +"); - private static final JaroWinklerDistance DISTANCE = new JaroWinklerDistance(); static { @@ -119,16 +119,13 @@ class PluginHubPanel extends PluginPanel private static final int HEIGHT = 70; private static final int ICON_WIDTH = 48; private static final int BOTTOM_LINE_HEIGHT = 16; - static final float MIN_FILTER_SCORE = .8f; private final ExternalPluginManifest manifest; + private final List keywords = new ArrayList<>(); @Getter private final boolean installed; - @Getter - private float filter; - PluginItem(ExternalPluginManifest newManifest, Collection loadedPlugins, boolean installed) { ExternalPluginManifest loaded = null; @@ -140,6 +137,23 @@ class PluginHubPanel extends PluginPanel manifest = newManifest == null ? loaded : newManifest; this.installed = installed; + if (manifest != null) + { + Collections.addAll(keywords, SPACES.split(manifest.getDisplayName().toLowerCase())); + + if (manifest.getDescription() != null) + { + Collections.addAll(keywords, SPACES.split(manifest.getDescription().toLowerCase())); + } + + Collections.addAll(keywords, manifest.getAuthor().toLowerCase()); + + if (manifest.getTags() != null) + { + Collections.addAll(keywords, manifest.getTags()); + } + } + setBackground(ColorScheme.DARKER_GRAY_COLOR); setOpaque(true); @@ -302,23 +316,6 @@ class PluginHubPanel extends PluginPanel .addComponent(addrm, BOTTOM_LINE_HEIGHT, BOTTOM_LINE_HEIGHT, BOTTOM_LINE_HEIGHT)) .addGap(5))); } - - float setFilter(String[] filter) - { - ToDoubleFunction match = r -> Stream.of(filter) - .mapToDouble(l -> Math.pow(DISTANCE.apply(l, r), 2)) - .max() - .orElse(0.D); - - double sim = SPACES.splitAsStream(manifest.getDisplayName()).collect(Collectors.averagingDouble(match)) * 2; - - if (manifest.getTags() != null) - { - sim += Stream.of(manifest.getTags()).mapToDouble(match).sum(); - } - - return this.filter = (float) sim; - } } private final PluginListPanel pluginListPanel; @@ -537,8 +534,8 @@ class PluginHubPanel extends PluginPanel { String[] searchArray = SPACES.split(search.toLowerCase()); stream = stream - .filter(p -> p.setFilter(searchArray) > PluginItem.MIN_FILTER_SCORE) - .sorted(Comparator.comparing(PluginItem::getFilter)); + .filter(p -> Text.matchesSearchTerms(searchArray, p.keywords)) + .sorted(Comparator.comparing(p -> p.manifest.getDisplayName())); } else {