esSettings
.put("index.mapper.dynamic", false)
- // Sortable text analyzer
+ // Sortable text analyzer
.put("index.analysis.analyzer.sortable.type", "custom")
.put("index.analysis.analyzer.sortable.tokenizer", "keyword")
.putArray("index.analysis.analyzer.sortable.filter", "trim", "lowercase", "truncate")
- // Edge NGram index-analyzer
+ // Edge NGram index-analyzer
.put("index.analysis.analyzer.index_grams.type", "custom")
.put("index.analysis.analyzer.index_grams.tokenizer", "whitespace")
.putArray("index.analysis.analyzer.index_grams.filter", "trim", "lowercase", "gram_filter")
- // Edge NGram search-analyzer
+ // Edge NGram search-analyzer
.put("index.analysis.analyzer.search_grams.type", "custom")
.put("index.analysis.analyzer.search_grams.tokenizer", "whitespace")
.putArray("index.analysis.analyzer.search_grams.filter", "trim", "lowercase")
- // Word index-analyzer
+ // Word index-analyzer
.put("index.analysis.analyzer.index_words.type", "custom")
.put("index.analysis.analyzer.index_words.tokenizer", "standard")
.putArray("index.analysis.analyzer.index_words.filter",
"standard", "word_filter", "lowercase", "stop", "asciifolding", "porter_stem")
- // Word search-analyzer
+ // Word search-analyzer
.put("index.analysis.analyzer.search_words.type", "custom")
.put("index.analysis.analyzer.search_words.tokenizer", "standard")
.putArray("index.analysis.analyzer.search_words.filter",
"standard", "lowercase", "stop", "asciifolding", "porter_stem")
- // Edge NGram filter
+ // Edge NGram filter
.put("index.analysis.filter.gram_filter.type", "edgeNGram")
.put("index.analysis.filter.gram_filter.min_gram", 2)
.put("index.analysis.filter.gram_filter.max_gram", 15)
.putArray("index.analysis.filter.gram_filter.token_chars", "letter", "digit", "punctuation", "symbol")
- // Word filter
+ // Word filter
.put("index.analysis.filter.word_filter.type", "word_delimiter")
.put("index.analysis.filter.word_filter.generate_word_parts", true)
.put("index.analysis.filter.word_filter.catenate_words", true)
.put("index.analysis.filter.word_filter.split_on_numerics", true)
.put("index.analysis.filter.word_filter.stem_english_possessive", true)
- // Path Analyzer
+ // Path Analyzer
.put("index.analysis.analyzer.path_analyzer.type", "custom")
.put("index.analysis.analyzer.path_analyzer.tokenizer", "path_hierarchy");
return client;
}
- public <K extends ActionResponse> K execute(ActionRequestBuilder action) {
+ public <K extends ActionResponse> K execute(ActionRequestBuilder request) {
StopWatch basicProfile = profiling.start("search", Profiling.Level.BASIC);
StopWatch fullProfile = profiling.start("search", Profiling.Level.FULL);
- ListenableActionFuture acc = action.execute();
+ ListenableActionFuture acc = request.execute();
try {
+ K response = (K) acc.get();
+
if (profiling.isProfilingEnabled(Profiling.Level.BASIC)) {
- basicProfile.stop("ES Request: %s", action.toString().replaceAll("\n", ""));
+ if (ToXContent.class.isAssignableFrom(request.getClass())) {
+ XContentBuilder debugResponse = XContentFactory.jsonBuilder();
+ debugResponse.startObject();
+ ((ToXContent) request).toXContent(debugResponse, ToXContent.EMPTY_PARAMS);
+ debugResponse.endObject();
+ fullProfile.stop("ES Request: %s", debugResponse.string());
+ } else {
+ fullProfile.stop("ES Request: %s", request.toString().replaceAll("\n", ""));
+ }
}
- K response = (K) acc.get();
if (profiling.isProfilingEnabled(Profiling.Level.FULL)) {
if (ToXContent.class.isAssignableFrom(response.getClass())) {
public class RuleIndexMediumTest {
@ClassRule
- public static ServerTester tester = new ServerTester();
+ public static ServerTester tester = new ServerTester()
+ .setProperty("sonar.log.profilingLevel", "FULL");
RuleDao dao = tester.get(RuleDao.class);
RuleIndex index = tester.get(RuleIndex.class);
// 4. get all active rules on profile
result = index.search(new RuleQuery().setActivation(true)
- .setQProfileKey(qualityProfileDto2.getKey()),
+ .setQProfileKey(qualityProfileDto2.getKey()),
new QueryOptions());
assertThat(result.getHits()).hasSize(1);
assertThat(result.getHits().get(0).name()).isEqualTo(rule1.getName());
ActiveRuleDto.createFor(qualityProfileDto2, rule3)
.setSeverity("BLOCKER")
.setInheritance(ActiveRule.Inheritance.INHERITED.name())
- );
+ );
dbSession.commit();
// 3. get Inherited Rules on profile1
result = index.search(new RuleQuery().setActivation(true)
- .setQProfileKey(qualityProfileDto1.getKey())
- .setInheritance(ImmutableSet.of(ActiveRule.Inheritance.INHERITED.name())),
+ .setQProfileKey(qualityProfileDto1.getKey())
+ .setInheritance(ImmutableSet.of(ActiveRule.Inheritance.INHERITED.name())),
new QueryOptions()
- );
+ );
assertThat(result.getHits()).hasSize(0);
// 4. get Inherited Rules on profile2
result = index.search(new RuleQuery().setActivation(true)
- .setQProfileKey(qualityProfileDto2.getKey())
- .setInheritance(ImmutableSet.of(ActiveRule.Inheritance.INHERITED.name())),
+ .setQProfileKey(qualityProfileDto2.getKey())
+ .setInheritance(ImmutableSet.of(ActiveRule.Inheritance.INHERITED.name())),
new QueryOptions()
- );
+ );
assertThat(result.getHits()).hasSize(2);
// 5. get Overridden Rules on profile1
result = index.search(new RuleQuery().setActivation(true)
- .setQProfileKey(qualityProfileDto1.getKey())
- .setInheritance(ImmutableSet.of(ActiveRule.Inheritance.OVERRIDES.name())),
+ .setQProfileKey(qualityProfileDto1.getKey())
+ .setInheritance(ImmutableSet.of(ActiveRule.Inheritance.OVERRIDES.name())),
new QueryOptions()
- );
+ );
assertThat(result.getHits()).hasSize(0);
// 6. get Overridden Rules on profile2
result = index.search(new RuleQuery().setActivation(true)
- .setQProfileKey(qualityProfileDto2.getKey())
- .setInheritance(ImmutableSet.of(ActiveRule.Inheritance.OVERRIDES.name())),
+ .setQProfileKey(qualityProfileDto2.getKey())
+ .setInheritance(ImmutableSet.of(ActiveRule.Inheritance.OVERRIDES.name())),
new QueryOptions()
- );
+ );
assertThat(result.getHits()).hasSize(1);
// 7. get Inherited AND Overridden Rules on profile1
result = index.search(new RuleQuery().setActivation(true)
- .setQProfileKey(qualityProfileDto1.getKey())
- .setInheritance(ImmutableSet.of(
- ActiveRule.Inheritance.INHERITED.name(), ActiveRule.Inheritance.OVERRIDES.name())),
+ .setQProfileKey(qualityProfileDto1.getKey())
+ .setInheritance(ImmutableSet.of(
+ ActiveRule.Inheritance.INHERITED.name(), ActiveRule.Inheritance.OVERRIDES.name())),
new QueryOptions()
- );
+ );
assertThat(result.getHits()).hasSize(0);
// 8. get Inherited AND Overridden Rules on profile2
result = index.search(new RuleQuery().setActivation(true)
- .setQProfileKey(qualityProfileDto2.getKey())
- .setInheritance(ImmutableSet.of(
- ActiveRule.Inheritance.INHERITED.name(), ActiveRule.Inheritance.OVERRIDES.name())),
+ .setQProfileKey(qualityProfileDto2.getKey())
+ .setInheritance(ImmutableSet.of(
+ ActiveRule.Inheritance.INHERITED.name(), ActiveRule.Inheritance.OVERRIDES.name())),
new QueryOptions()
- );
+ );
assertThat(result.getHits()).hasSize(3);
}