]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5959 Fix an issue with case sensitive search on UUID path
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Tue, 6 Jan 2015 10:25:53 +0000 (11:25 +0100)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Tue, 6 Jan 2015 12:44:52 +0000 (13:44 +0100)
server/sonar-server/src/main/java/org/sonar/server/es/DefaultIndexSettings.java
server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java
server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexMediumTest.java

index 328ec30db516b7dda97825456ae60eedd6032354..c65805da3ba30effa8ab201ca94626c434cb57b4 100644 (file)
@@ -87,7 +87,7 @@ class DefaultIndexSettings {
       .put("index.analysis.tokenizer.dot_tokenizer.type", "pattern")
       .put("index.analysis.tokenizer.dot_tokenizer.pattern", "\\.")
       .put("index.analysis.analyzer.uuid_analyzer.type", "custom")
-      .putArray("index.analysis.analyzer.uuid_analyzer.filter", "trim", "lowercase")
+      .putArray("index.analysis.analyzer.uuid_analyzer.filter", "trim")
       .put("index.analysis.analyzer.uuid_analyzer.tokenizer", "dot_tokenizer");
 
   }
index f83322c952bf18afc0729e2d7c1cb07f42e5dd9d..21a9d72883b1f816a11886d025c1940361422294 100644 (file)
@@ -284,15 +284,15 @@ public class IssueIndex extends BaseIndex<Issue, FakeIssueDto, String> {
 
       FilterBuilder componentFilter = matchFilter(IssueIndexDefinition.FIELD_ISSUE_COMPONENT_UUID, query.componentUuids());
       FilterBuilder modulePathFilter = matchFilter(IssueIndexDefinition.FIELD_ISSUE_MODULE_PATH, query.componentUuids());
-      BoolFilterBuilder compositeFilter = null;
-      if (componentFilter != null || modulePathFilter != null) {
-        compositeFilter = FilterBuilders.boolFilter();
-        if (componentFilter != null) {
-          compositeFilter.should(componentFilter);
-        }
+      FilterBuilder compositeFilter = null;
+      if (componentFilter != null) {
         if (modulePathFilter != null) {
-          compositeFilter.should(modulePathFilter);
+          compositeFilter = FilterBuilders.orFilter(componentFilter, modulePathFilter);
+        } else {
+          compositeFilter = componentFilter;
         }
+      } else if (modulePathFilter != null) {
+        compositeFilter = modulePathFilter;
       }
       filters.put(IssueIndexDefinition.FIELD_ISSUE_COMPONENT_UUID, compositeFilter);
     }
index df73549e5b59f3fa3d00a05d3ed8adb21074a3bb..838e8a8b2eaeb1c97c09c182d2c55cf06c8b1909 100644 (file)
@@ -73,7 +73,7 @@ public class IssueIndexMediumTest {
   DbSession session;
   IssueIndex index;
   RuleDto rule = RuleTesting.newXooX1();
-  ComponentDto project = ComponentTesting.newProjectDto("P1");
+  ComponentDto project = ComponentTesting.newProjectDto("My-Project");
   ComponentDto file;
   ComponentDto file2;
 
@@ -175,6 +175,30 @@ public class IssueIndexMediumTest {
     assertThat(index.search(IssueQuery.builder().issueKeys(newArrayList("3", "4")).build(), new QueryContext()).getHits()).isEmpty();
   }
 
+  @Test
+  public void filter_by_projects() throws Exception {
+    ComponentDto module = ComponentTesting.newModuleDto(project);
+    ComponentDto subModule = ComponentTesting.newModuleDto(module);
+    ComponentDto file1 = ComponentTesting.newFileDto(project);
+    ComponentDto file2 = ComponentTesting.newFileDto(module);
+    ComponentDto file3 = ComponentTesting.newFileDto(subModule);
+    tester.get(ComponentDao.class).insert(session, module, subModule, file1, file2, file3);
+
+    db.issueDao().insert(session,
+      IssueTesting.newDto(rule, project, project),
+      IssueTesting.newDto(rule, file1, project),
+      IssueTesting.newDto(rule, module, project),
+      IssueTesting.newDto(rule, file2, project),
+      IssueTesting.newDto(rule, subModule, project),
+      IssueTesting.newDto(rule, file3, project));
+    session.commit();
+    index();
+
+    assertThat(index.search(IssueQuery.builder().projectUuids(newArrayList(project.uuid())).build(), new QueryContext()).getHits()).hasSize(6);
+    assertThat(index.search(IssueQuery.builder().projectUuids(newArrayList(project.uuid())).onComponentOnly(true).build(), new QueryContext()).getHits()).hasSize(1);
+    assertThat(index.search(IssueQuery.builder().projectUuids(newArrayList("unknown")).build(), new QueryContext()).getHits()).isEmpty();
+  }
+
   @Test
   public void filter_by_modules() throws Exception {
     ComponentDto module = ComponentTesting.newModuleDto(project);
@@ -221,6 +245,8 @@ public class IssueIndexMediumTest {
     assertThat(index.search(IssueQuery.builder().componentUuids(newArrayList(subModule.uuid())).onComponentOnly(true).build(), new QueryContext()).getHits()).hasSize(1);
     assertThat(index.search(IssueQuery.builder().componentUuids(newArrayList(module.uuid())).build(), new QueryContext()).getHits()).hasSize(4);
     assertThat(index.search(IssueQuery.builder().componentUuids(newArrayList(module.uuid())).onComponentOnly(true).build(), new QueryContext()).getHits()).hasSize(1);
+    assertThat(index.search(IssueQuery.builder().componentUuids(newArrayList(project.uuid())).build(), new QueryContext()).getHits()).hasSize(6);
+    assertThat(index.search(IssueQuery.builder().componentUuids(newArrayList(project.uuid())).onComponentOnly(true).build(), new QueryContext()).getHits()).hasSize(1);
     assertThat(index.search(IssueQuery.builder().componentUuids(newArrayList("unknown")).build(), new QueryContext()).getHits()).isEmpty();
   }