aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/searchdefinition/processing/TensorFieldProcessor.java
blob: ae16f6cfed842a177565fc1b518fe7da9cf853c4 (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
// Copyright 2016 Yahoo Inc. 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.document.DataType;
import com.yahoo.searchdefinition.RankProfileRegistry;
import com.yahoo.searchdefinition.Search;
import com.yahoo.searchdefinition.document.Attribute;
import com.yahoo.searchdefinition.document.SDField;
import com.yahoo.vespa.model.container.search.QueryProfiles;

/**
 * Class that processes and validates tensor fields.
 *
 * @author geirst
 */
public class TensorFieldProcessor extends Processor {

    public TensorFieldProcessor(Search search, DeployLogger deployLogger, RankProfileRegistry rankProfileRegistry, QueryProfiles queryProfiles) {
        super(search, deployLogger, rankProfileRegistry, queryProfiles);
    }

    @Override
    public void process() {
        for (SDField field : search.allFieldsList()) {
            if (field.getDataType() == DataType.TENSOR) {
                warnUseOfTensorFieldAsAttribute(field);
                validateIndexingScripsForTensorField(field);
                validateAttributeSettingForTensorField(field);
            } else {
                validateDataTypeForField(field);
            }
        }
    }

    private void warnUseOfTensorFieldAsAttribute(SDField field) {
        if (field.doesAttributing()) {
            // TODO (geirst): Remove when no longer beta
            warn(search, field, "An attribute of type 'tensor' is currently beta, and re-feeding data between Vespa versions might be required.");
        }
    }

    private void validateIndexingScripsForTensorField(SDField field) {
        if (field.doesIndexing()) {
            fail(search, field, "A field of type 'tensor' cannot be specified as an 'index' field.");
        }
    }

    private void validateAttributeSettingForTensorField(SDField field) {
        if (field.doesAttributing()) {
            Attribute attribute = field.getAttributes().get(field.getName());
            if (attribute != null && attribute.isFastSearch()) {
                fail(search, field, "An attribute of type 'tensor' cannot be 'fast-search'.");
            }
        }
    }

    private void validateDataTypeForField(SDField field) {
        if (field.getDataType().getPrimitiveType() == DataType.TENSOR) {
            fail(search, field, "A field with collection type of tensor is not supported. Use simple type 'tensor' instead.");
        }
    }
}