summaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/search/config/SchemaInfoConfigurer.java
blob: ae06babda6630c92fc8186adf59d5ff7056f99ce (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
48
49
50
51
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.config;

import com.yahoo.container.QrSearchersConfig;
import com.yahoo.prelude.fastsearch.DocumentdbInfoConfig;
import com.yahoo.tensor.TensorType;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * Translation between schema info configuration and schema objects.
 *
 * @author bratseth
 */
class SchemaInfoConfigurer {

    static List<Schema> toSchemas(DocumentdbInfoConfig documentdbInfoConfig) {
        return documentdbInfoConfig.documentdb().stream().map(config -> toSchema(config)).collect(Collectors.toList());
    }

    static Schema toSchema(DocumentdbInfoConfig.Documentdb documentDbConfig) {
        Schema.Builder builder = new Schema.Builder(documentDbConfig.name());
        for (var profileConfig : documentDbConfig.rankprofile()) {
            RankProfile.Builder profileBuilder = new RankProfile.Builder(profileConfig.name());
            profileBuilder.setHasSummaryFeatures(profileConfig.hasSummaryFeatures());
            profileBuilder.setHasRankFeatures(profileConfig.hasRankFeatures());
            for (var inputConfig : profileConfig.input())
                profileBuilder.addInput(inputConfig.name(), TensorType.fromSpec(inputConfig.type()));
            builder.add(profileBuilder.build());
        }
        return builder.build();
    }

    static Map<String, List<String>> toClusters(QrSearchersConfig config) {
        Map<String, List<String>> clusters = new HashMap<>();
        for (int i = 0; i < config.searchcluster().size(); ++i) {
            List<String> schemas = new ArrayList<>();
            String clusterName = config.searchcluster(i).name();
            for (int j = 0; j < config.searchcluster(i).searchdef().size(); ++j)
                schemas.add(config.searchcluster(i).searchdef(j));
            clusters.put(clusterName, schemas);
        }
        return clusters;
    }

}