aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2017-03-15 16:23:07 +0100
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2017-03-16 08:53:13 +0100
commit9db4eb325adf58b3c51bc7ae0bce65a361e98a74 (patch)
tree8d460bbadc27805b1a5f6013e68979d650329dc8
parent6cb42ee9a2ce16ff0203ba7bd738b71931b560c2 (diff)
downloadsonarqube-9db4eb325adf58b3c51bc7ae0bce65a361e98a74.tar.gz
sonarqube-9db4eb325adf58b3c51bc7ae0bce65a361e98a74.zip
SONAR-8840 WS api/project_tags/search is lexically ordered
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/measure/index/ProjectMeasuresIndex.java3
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTest.java17
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/projecttag/ws/SearchActionTest.java11
3 files changed, 28 insertions, 3 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/index/ProjectMeasuresIndex.java b/server/sonar-server/src/main/java/org/sonar/server/measure/index/ProjectMeasuresIndex.java
index fe64103bbfc..9892a11d5c8 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/measure/index/ProjectMeasuresIndex.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/measure/index/ProjectMeasuresIndex.java
@@ -315,7 +315,8 @@ public class ProjectMeasuresIndex extends BaseIndex {
TermsBuilder tagFacet = AggregationBuilders.terms(FIELD_TAGS)
.field(FIELD_TAGS)
.size(pageSize)
- .minDocCount(1);
+ .minDocCount(1)
+ .order(Terms.Order.term(true));
if (textQuery != null) {
tagFacet.include(".*" + escapeSpecialRegexChars(textQuery) + ".*");
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTest.java
index f8f001a61c8..c8d441acf52 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTest.java
@@ -1174,7 +1174,7 @@ public class ProjectMeasuresIndexTest {
List<String> result = underTest.searchTags("off", 10);
- assertThat(result).containsExactly("offshore", "official", "Madhoff");
+ assertThat(result).containsOnly("offshore", "official", "Madhoff");
}
@Test
@@ -1193,6 +1193,21 @@ public class ProjectMeasuresIndexTest {
}
@Test
+ public void search_tags_in_lexical_order() {
+ index(
+ newDoc().setTags(newArrayList("finance", "offshore", "java")),
+ newDoc().setTags(newArrayList("official", "javascript")),
+ newDoc().setTags(newArrayList("marketing", "official")),
+ newDoc().setTags(newArrayList("marketing", "Madhoff")),
+ newDoc().setTags(newArrayList("finance", "offshore")),
+ newDoc().setTags(newArrayList("offshore")));
+
+ List<String> result = underTest.searchTags(null, 10);
+
+ assertThat(result).containsExactly("Madhoff", "finance", "java", "javascript", "marketing", "official", "offshore");
+ }
+
+ @Test
public void search_tags_only_of_authorized_projects() {
indexForUser(USER1,
newDoc(PROJECT1).setTags(singletonList("finance")),
diff --git a/server/sonar-server/src/test/java/org/sonar/server/projecttag/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/projecttag/ws/SearchActionTest.java
index 3d151e14117..0438f15d6d8 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/projecttag/ws/SearchActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/projecttag/ws/SearchActionTest.java
@@ -88,7 +88,16 @@ public class SearchActionTest {
SearchResponse result = call("off", 2);
- assertThat(result.getTagsList()).containsOnly("offshore", "playoff");
+ assertThat(result.getTagsList()).containsOnly("offshore", "official");
+ }
+
+ @Test
+ public void search_in_lexical_order() {
+ index(newDoc().setTags(newArrayList("offshore", "official", "Playoff")));
+
+ SearchResponse result = call(null, null);
+
+ assertThat(result.getTagsList()).containsExactly("Playoff", "official", "offshore");
}
@Test