aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/AttributeOperation.java
blob: 4df3660a967cb9b742c4d92bd0c3f6fce1816005 (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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.searchdefinition.fieldoperation;

import com.yahoo.searchdefinition.document.Attribute;
import com.yahoo.searchdefinition.document.SDField;
import com.yahoo.tensor.TensorType;

import java.util.Optional;

/**
 * @author Einar M R Rosenvinge
 */
public class AttributeOperation implements FieldOperation, FieldOperationContainer {

    private final String name;
    private Boolean huge;
    private Boolean fastSearch;
    private Boolean fastAccess;
    private Boolean mutable;
    private Boolean prefetch;
    private Boolean enableBitVectors;
    private Boolean enableOnlyBitVector;
    //TODO: Husk sorting!!
    private boolean doAlias = false;
    private String alias;
    private String aliasedName;
    private Optional<TensorType> tensorType = Optional.empty();

    public AttributeOperation(String name) {
        this.name = name;
    }

    @Override
    public void addOperation(FieldOperation op) {
        //TODO: Implement this method:

    }

    @Override
    public void applyOperations(SDField field) {
        //TODO: Implement this method:
    }

    @Override
    public String getName() {
        return name;
    }

    public Boolean getHuge() {
        return huge;
    }

    public void setHuge(Boolean huge) {
        this.huge = huge;
    }

    public Boolean getFastSearch() {
        return fastSearch;
    }

    public void setFastSearch(Boolean fastSearch) {
        this.fastSearch = fastSearch;
    }

    public Boolean getFastAccess() {
        return fastAccess;
    }

    public void setFastAccess(Boolean fastAccess) {
        this.fastAccess = fastAccess;
    }
    public void setMutable(Boolean mutable) {
        this.mutable = mutable;
    }

    public Boolean getPrefetch() {
        return prefetch;
    }

    public void setPrefetch(Boolean prefetch) {
        this.prefetch = prefetch;
    }

    public Boolean getEnableBitVectors() {
        return enableBitVectors;
    }

    public void setEnableBitVectors(Boolean enableBitVectors) {
        this.enableBitVectors = enableBitVectors;
    }

    public Boolean getEnableOnlyBitVector() {
        return enableOnlyBitVector;
    }

    public void setEnableOnlyBitVector(Boolean enableOnlyBitVector) {
        this.enableOnlyBitVector = enableOnlyBitVector;
    }

    public boolean isDoAlias() {
        return doAlias;
    }

    public void setDoAlias(boolean doAlias) {
        this.doAlias = doAlias;
    }

    public String getAlias() {
        return alias;
    }

    public void setAlias(String alias) {
        this.alias = alias;
    }

    public String getAliasedName() {
        return aliasedName;
    }

    public void setAliasedName(String aliasedName) {
        this.aliasedName = aliasedName;
    }

    public void setTensorType(TensorType tensorType) {
        this.tensorType = Optional.of(tensorType);
    }

    public void apply(SDField field) {
        Attribute attribute = null;
        if (attributeIsSuffixOfStructField(field.getName())) {
            attribute = field.getAttributes().get(field.getName());
        }
        if (attribute == null) {
            attribute = field.getAttributes().get(name);
            if (attribute == null) {
                attribute = new Attribute(name, field.getDataType());
                field.addAttribute(attribute);
            }
        }

        if (huge != null) {
            attribute.setHuge(huge);
        }
        if (fastSearch != null) {
            attribute.setFastSearch(fastSearch);
        }
        if (fastAccess != null) {
            attribute.setFastAccess(fastAccess);
        }
        if (mutable != null) {
            attribute.setMutable(mutable);
        }
        if (prefetch != null) {
            attribute.setPrefetch(prefetch);
        }
        if (enableBitVectors != null) {
            attribute.setEnableBitVectors(enableBitVectors);
        }
        if (enableOnlyBitVector != null) {
            attribute.setEnableOnlyBitVector(enableOnlyBitVector);
        }
        if (doAlias) {
            field.getAliasToName().put(alias, aliasedName);
        }
        if (tensorType.isPresent()) {
            attribute.setTensorType(tensorType.get());
        }
    }

    private boolean attributeIsSuffixOfStructField(String fieldName) {
        return ((fieldName.indexOf('.') != -1) && fieldName.endsWith(name));
    }

}