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
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.searchdefinition.derived;
import com.yahoo.searchdefinition.RankProfileRegistry;
import com.yahoo.vespa.config.search.RankProfilesConfig;
import com.yahoo.searchdefinition.RankProfile;
import com.yahoo.searchdefinition.Search;
import java.util.Map;
/**
* The derived rank profiles of a search definition
*
* @author bratseth
*/
public class RankProfileList extends Derived implements RankProfilesConfig.Producer {
private Map<String, RawRankProfile> rankProfiles = new java.util.LinkedHashMap<>();
/**
* Creates a rank profile
*
* @param search the search definition this is a rank profile from
* @param attributeFields the attribute fields to create a ranking for
*/
public RankProfileList(Search search, AttributeFields attributeFields, RankProfileRegistry rankProfileRegistry) {
setName(search.getName());
deriveRankProfiles(rankProfileRegistry, search, attributeFields);
}
private void deriveRankProfiles(RankProfileRegistry rankProfileRegistry, Search search, AttributeFields attributeFields) {
RawRankProfile defaultProfile = new RawRankProfile(rankProfileRegistry.getRankProfile(search, "default"), attributeFields);
rankProfiles.put(defaultProfile.getName(), defaultProfile);
for (RankProfile rank : rankProfileRegistry.localRankProfiles(search)) {
if ("default".equals(rank.getName())) continue;
RawRankProfile rawRank = new RawRankProfile(rank, attributeFields);
rankProfiles.put(rawRank.getName(), rawRank);
}
}
public Map<String, RawRankProfile> getRankProfiles() {
return rankProfiles;
}
/** Returns the raw rank profile with the given name, or null if it is not present */
public RawRankProfile getRankProfile(String name) {
return rankProfiles.get(name);
}
@Override
public String getDerivedName() { return "rank-profiles"; }
@Override
public void getConfig(RankProfilesConfig.Builder builder) {
for (RawRankProfile rank : rankProfiles.values() ) {
rank.getConfig(builder);
}
}
}
|