blob: b09f85726e52d9bbea8f1831711e36d8f0fedf06 (
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
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.searchdefinition.derived.validation;
import com.yahoo.searchdefinition.document.SDDocumentType;
import com.yahoo.searchdefinition.Search;
import com.yahoo.searchdefinition.derived.DerivedConfiguration;
import com.yahoo.searchdefinition.derived.IndexingScript;
import com.yahoo.vespa.indexinglanguage.ExpressionVisitor;
import com.yahoo.vespa.indexinglanguage.expressions.Expression;
import com.yahoo.vespa.indexinglanguage.expressions.OutputExpression;
/**
* @author <a href="mailto:mlidal@yahoo-inc.com">Mathias M Lidal</a>
*/
public class IndexStructureValidator extends Validator {
public IndexStructureValidator(DerivedConfiguration config, Search search) {
super(config, search);
}
public void validate() {
IndexingScript script = config.getIndexingScript();
for (Expression exp : script.expressions()) {
new OutputVisitor(search.getDocument(), exp).visit(exp);
}
}
private static class OutputVisitor extends ExpressionVisitor {
final SDDocumentType docType;
final Expression exp;
public OutputVisitor(SDDocumentType docType, Expression exp) {
this.docType = docType;
this.exp = exp;
}
@Override
protected void doVisit(Expression exp) {
if (!(exp instanceof OutputExpression)) {
return;
}
String fieldName = ((OutputExpression)exp).getFieldName();
if (docType.getField(fieldName) != null) {
return;
}
throw new IllegalArgumentException("Indexing expression '" + this.exp + "' refers to field '" +
fieldName + "' which does not exist in the index structure.");
}
}
}
|