3 * Copyright (C) 2009-2019 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.server.measure.index;
22 import org.sonar.api.config.Configuration;
23 import org.sonar.server.es.IndexDefinition;
24 import org.sonar.server.es.IndexType;
25 import org.sonar.server.es.NewIndex;
27 import static org.sonar.server.es.DefaultIndexSettingsElement.SEARCH_GRAMS_ANALYZER;
28 import static org.sonar.server.es.DefaultIndexSettingsElement.SORTABLE_ANALYZER;
29 import static org.sonar.server.es.NewIndex.SettingsConfiguration.MANUAL_REFRESH_INTERVAL;
30 import static org.sonar.server.es.NewIndex.SettingsConfiguration.newBuilder;
32 public class ProjectMeasuresIndexDefinition implements IndexDefinition {
34 public static final IndexType INDEX_TYPE_PROJECT_MEASURES = new IndexType("projectmeasures", "projectmeasure");
35 public static final String FIELD_UUID = "uuid";
36 public static final String FIELD_ORGANIZATION_UUID = "organizationUuid";
39 * Project key. Only projects (qualifier=TRK)
41 public static final String FIELD_KEY = "key";
42 public static final String FIELD_NAME = "name";
43 public static final String FIELD_ANALYSED_AT = "analysedAt";
44 public static final String FIELD_QUALITY_GATE_STATUS = "qualityGateStatus";
45 public static final String FIELD_TAGS = "tags";
46 public static final String FIELD_MEASURES = "measures";
47 public static final String FIELD_MEASURES_KEY = "key";
48 public static final String FIELD_MEASURES_VALUE = "value";
49 public static final String FIELD_LANGUAGES = "languages";
50 public static final String FIELD_NCLOC_LANGUAGE_DISTRIBUTION = "nclocLanguageDistribution";
51 public static final String FIELD_DISTRIB_LANGUAGE = "language";
52 public static final String FIELD_DISTRIB_NCLOC = "ncloc";
54 private final Configuration config;
56 public ProjectMeasuresIndexDefinition(Configuration settings) {
57 this.config = settings;
61 public void define(IndexDefinitionContext context) {
62 NewIndex index = context.create(
63 INDEX_TYPE_PROJECT_MEASURES.getIndex(),
65 .setRefreshInterval(MANUAL_REFRESH_INTERVAL)
66 .setDefaultNbOfShards(5)
69 NewIndex.NewIndexType mapping = index.createType(INDEX_TYPE_PROJECT_MEASURES.getType())
70 .requireProjectAuthorization();
72 mapping.keywordFieldBuilder(FIELD_UUID).disableNorms().build();
73 mapping.keywordFieldBuilder(FIELD_ORGANIZATION_UUID).disableNorms().build();
74 mapping.keywordFieldBuilder(FIELD_KEY).disableNorms().addSubFields(SORTABLE_ANALYZER).build();
75 mapping.keywordFieldBuilder(FIELD_NAME).addSubFields(SORTABLE_ANALYZER, SEARCH_GRAMS_ANALYZER).build();
76 mapping.keywordFieldBuilder(FIELD_QUALITY_GATE_STATUS).build();
77 mapping.keywordFieldBuilder(FIELD_TAGS).build();
78 mapping.keywordFieldBuilder(FIELD_LANGUAGES).build();
79 mapping.nestedFieldBuilder(FIELD_MEASURES)
80 .addKeywordField(FIELD_MEASURES_KEY)
81 .addDoubleField(FIELD_MEASURES_VALUE)
83 mapping.nestedFieldBuilder(FIELD_NCLOC_LANGUAGE_DISTRIBUTION)
84 .addKeywordField(FIELD_DISTRIB_LANGUAGE)
85 .addIntegerField(FIELD_DISTRIB_NCLOC)
87 mapping.createDateTimeField(FIELD_ANALYSED_AT);
88 mapping.setEnableSource(false);