diff options
author | Stephane Gamard <stephane.gamard@searchbox.com> | 2014-06-10 10:10:39 +0200 |
---|---|---|
committer | Stephane Gamard <stephane.gamard@searchbox.com> | 2014-06-10 10:18:12 +0200 |
commit | 3b6e2a01930dbf382967e87505c87f090ed23e87 (patch) | |
tree | b898b3568a169c03c8901933524ab03f6b803bf5 | |
parent | 61ba765f16992f3bb5e853f3330f67b88d809e8f (diff) | |
download | sonarqube-3b6e2a01930dbf382967e87505c87f090ed23e87.tar.gz sonarqube-3b6e2a01930dbf382967e87505c87f090ed23e87.zip |
fix quality flaw (flow & dead code)
-rw-r--r-- | sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndex.java | 96 |
1 files changed, 33 insertions, 63 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndex.java b/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndex.java index 7e7cde2347a..2b861ca1075 100644 --- a/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndex.java +++ b/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndex.java @@ -172,70 +172,40 @@ public class RuleIndex extends BaseIndex<Rule, RuleDto, RuleKey> { /* Build main query (search based) */ protected QueryBuilder getQuery(RuleQuery query, QueryOptions options) { - if (query.getQueryText() != null && !query.getQueryText().isEmpty()) { - - BoolQueryBuilder qb = QueryBuilders.boolQuery(); - String queryString = query.getQueryText(); - - //Human readable type of querying - qb.should(QueryBuilders.queryString(query.getQueryText()) - .field(RuleNormalizer.RuleField.NAME.field() + "." + IndexField.SEARCH_WORDS_SUFFIX, 20f) - .field(RuleNormalizer.RuleField.HTML_DESCRIPTION.field() + "." + IndexField.SEARCH_WORDS_SUFFIX, 3f) - .enablePositionIncrements(true) - .defaultOperator(QueryStringQueryBuilder.Operator.AND) - .fuzziness(Fuzziness.ONE) - .autoGeneratePhraseQueries(true) - .lenient(false) - .useDisMax(true) - .boost(20f)); - - // Match and partial Match queries - qb.should(this.termQuery(RuleNormalizer.RuleField.KEY, queryString, 15f)); - qb.should(this.termQuery(RuleNormalizer.RuleField._KEY, queryString, 35f)); - qb.should(this.termQuery(RuleNormalizer.RuleField.LANGUAGE, queryString, 3f)); - qb.should(this.termQuery(RuleNormalizer.RuleField.CHARACTERISTIC, queryString, 5f)); - qb.should(this.termQuery(RuleNormalizer.RuleField.SUB_CHARACTERISTIC, queryString, 5f)); - qb.should(this.termQuery(RuleNormalizer.RuleField._TAGS, queryString, 10f)); - qb.should(this.termAnyQuery(RuleNormalizer.RuleField.CHARACTERISTIC, queryString, 1f)); - qb.should(this.termAnyQuery(RuleNormalizer.RuleField.SUB_CHARACTERISTIC, queryString, 1f)); - qb.should(this.termAnyQuery(RuleNormalizer.RuleField._TAGS, queryString, 1f)); - - return qb; - -// PURE EDISMAX Query style -// return QueryBuilders.queryString(query.getQueryText()) -// // Human readable type of querying -// .field(RuleNormalizer.RuleField.NAME.field() + "." + IndexField.SEARCH_WORDS_SUFFIX, 20f) -// .field(RuleNormalizer.RuleField.HTML_DESCRIPTION.field() + "." + IndexField.SEARCH_WORDS_SUFFIX, 3f) -// -// // Match and partial Match queries -// .field(RuleNormalizer.RuleField.KEY.field() + "." + IndexField.SEARCH_WORDS_SUFFIX, 15f) -// .field(RuleNormalizer.RuleField._KEY.field() + "." + IndexField.SEARCH_WORDS_SUFFIX, 15f) -// .field(RuleNormalizer.RuleField.LANGUAGE.field() + "." + IndexField.SEARCH_WORDS_SUFFIX, 5f) -// .field(RuleNormalizer.RuleField.CHARACTERISTIC.field() + "." + IndexField.SEARCH_WORDS_SUFFIX, 5f) -// .field(RuleNormalizer.RuleField.SUB_CHARACTERISTIC.field() + "." + IndexField.SEARCH_WORDS_SUFFIX, 5f) -// .field(RuleNormalizer.RuleField._TAGS.field() + "." + IndexField.SEARCH_WORDS_SUFFIX, 10f); - -// PURE FIELD_MATCHING Q -// //Human readable type of querying -// qb.should(this.phraseQuery(RuleNormalizer.RuleField.NAME, queryString, 20f)); -// qb.should(this.phraseQuery(RuleNormalizer.RuleField.HTML_DESCRIPTION, queryString, 3f)); -// -// // Match and partial Match queries -// qb.should(this.termQuery(RuleNormalizer.RuleField.KEY, queryString, 15f)); -// qb.should(this.termQuery(RuleNormalizer.RuleField._KEY, queryString, 35f)); -// qb.should(this.termQuery(RuleNormalizer.RuleField.LANGUAGE, queryString, 3f)); -// qb.should(this.termQuery(RuleNormalizer.RuleField.CHARACTERISTIC, queryString, 5f)); -// qb.should(this.termQuery(RuleNormalizer.RuleField.SUB_CHARACTERISTIC, queryString, 5f)); -// qb.should(this.termQuery(RuleNormalizer.RuleField._TAGS, queryString, 10f)); -// qb.should(this.termAnyQuery(RuleNormalizer.RuleField.CHARACTERISTIC, queryString, 1f)); -// qb.should(this.termAnyQuery(RuleNormalizer.RuleField.SUB_CHARACTERISTIC, queryString, 1f)); -// qb.should(this.termAnyQuery(RuleNormalizer.RuleField._TAGS, queryString, 1f)); -// -// return qb; + // No contextual query case + if (query.getQueryText() == null || query.getQueryText().isEmpty()) { + return QueryBuilders.matchAllQuery(); } - return QueryBuilders.matchAllQuery(); + + // Build RuleBased contextual query + BoolQueryBuilder qb = QueryBuilders.boolQuery(); + String queryString = query.getQueryText(); + + //Human readable type of querying + qb.should(QueryBuilders.queryString(query.getQueryText()) + .field(RuleNormalizer.RuleField.NAME.field() + "." + IndexField.SEARCH_WORDS_SUFFIX, 20f) + .field(RuleNormalizer.RuleField.HTML_DESCRIPTION.field() + "." + IndexField.SEARCH_WORDS_SUFFIX, 3f) + .enablePositionIncrements(true) + .defaultOperator(QueryStringQueryBuilder.Operator.AND) + .fuzziness(Fuzziness.ONE) + .autoGeneratePhraseQueries(true) + .lenient(false) + .useDisMax(true) + .boost(20f)); + + // Match and partial Match queries + qb.should(this.termQuery(RuleNormalizer.RuleField.KEY, queryString, 15f)); + qb.should(this.termQuery(RuleNormalizer.RuleField._KEY, queryString, 35f)); + qb.should(this.termQuery(RuleNormalizer.RuleField.LANGUAGE, queryString, 3f)); + qb.should(this.termQuery(RuleNormalizer.RuleField.CHARACTERISTIC, queryString, 5f)); + qb.should(this.termQuery(RuleNormalizer.RuleField.SUB_CHARACTERISTIC, queryString, 5f)); + qb.should(this.termQuery(RuleNormalizer.RuleField._TAGS, queryString, 10f)); + qb.should(this.termAnyQuery(RuleNormalizer.RuleField.CHARACTERISTIC, queryString, 1f)); + qb.should(this.termAnyQuery(RuleNormalizer.RuleField.SUB_CHARACTERISTIC, queryString, 1f)); + qb.should(this.termAnyQuery(RuleNormalizer.RuleField._TAGS, queryString, 1f)); + + return qb; } /* Build main filter (match based) */ @@ -259,7 +229,7 @@ public class RuleIndex extends BaseIndex<Rule, RuleDto, RuleKey> { //Debt char exist filter - if(query.getHasDebtCharacteristic() != null && query.getHasDebtCharacteristic()) { + if (query.getHasDebtCharacteristic() != null && query.getHasDebtCharacteristic()) { fb.must(FilterBuilders.existsFilter(RuleNormalizer.RuleField.SUB_CHARACTERISTIC.field())); } |