From d89704376bf0add2f3ac04d57e16e6a7f0aaf39b Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Lievremont Date: Tue, 6 Jan 2015 11:25:53 +0100 Subject: [PATCH] SONAR-5959 Fix an issue with case sensitive search on UUID path --- .../sonar/server/es/DefaultIndexSettings.java | 2 +- .../sonar/server/issue/index/IssueIndex.java | 14 +++++----- .../issue/index/IssueIndexMediumTest.java | 28 ++++++++++++++++++- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/es/DefaultIndexSettings.java b/server/sonar-server/src/main/java/org/sonar/server/es/DefaultIndexSettings.java index 328ec30db51..c65805da3ba 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/es/DefaultIndexSettings.java +++ b/server/sonar-server/src/main/java/org/sonar/server/es/DefaultIndexSettings.java @@ -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"); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java index f83322c952b..21a9d72883b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java @@ -284,15 +284,15 @@ public class IssueIndex extends BaseIndex { 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); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexMediumTest.java index df73549e5b5..838e8a8b2ea 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexMediumTest.java @@ -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(); } -- 2.39.5