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);
}
DbSession session;
IssueIndex index;
RuleDto rule = RuleTesting.newXooX1();
- ComponentDto project = ComponentTesting.newProjectDto("P1");
+ ComponentDto project = ComponentTesting.newProjectDto("My-Project");
ComponentDto file;
ComponentDto file2;
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);
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();
}