better plugin search

This commit is contained in:
Sergey Ignatov
2015-04-27 17:55:50 +03:00
parent cc2c199b7b
commit 538f104f29
2 changed files with 16 additions and 30 deletions
@@ -607,34 +607,22 @@ public abstract class PluginManagerMain implements Disposable {
pluginTable.select(descriptors);
}
protected static boolean isAccepted(String filter,
Set<String> search,
IdeaPluginDescriptor descriptor) {
protected static boolean isAccepted(@Nullable String filter, @NotNull Set<String> search, @NotNull IdeaPluginDescriptor descriptor) {
if (StringUtil.isEmpty(filter)) return true;
if (isAccepted(search, filter, descriptor.getName())) {
return true;
}
else {
final String description = descriptor.getDescription();
if (description != null && isAccepted(search, filter, description)) {
return true;
}
final String category = descriptor.getCategory();
if (category != null && isAccepted(search, filter, category)) {
return true;
}
final String changeNotes = descriptor.getChangeNotes();
if (changeNotes != null && isAccepted(search, filter, changeNotes)) {
return true;
}
}
return false;
if (StringUtil.containsIgnoreCase(descriptor.getName(), filter) || isAccepted(search, filter, descriptor.getName())) return true;
if (isAccepted(search, filter, descriptor.getDescription())) return true;
String category = descriptor.getCategory();
return category != null && (StringUtil.containsIgnoreCase(category, filter) || isAccepted(search, filter, category));
}
private static boolean isAccepted(Set<String> search, @NotNull String filter, @NotNull String description) {
if (StringUtil.containsIgnoreCase(description, filter)) return true;
private static boolean isAccepted(@NotNull Set<String> search, @NotNull String filter, @Nullable String description) {
if (StringUtil.isEmpty(description)) return false;
if (filter.length() <= 2) return false;
Set<String> words = SearchableOptionsRegistrar.getInstance().getProcessedWords(description);
if (words.contains(filter)) return true;
if (search.isEmpty()) return false;
Set<String> descriptionSet = new HashSet<String>(search);
descriptionSet.removeAll(SearchableOptionsRegistrar.getInstance().getProcessedWords(description));
descriptionSet.removeAll(words);
return descriptionSet.isEmpty();
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -345,6 +345,7 @@ public class SearchUtil {
}
}
for (String stripped : quoted) {
if (registrar.isStopWord(stripped)) continue;
textToMarkup = markup(textToMarkup, insideHtmlTagPattern, stripped);
}
return head + textToMarkup + foot;
@@ -365,15 +366,12 @@ public class SearchUtil {
}
private static String markup(@NonNls String textToMarkup, final Pattern insideHtmlTagPattern, final String option) {
@NonNls String result = "";
final int styleIdx = textToMarkup.indexOf("<style");
final int styleEndIdx = textToMarkup.indexOf("</style>");
if (styleIdx < 0 || styleEndIdx < 0) {
result = markupInText(textToMarkup, insideHtmlTagPattern, option);
} else {
result = markup(textToMarkup.substring(0, styleIdx), insideHtmlTagPattern, option) + markup(textToMarkup.substring(styleEndIdx + STYLE_END.length()), insideHtmlTagPattern, option);
return markupInText(textToMarkup, insideHtmlTagPattern, option);
}
return result;
return markup(textToMarkup.substring(0, styleIdx), insideHtmlTagPattern, option) + markup(textToMarkup.substring(styleEndIdx + STYLE_END.length()), insideHtmlTagPattern, option);
}
private static String markupInText(String textToMarkup, Pattern insideHtmlTagPattern, String option) {