summaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/SummaryInFieldLongOperation.java
blob: 4d6e077aaaa31d3decd703f1cf858a964e506112 (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
// 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.document.DataType;
import com.yahoo.searchdefinition.document.SDField;
import com.yahoo.vespa.documentmodel.SummaryField;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

/**
 * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a>
 */
public class SummaryInFieldLongOperation extends SummaryInFieldOperation {
    private DataType type;
    private Boolean bold;
    private Set<String> destinations = new java.util.LinkedHashSet<>();
    private List<SummaryField.Property> properties = new ArrayList<>();

    public SummaryInFieldLongOperation(String name) {
        super(name);
    }

    public SummaryInFieldLongOperation() {
        super(null);
    }

    public void setType(DataType type) {
        this.type = type;
    }

    public void setBold(Boolean bold) {
        this.bold = bold;
    }

    public void addDestination(String destination) {
        destinations.add(destination);
    }

    public Iterator<String> destinationIterator() {
        return destinations.iterator();
    }


    public void addProperty(SummaryField.Property property) {
        properties.add(property);
    }

    public void apply(SDField field) {
        if (type == null) {
            type = field.getDataType();
        }
        SummaryField summary = new SummaryField(name, type);
        applyToSummary(summary);
        field.addSummaryField(summary);
    }

    public void applyToSummary(SummaryField summary) {
        if (transform != null) {
            summary.setTransform(transform);
        }

        if (bold != null) {
            summary.setTransform(bold ? summary.getTransform().bold() : summary.getTransform().unbold());
        }

        for (SummaryField.Source source : sources) {
            summary.addSource(source);
        }

        for (String destination : destinations) {
            summary.addDestination(destination);
        }

        for (SummaryField.Property prop : properties) {
            summary.addProperty(prop.getName(), prop.getValue());
        }
    }
}