aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/searchdefinition/processing/IndexSettingsNonFieldNames.java
blob: 7701282337287bd120e89af2fbc543bdcff85da3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.searchdefinition.processing;

import com.yahoo.config.application.api.DeployLogger;
import com.yahoo.searchdefinition.RankProfileRegistry;
import com.yahoo.searchdefinition.document.SDField;
import com.yahoo.searchdefinition.Index;
import com.yahoo.searchdefinition.Search;
import com.yahoo.vespa.model.container.search.QueryProfiles;

import java.util.Iterator;

/**
 * Fail if:
 * 1) There are index: settings without explicit index names (name same as field name)
 * 2) All the index-to indexes differ from the field name.
 * @author vegardh
 *
 */
public class IndexSettingsNonFieldNames extends Processor {

    public IndexSettingsNonFieldNames(Search search, DeployLogger deployLogger, RankProfileRegistry rankProfileRegistry, QueryProfiles queryProfiles) {
        super(search, deployLogger, rankProfileRegistry, queryProfiles);
    }

    @Override
    public void process() {
        for (SDField field : search.allConcreteFields()) {
            boolean fieldNameUsed = false;
            for (Iterator i = field.getFieldNameAsIterator(); i.hasNext();) {
                String iName = (String)(i.next());
                if (iName.equals(field.getName())) {
                    fieldNameUsed = true;
                }
            }
            if (!fieldNameUsed) {
                for (Index index : field.getIndices().values()) {
                    if (index.getName().equals(field.getName())) {
                        throw new IllegalArgumentException("Error in " + field + " in " + search +
                        ": When all index names differ from field name, index parameter settings must specify index name explicitly.");
                    }
                }
            }
        }
    }

}