]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8798 prepare changing literal values for es property "index"
authorDaniel Schwarz <daniel.schwarz@sonarsource.com>
Wed, 28 Jun 2017 08:44:39 +0000 (10:44 +0200)
committerDaniel Schwarz <bartfastiel@users.noreply.github.com>
Wed, 9 Aug 2017 13:09:54 +0000 (15:09 +0200)
server/sonar-server/src/main/java/org/sonar/server/es/DefaultIndexSettings.java
server/sonar-server/src/main/java/org/sonar/server/es/DefaultIndexSettingsElement.java
server/sonar-server/src/main/java/org/sonar/server/es/NewIndex.java
server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndexDefinition.java
server/sonar-server/src/main/java/org/sonar/server/test/index/TestIndexDefinition.java
server/sonar-server/src/test/java/org/sonar/server/es/NewIndexTest.java

index 1743c3e5f41af3076dd7411bad881325153638c7..75aa7cabcfefb46fe3755f8a29e5e46602a8dca1 100644 (file)
@@ -43,7 +43,9 @@ public class DefaultIndexSettings {
 
   public static final String TYPE = "type";
   public static final String INDEX = "index";
-  public static final String ANALYZED = "analyzed";
+  public static final String INDEX_SEARCHABLE_FOR_TEXT = "analyzed"; // ES 5: remove this constant and replace usages with INDEX_SEARCHABLE
+  public static final String INDEX_SEARCHABLE_FOR_KEYWORD = "not_analyzed"; // ES 5: change to true and rename to INDEX_SEARCHABLE
+  public static final String INDEX_NOT_SEARCHABLE = "no"; // ES 5: change to false
   public static final String FIELD_TYPE_TEXT = "string";  // ES 5: change to text
   public static final String FIELD_TYPE_KEYWORD = "string";  // ES 5: change to keyword
   public static final String STANDARD = "standard";
index 2e20bd0364e71956e96ec1b1fa7933a07f532ede..f4de5e0e5e7b39fba1c472b5b9914cba84f32b71 100644 (file)
@@ -27,13 +27,13 @@ import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.common.settings.Settings.Builder;
 
 import static org.sonar.server.es.DefaultIndexSettings.ANALYSIS;
-import static org.sonar.server.es.DefaultIndexSettings.ANALYZED;
 import static org.sonar.server.es.DefaultIndexSettings.ANALYZER;
 import static org.sonar.server.es.DefaultIndexSettings.ASCIIFOLDING;
 import static org.sonar.server.es.DefaultIndexSettings.DELIMITER;
 import static org.sonar.server.es.DefaultIndexSettings.FIELD_TYPE_TEXT;
 import static org.sonar.server.es.DefaultIndexSettings.FILTER;
 import static org.sonar.server.es.DefaultIndexSettings.INDEX;
+import static org.sonar.server.es.DefaultIndexSettings.INDEX_SEARCHABLE_FOR_TEXT;
 import static org.sonar.server.es.DefaultIndexSettings.KEYWORD;
 import static org.sonar.server.es.DefaultIndexSettings.LOWERCASE;
 import static org.sonar.server.es.DefaultIndexSettings.MAXIMUM_NGRAM_LENGTH;
@@ -125,7 +125,7 @@ public enum DefaultIndexSettingsElement {
     public SortedMap<String, String> fieldMapping() {
       return ImmutableSortedMap.of(
         TYPE, FIELD_TYPE_TEXT,
-        INDEX, ANALYZED,
+        INDEX, INDEX_SEARCHABLE_FOR_TEXT,
         ANALYZER, getName());
     }
   },
@@ -149,7 +149,7 @@ public enum DefaultIndexSettingsElement {
     public SortedMap<String, String> fieldMapping() {
       return ImmutableSortedMap.of(
         TYPE, FIELD_TYPE_TEXT,
-        INDEX, ANALYZED,
+        INDEX, INDEX_SEARCHABLE_FOR_TEXT,
         ANALYZER, INDEX_GRAMS_ANALYZER.getName(),
         SEARCH_ANALYZER, getName());
     }
@@ -174,7 +174,7 @@ public enum DefaultIndexSettingsElement {
     public SortedMap<String, String> fieldMapping() {
       return ImmutableSortedMap.of(
         TYPE, FIELD_TYPE_TEXT,
-        INDEX, ANALYZED,
+        INDEX, INDEX_SEARCHABLE_FOR_TEXT,
         ANALYZER, INDEX_PREFIX_ANALYZER.getName(),
         SEARCH_ANALYZER, getName());
     }
@@ -199,7 +199,7 @@ public enum DefaultIndexSettingsElement {
     public SortedMap<String, String> fieldMapping() {
       return ImmutableSortedMap.of(
         TYPE, FIELD_TYPE_TEXT,
-        INDEX, ANALYZED,
+        INDEX, INDEX_SEARCHABLE_FOR_TEXT,
         ANALYZER, INDEX_PREFIX_CASE_INSENSITIVE_ANALYZER.getName(),
         SEARCH_ANALYZER, getName());
     }
@@ -224,7 +224,7 @@ public enum DefaultIndexSettingsElement {
     public SortedMap<String, String> fieldMapping() {
       return ImmutableSortedMap.of(
         TYPE, FIELD_TYPE_TEXT,
-        INDEX, ANALYZED,
+        INDEX, INDEX_SEARCHABLE_FOR_TEXT,
         ANALYZER, USER_INDEX_GRAMS_ANALYZER.getName(),
         SEARCH_ANALYZER, getName());
     }
@@ -249,7 +249,7 @@ public enum DefaultIndexSettingsElement {
     public SortedMap<String, String> fieldMapping() {
       return ImmutableSortedMap.of(
         TYPE, FIELD_TYPE_TEXT,
-        INDEX, ANALYZED,
+        INDEX, INDEX_SEARCHABLE_FOR_TEXT,
         ANALYZER, INDEX_WORDS_ANALYZER.getName(),
         SEARCH_ANALYZER, getName());
     }
index 5941710a5ed881cec5ace9a47ea5b75044a9816c..9120258cab573a3d36da162a197726026454ddb3 100644 (file)
@@ -38,11 +38,13 @@ import org.sonar.server.permission.index.AuthorizationTypeSupport;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static java.lang.String.format;
-import static org.sonar.server.es.DefaultIndexSettings.ANALYZED;
 import static org.sonar.server.es.DefaultIndexSettings.ANALYZER;
 import static org.sonar.server.es.DefaultIndexSettings.FIELD_TYPE_KEYWORD;
 import static org.sonar.server.es.DefaultIndexSettings.FIELD_TYPE_TEXT;
 import static org.sonar.server.es.DefaultIndexSettings.INDEX;
+import static org.sonar.server.es.DefaultIndexSettings.INDEX_NOT_SEARCHABLE;
+import static org.sonar.server.es.DefaultIndexSettings.INDEX_SEARCHABLE_FOR_KEYWORD;
+import static org.sonar.server.es.DefaultIndexSettings.INDEX_SEARCHABLE_FOR_TEXT;
 import static org.sonar.server.es.DefaultIndexSettings.TYPE;
 import static org.sonar.server.es.DefaultIndexSettingsElement.UUID_MODULE_ANALYZER;
 
@@ -178,7 +180,7 @@ public class NewIndex {
     public NewIndexType createUuidPathField(String fieldName) {
       return setProperty(fieldName, ImmutableSortedMap.of(
         TYPE, FIELD_TYPE_TEXT,
-        INDEX, ANALYZED,
+        INDEX, INDEX_SEARCHABLE_FOR_TEXT,
         ANALYZER, UUID_MODULE_ANALYZER.getName()));
     }
 
@@ -250,6 +252,12 @@ public class NewIndex {
      * By default field is "not_analyzed": it is searchable, but index the value exactly
      * as specified.
      */
+    // ES 5: update javadoc to:
+    /*
+     * "index: false" -> Make this field not searchable.
+     * By default field is "true": it is searchable, but index the value exactly
+     * as specified.
+     */
     public KeywordFieldBuilder disableSearch() {
       this.disableSearch = true;
       return this;
@@ -260,7 +268,7 @@ public class NewIndex {
       if (subFields.isEmpty()) {
         hash.putAll(ImmutableMap.of(
             "type", FIELD_TYPE_KEYWORD,
-            "index", disableSearch ? "no" : "not_analyzed", // ES 5: change to false and true
+            "index", disableSearch ? INDEX_NOT_SEARCHABLE : INDEX_SEARCHABLE_FOR_KEYWORD,
             "norms", ImmutableMap.of("enabled", String.valueOf(!disableNorms))));
       } else {
         hash.put("type", "multi_field");
@@ -281,7 +289,7 @@ public class NewIndex {
 
         multiFields.put(fieldName, ImmutableMap.of(
             "type", FIELD_TYPE_KEYWORD,
-            "index", "not_analyzed", // ES 5: change to true
+            "index", INDEX_SEARCHABLE_FOR_KEYWORD,
             "term_vector", termVectorWithPositionOffsets ? "with_positions_offsets" : "no",
             "norms", ImmutableMap.of("enabled", "false")));
 
@@ -317,7 +325,7 @@ public class NewIndex {
     public NestedFieldBuilder addKeywordField(String fieldName) {
       return setProperty(fieldName, ImmutableMap.of(
         "type", FIELD_TYPE_KEYWORD,
-        "index", "not_analyzed"));
+        "index", INDEX_SEARCHABLE_FOR_KEYWORD));
     }
 
     public NestedFieldBuilder addDoubleField(String fieldName) {
index eff0896ad567b508832bcbe8a5c12667d2457bbe..4051e8a9ea0907845bcc2b5c5291682e51c9ab0a 100644 (file)
@@ -141,7 +141,7 @@ public class RuleIndexDefinition implements IndexDefinition {
     ruleMapping.keywordFieldBuilder(FIELD_RULE_NAME).addSubFields(SORTABLE_ANALYZER, SEARCH_WORDS_ANALYZER).build();
     ruleMapping.setProperty(FIELD_RULE_HTML_DESCRIPTION, ImmutableSortedMap.of(
       DefaultIndexSettings.TYPE, DefaultIndexSettings.FIELD_TYPE_TEXT,
-      DefaultIndexSettings.INDEX, DefaultIndexSettings.ANALYZED,
+      DefaultIndexSettings.INDEX, DefaultIndexSettings.INDEX_SEARCHABLE_FOR_TEXT,
       DefaultIndexSettings.ANALYZER, ENGLISH_HTML_ANALYZER.getName(),
       DefaultIndexSettings.SEARCH_ANALYZER, ENGLISH_HTML_ANALYZER.getName()));
     ruleMapping.keywordFieldBuilder(FIELD_RULE_SEVERITY).disableNorms().build();
index ea415ff30263b97a5cc497093658a0eb32f08797..65cc11d580385196429d14474247f9d131728cff 100644 (file)
@@ -26,6 +26,7 @@ import org.sonar.server.es.IndexType;
 import org.sonar.server.es.NewIndex;
 
 import static org.sonar.server.es.DefaultIndexSettings.FIELD_TYPE_KEYWORD;
+import static org.sonar.server.es.DefaultIndexSettings.INDEX_SEARCHABLE_FOR_KEYWORD;
 
 public class TestIndexDefinition implements IndexDefinition {
 
@@ -67,7 +68,7 @@ public class TestIndexDefinition implements IndexDefinition {
     mapping.keywordFieldBuilder(FIELD_MESSAGE).disableNorms().disableSearch().build();
     mapping.keywordFieldBuilder(FIELD_STACKTRACE).disableNorms().disableSearch().build();
     mapping.setProperty(FIELD_COVERED_FILES, ImmutableMap.of("type", "nested", "properties", ImmutableMap.of(
-      FIELD_COVERED_FILE_UUID, ImmutableMap.of("type", FIELD_TYPE_KEYWORD, "index", "not_analyzed"),
+      FIELD_COVERED_FILE_UUID, ImmutableMap.of("type", FIELD_TYPE_KEYWORD, "index", INDEX_SEARCHABLE_FOR_KEYWORD),
       FIELD_COVERED_FILE_LINES, ImmutableMap.of("type", "integer"))));
     mapping.createDateTimeField(FIELD_UPDATED_AT);
   }
index ceabf6cb2bc92c9f6de8af02b39f956bae7ae317..89482d7871d29016032a2748fab6311b818ae006 100644 (file)
@@ -103,12 +103,12 @@ public class NewIndexTest {
 
     Map<String, Object> props = (Map) mapping.getProperty("basic_field");
     assertThat(props.get("type")).isEqualTo("string");// ES 5: change to keyword
-    assertThat(props.get("index")).isEqualTo("not_analyzed");
+    assertThat(props.get("index")).isEqualTo("not_analyzed");// ES 5: change to true
     assertThat(props.get("fields")).isNull();
 
     props = (Map) mapping.getProperty("not_searchable_field");
     assertThat(props.get("type")).isEqualTo("string");// ES 5: change to keyword
-    assertThat(props.get("index")).isEqualTo("no");
+    assertThat(props.get("index")).isEqualTo("no");// ES 5: change to false
     assertThat(props.get("fields")).isNull();
 
     props = (Map) mapping.getProperty("all_capabilities_field");