blob: c5a74ece866dce383d9dbcc8daa4db2724874aa0 (
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.schema;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.yahoo.container.QrSearchersConfig;
import com.yahoo.prelude.fastsearch.DocsumDefinition;
import com.yahoo.prelude.fastsearch.DocsumField;
import com.yahoo.prelude.fastsearch.DocumentdbInfoConfig;
import com.yahoo.search.config.SchemaInfoConfig;
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(SchemaInfoConfig schemaInfoConfig) {
return schemaInfoConfig.schema().stream().map(config -> toSchema(config)).collect(Collectors.toList());
}
static Schema toSchema(SchemaInfoConfig.Schema schemaInfoConfig) {
Schema.Builder builder = new Schema.Builder(schemaInfoConfig.name());
for (var profileConfig : schemaInfoConfig.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());
}
for (var summaryConfig : schemaInfoConfig.summaryclass()) {
DocumentSummary.Builder summaryBuilder = new DocumentSummary.Builder(summaryConfig.name());
for (var field : summaryConfig.fields()) {
if (field.dynamic())
summaryBuilder.setDynamic(true);
summaryBuilder.add(new DocumentSummary.Field(field.name(), field.type()));
}
builder.add(summaryBuilder.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;
}
}
|