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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
// 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.RankProfile;
import com.yahoo.searchdefinition.RankProfileRegistry;
import com.yahoo.searchdefinition.Search;
import com.yahoo.searchdefinition.document.Attribute;
import com.yahoo.vespa.model.container.search.QueryProfiles;
/**
* Validates the match phase settings for all registered rank profiles.
*
* @author geirst
*/
public class MatchPhaseSettingsValidator extends Processor {
public MatchPhaseSettingsValidator(Search search, DeployLogger deployLogger, RankProfileRegistry rankProfileRegistry, QueryProfiles queryProfiles) {
super(search, deployLogger, rankProfileRegistry, queryProfiles);
}
@Override
public void process(boolean validate, boolean documentsOnly) {
if ( ! validate) return;
if (documentsOnly) return;
for (RankProfile rankProfile : rankProfileRegistry.rankProfilesOf(search)) {
RankProfile.MatchPhaseSettings settings = rankProfile.getMatchPhaseSettings();
if (settings != null) {
validateMatchPhaseSettings(rankProfile, settings);
}
}
}
private void validateMatchPhaseSettings(RankProfile rankProfile, RankProfile.MatchPhaseSettings settings) {
String attributeName = settings.getAttribute();
new AttributeValidator(search.getName(),
rankProfile.getName(),
search.getAttribute(attributeName), attributeName).validate();
}
public static class AttributeValidator {
private final String searchName;
private final String rankProfileName;
protected final Attribute attribute;
private final String attributeName;
public AttributeValidator(String searchName, String rankProfileName, Attribute attribute, String attributeName) {
this.searchName = searchName;
this.rankProfileName = rankProfileName;
this.attribute = attribute;
this.attributeName = attributeName;
}
public void validate() {
validateThatAttributeExists();
validateThatAttributeIsSingleNumeric();
validateThatAttributeIsFastSearch();
}
protected void validateThatAttributeExists() {
if (attribute == null) {
failValidation("does not exists");
}
}
protected void validateThatAttributeIsSingleNumeric() {
if (!attribute.getCollectionType().equals(Attribute.CollectionType.SINGLE) ||
attribute.getType().equals(Attribute.Type.STRING) ||
attribute.getType().equals(Attribute.Type.PREDICATE))
{
failValidation("must be single value numeric, but it is '" +
attribute.getDataType().getName() + "'");
}
}
protected void validateThatAttributeIsFastSearch() {
if ( ! attribute.isFastSearch()) {
failValidation("must be fast-search, but it is not");
}
}
protected void failValidation(String what) {
throw new IllegalArgumentException(createMessagePrefix() + what);
}
public String getValidationType() { return "match-phase"; }
private String createMessagePrefix() {
return "In search definition '" + searchName +
"', rank-profile '" + rankProfileName +
"': " + getValidationType() + " attribute '" + attributeName + "' ";
}
}
}
|