3 * Copyright (C) 2009-2017 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.Settings;
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;
30 public class ProjectMeasuresIndexDefinition implements IndexDefinition {
32 public static final IndexType INDEX_TYPE_PROJECT_MEASURES = new IndexType("projectmeasures", "projectmeasure");
33 public static final String FIELD_ORGANIZATION_UUID = "organizationUuid";
34 public static final String FIELD_KEY = "key";
35 public static final String FIELD_NAME = "name";
36 public static final String FIELD_ANALYSED_AT = "analysedAt";
37 public static final String FIELD_QUALITY_GATE_STATUS = "qualityGateStatus";
38 public static final String FIELD_TAGS = "tags";
39 public static final String FIELD_MEASURES = "measures";
40 public static final String FIELD_MEASURES_KEY = "key";
41 public static final String FIELD_MEASURES_VALUE = "value";
42 public static final String FIELD_LANGUAGES = "languages";
44 private final Settings settings;
46 public ProjectMeasuresIndexDefinition(Settings settings) {
47 this.settings = settings;
51 public void define(IndexDefinitionContext context) {
52 NewIndex index = context.create(INDEX_TYPE_PROJECT_MEASURES.getIndex());
53 index.refreshHandledByIndexer();
54 index.configureShards(settings, 5);
56 NewIndex.NewIndexType mapping = index.createType(INDEX_TYPE_PROJECT_MEASURES.getType())
57 .requireProjectAuthorization();
59 mapping.stringFieldBuilder(FIELD_ORGANIZATION_UUID).build();
60 mapping.stringFieldBuilder(FIELD_KEY).disableNorms().addSubFields(SORTABLE_ANALYZER).build();
61 mapping.stringFieldBuilder(FIELD_NAME).addSubFields(SORTABLE_ANALYZER, SEARCH_GRAMS_ANALYZER).build();
62 mapping.stringFieldBuilder(FIELD_QUALITY_GATE_STATUS).build();
63 mapping.stringFieldBuilder(FIELD_TAGS).build();
64 mapping.stringFieldBuilder(FIELD_LANGUAGES).build();
65 mapping.nestedFieldBuilder(FIELD_MEASURES)
66 .addStringField(FIELD_MEASURES_KEY)
67 .addDoubleField(FIELD_MEASURES_VALUE)
69 mapping.createDateTimeField(FIELD_ANALYSED_AT);
70 mapping.setEnableSource(false);