blob: e7d0d5c3dbb8f682ba997f7e4aa901a020bb3334 (
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
69
70
|
// 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.Search;
import com.yahoo.vespa.model.container.search.QueryProfiles;
/**
* Checks that attribute properties only are set for attributes that have data (are created by an indexing statement).
*
* @author hmusum
*/
public class AttributeProperties extends Processor {
public AttributeProperties(Search search, DeployLogger deployLogger, RankProfileRegistry rankProfileRegistry, QueryProfiles queryProfiles) {
super(search, deployLogger, rankProfileRegistry, queryProfiles);
}
@Override
public void process() {
for (SDField field : search.allConcreteFields()) {
String fieldName = field.getName();
// For each attribute, check if the attribute has been created
// by an indexing statement.
for (Attribute attribute : field.getAttributes().values()) {
if (attributeCreated(field, attribute.getName())) {
continue;
}
// Check other fields or statements that may have created this attribute.
boolean created = false;
for (SDField f : search.allConcreteFields()) {
// Checking against the field we are looking at
if (!f.getName().equals(fieldName)) {
if (attributeCreated(f, attribute.getName())) {
created = true;
break;
}
}
}
if (!created) {
throw new IllegalArgumentException("Attribute '" + attribute.getName() + "' in field '" +
field.getName() + "' is not created by the indexing statement");
}
}
}
}
/**
* Checks if the attribute has been created bye an indexing statement in this field.
*
* @param field a searchdefinition field
* @param attributeName name of the attribute
* @return true if the attribute has been created by this field, else false
*/
static boolean attributeCreated(SDField field, String attributeName) {
if (!field.doesAttributing()) {
return false;
}
for (Attribute attribute : field.getAttributes().values()) {
if (attribute.getName().equals(attributeName)) {
return true;
}
}
return false;
}
}
|