diff options
author | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2015-05-05 15:47:24 +0200 |
---|---|---|
committer | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2015-05-06 10:57:07 +0200 |
commit | c33ac9afe453442a2852ca0af1145b9b9b61baa2 (patch) | |
tree | 2666aa4c66837a9f962cac81d9db6571a1c92eb7 | |
parent | aa0cae74eda0e6cf94b9a2386451514623e6723e (diff) | |
download | sonarqube-c33ac9afe453442a2852ca0af1145b9b9b61baa2.tar.gz sonarqube-c33ac9afe453442a2852ca0af1145b9b9b61baa2.zip |
SONAR-6465 Enforce use of SortedMap for ES index settings
-rw-r--r-- | server/sonar-server/src/main/java/org/sonar/server/es/NewIndex.java | 15 | ||||
-rw-r--r-- | server/sonar-server/src/main/java/org/sonar/server/user/index/UserIndexDefinition.java | 4 |
2 files changed, 9 insertions, 10 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/es/NewIndex.java b/server/sonar-server/src/main/java/org/sonar/server/es/NewIndex.java index dd26b7edf84..b5768fdec3d 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/es/NewIndex.java +++ b/server/sonar-server/src/main/java/org/sonar/server/es/NewIndex.java @@ -175,7 +175,7 @@ public class NewIndex { public static class StringFieldBuilder { private final NewIndexType indexType; private final String fieldName; - private boolean sortable = false, wordSearch = false, gramSearch = false, docValues = false, disableSearch = false; + private boolean docValues = false, disableSearch = false, hasAnalyzedField = false; private SortedMap<String, Object> subFields = Maps.newTreeMap(); private StringFieldBuilder(NewIndexType indexType, String fieldName) { @@ -189,10 +189,12 @@ public class NewIndex { } /** - * Add a sub-field + * Add a sub-field. A {@code SortedMap} is required for consistency of the index settings hash. + * @see IndexDefinitionHash */ - public StringFieldBuilder addSubField(String fieldName, Map<String, String> fieldDefinition) { + public StringFieldBuilder addSubField(String fieldName, SortedMap<String, String> fieldDefinition) { subFields.put(fieldName, fieldDefinition); + hasAnalyzedField |= "analyzed".equals(fieldDefinition.get("index")); return this; } @@ -200,7 +202,6 @@ public class NewIndex { * Create an inner-field named "sort" with analyzer "sortable" */ public StringFieldBuilder enableSorting() { - this.sortable = true; addSubField(IndexField.SORT_SUFFIX, ImmutableSortedMap.of( "type", "string", "index", "analyzed", @@ -212,7 +213,6 @@ public class NewIndex { * Create an inner-field named "words" with analyzer "words" */ public StringFieldBuilder enableWordSearch() { - this.wordSearch = true; addSubField(IndexField.SEARCH_WORDS_SUFFIX, ImmutableSortedMap.of( "type", "string", "index", "analyzed", @@ -225,7 +225,6 @@ public class NewIndex { * Create a inner-field named "grams" with analyzer "grams" */ public StringFieldBuilder enableGramSearch() { - this.gramSearch = true; addSubField(IndexField.SEARCH_PARTIAL_SUFFIX, ImmutableSortedMap.of( "type", "string", "index", "analyzed", @@ -268,10 +267,10 @@ public class NewIndex { } private void validate() { - if (docValues && (gramSearch || wordSearch || sortable)) { + if (docValues && hasAnalyzedField) { throw new IllegalStateException("Doc values are not supported on analyzed strings of field: " + fieldName); } - if (disableSearch && (gramSearch || wordSearch || sortable)) { + if (disableSearch && hasAnalyzedField) { throw new IllegalStateException("Can't mix searchable and non-searchable arguments on field: " + fieldName); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/user/index/UserIndexDefinition.java b/server/sonar-server/src/main/java/org/sonar/server/user/index/UserIndexDefinition.java index c5b272329b4..64e13256ef3 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/user/index/UserIndexDefinition.java +++ b/server/sonar-server/src/main/java/org/sonar/server/user/index/UserIndexDefinition.java @@ -25,7 +25,7 @@ import org.sonar.api.config.Settings; import org.sonar.server.es.IndexDefinition; import org.sonar.server.es.NewIndex; -import java.util.Map; +import java.util.SortedMap; /** * Definition of ES index "users", including settings and fields. @@ -88,7 +88,7 @@ public class UserIndexDefinition implements IndexDefinition { mapping.stringFieldBuilder(FIELD_SCM_ACCOUNTS).build(); } - private Map<String, String> buildGramSearchField() { + private SortedMap<String, String> buildGramSearchField() { return ImmutableSortedMap.of( "type", "string", "index", "analyzed", |