aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/prelude/query/TaggableSegmentItem.java
blob: 1cba588ce405ef5e18fa4a2d949efe32f0f09698 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.prelude.query;

/**
 * Common implementation for Item classes implementing the TaggableItem interface.
 * Note that this file exist in 3 copies that should be kept in sync:
 *
 * CompositeTaggableItem.java
 * SimpleTaggableItem.java
 * TaggableSegmentItem.java
 *
 * These should only have trivial differences.
 * (multiple inheritance or mixins would have been nice).
 *
 * @author arnej27959
 */
public abstract class TaggableSegmentItem extends SegmentItem implements TaggableItem {

    protected TaggableSegmentItem(String rawWord, String current, boolean isFromQuery, boolean stemmed, Substring origin) {
        super(rawWord, current, isFromQuery, stemmed, origin);
    }

    @Override
    public int getUniqueID() {
        return uniqueID;
    }

    @Override
    public void setUniqueID(int id) {
        setHasUniqueID(true);
        uniqueID = id;
    }

    /** See {@link TaggableItem#setConnectivity} */
    @Override
    public void setConnectivity(Item item, double connectivity) {
        if (!(item instanceof TaggableItem)) {
            throw new IllegalArgumentException("setConnectivity item must be taggable, was: "
                                               + item.getClass() + " [" + item + "]");
        }
        setHasUniqueID(true);
        item.setHasUniqueID(true);
        if (connectedItem != null) {
            // untangle old connectivity
            connectedItem.connectedBacklink = null;
        }
        this.connectivity = connectivity;
        connectedItem = item;
        connectedItem.connectedBacklink = this;
    }

    @Override
    public Item getConnectedItem() {
        return connectedItem;
    }

    @Override
    public double getConnectivity() {
        return connectivity;
    }

    @Override
    public void setSignificance(double significance) {
        setHasUniqueID(true);
        setExplicitSignificance(true);
        this.significance = significance;
    }

    @Override
    public void setExplicitSignificance(boolean explicitSignificance) {
        this.explicitSignificance = explicitSignificance;
    }

    @Override
    public boolean hasExplicitSignificance() {
        return explicitSignificance;
    }

    @Override
    public double getSignificance() {
        return significance;
    }

    //Change access privilege from protected to public.
    @Override
    public boolean hasUniqueID() {
        return super.hasUniqueID();
    }

}