summaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/vespa/documentmodel/SummaryTransform.java
blob: 5c3aef89edc4fb9200f3894b295deee469eede12 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.documentmodel;

/**
 * A value class representing a search time
 * transformation on a summary field.
 *
 * @author bratseth
 */
public enum SummaryTransform {

    NONE("none"),
    ATTRIBUTE("attribute"),
    BOLDED("bolded"),
    DISTANCE("distance"),
    DYNAMICBOLDED("dynamicbolded"),
    DYNAMICTEASER("dynamicteaser"),
    POSITIONS("positions"),
    RANKFEATURES("rankfeatures"),
    SUMMARYFEATURES("summaryfeatures"),
    TEXTEXTRACTOR("textextractor"),
    GEOPOS("geopos"),
    ATTRIBUTECOMBINER("attributecombiner"),
    MATCHED_ELEMENTS_FILTER("matchedelementsfilter"),
    MATCHED_ATTRIBUTE_ELEMENTS_FILTER("matchedattributeelementsfilter"),
    COPY("copy"),
    DOCUMENT_ID("documentid");

    private final String name;

    SummaryTransform(String name) {
        this.name=name;
    }

    public String getName() {
        return name;
    }

    /** Returns the bolded version of this transform if possible, throws if not */
    public SummaryTransform bold() {
        switch (this) {
        case NONE:
        case BOLDED:
            return BOLDED;

        case DYNAMICBOLDED:
        case DYNAMICTEASER:
            return DYNAMICBOLDED;

        default:
            throw new IllegalArgumentException("Can not bold a '" + this + "' field.");
        }
    }

    /** Returns the unbolded version of this transform */
    public SummaryTransform unbold() {
        switch (this) {
        case NONE:
        case BOLDED:
            return NONE;

        case DYNAMICBOLDED:
            return DYNAMICTEASER;

        default:
            return this;
        }
    }

    /** Returns whether this value is bolded */
    public boolean isBolded() {
        return this==BOLDED || this==DYNAMICBOLDED;
    }

    /** Whether this is dynamically generated, both teasers and bolded fields are dynamic */
    public boolean isDynamic() {
        return this==BOLDED || this==DYNAMICBOLDED || this==DYNAMICTEASER;
    }

    /** Returns whether this is a teaser, not the complete field value */
    public boolean isTeaser() {
        return this==DYNAMICBOLDED || this==DYNAMICTEASER;
    }

    /** Returns whether this transform always gets its value by accessing memory only */
    public boolean isInMemory() {
        switch (this) {
        case ATTRIBUTE:
        case DISTANCE:
        case POSITIONS:
        case GEOPOS:
        case RANKFEATURES:
        case SUMMARYFEATURES:
        case ATTRIBUTECOMBINER:
        case MATCHED_ATTRIBUTE_ELEMENTS_FILTER:
            return true;

        default:
            return false;
        }
    }

    public String toString() {
        return name;
    }
}