blob: 0daf7265daa1d5b6705198e6e59a40417ffd2ddc (
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
|
// Copyright 2017 Yahoo Holdings. 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.Attribute;
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.ArrayList;
import java.util.List;
import java.util.Map;
/**
* Takes the aliases set on field by parser and sets them on correct Index or Attribute
*
* @author vegardh
*/
public class MakeAliases extends Processor {
public MakeAliases(Search search, DeployLogger deployLogger, RankProfileRegistry rankProfileRegistry, QueryProfiles queryProfiles) {
super(search, deployLogger, rankProfileRegistry, queryProfiles);
}
@Override
public void process(boolean validate, boolean documentsOnly) {
List<String> usedAliases = new ArrayList<>();
for (SDField field : search.allConcreteFields()) {
for (Map.Entry<String, String> e : field.getAliasToName().entrySet()) {
String alias = e.getKey();
String name = e.getValue();
String errMsg = "For search '" + search.getName() + "': alias '" + alias + "' ";
if (validate && search.existsIndex(alias)) {
throw new IllegalArgumentException(errMsg + "is illegal since it is the name of an index.");
}
if (validate && search.getAttribute(alias) != null) {
throw new IllegalArgumentException(errMsg + "is illegal since it is the name of an attribute.");
}
if (validate && usedAliases.contains(alias)) {
throw new IllegalArgumentException(errMsg + "specified more than once.");
}
usedAliases.add(alias);
Index index = field.getIndex(name);
Attribute attribute = field.getAttributes().get(name);
if (index != null) {
index.addAlias(alias); // alias will be for index in this case, since it is the one used in a search
} else if (attribute != null && ! field.doesIndexing()) {
attribute.getAliases().add(alias);
} else {
index = new Index(name);
index.addAlias(alias);
field.addIndex(index);
}
}
}
}
}
|