diff options
author | Michal Duda <michal.duda@sonarsource.com> | 2021-01-12 14:06:57 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2021-01-12 20:26:06 +0000 |
commit | c1f4f7790c70830e2f199751acb3006e31141bc7 (patch) | |
tree | d20ffdd0c48282b0a2a8b347eb504541ff2aeacd /server | |
parent | 064dddbf3b76b10232b9c11d86031c8c19c0a9aa (diff) | |
download | sonarqube-c1f4f7790c70830e2f199751acb3006e31141bc7.tar.gz sonarqube-c1f4f7790c70830e2f199751acb3006e31141bc7.zip |
SONAR-14325 fix rule search results no longer sorted by name
Diffstat (limited to 'server')
-rw-r--r-- | server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/SearchAction.java | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/SearchAction.java index f23a3da53d2..22e2025522b 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/SearchAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/SearchAction.java @@ -23,6 +23,7 @@ import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ListMultimap; import com.google.common.collect.Lists; +import com.google.common.collect.Maps; import com.google.common.collect.Ordering; import java.util.ArrayList; import java.util.Collection; @@ -236,8 +237,17 @@ public class SearchAction implements RulesWsAction { private SearchResult doSearch(DbSession dbSession, RuleQuery query, SearchOptions context) { SearchIdResult<String> result = ruleIndex.search(query, context); - List<RuleDto> rules = dbClient.ruleDao().selectByUuids(dbSession, result.getUuids()); - List<String> ruleUuids = rules.stream().map(RuleDto::getUuid).collect(Collectors.toList()); + List<String> ruleUuids = result.getUuids(); + // rule order is managed by ES, this order by must be kept when fetching rule details + Map<String, RuleDto> rulesByRuleKey = Maps.uniqueIndex(dbClient.ruleDao().selectByUuids(dbSession, ruleUuids), RuleDto::getUuid); + List<RuleDto> rules = new ArrayList<>(); + for (String ruleUuid : ruleUuids) { + RuleDto rule = rulesByRuleKey.get(ruleUuid); + if (rule != null) { + rules.add(rule); + } + } + List<String> templateRuleUuids = rules.stream() .map(RuleDto::getTemplateUuid) .filter(Objects::nonNull) |