aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/main/java/com/yahoo/searchlib/ranking/features/fieldmatch/QueryTerm.java
blob: aaac4c259858925d725875a266436afcaa71ca4a (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.searchlib.ranking.features.fieldmatch;

/**
 * A query term. Query terms are equal if they have the same term string.
 *
 * @author  bratseth
 */
public final class QueryTerm {

    private String term;

    private float connectedness = 0.1f;

    private int weight = 100;

    private float significance = 0.1f;

    private float exactness = 1.0f;

    public QueryTerm(String term) {
        this.term=term;
    }

    public QueryTerm(String term,float connectedness) {
        this.term=term;
        this.connectedness=connectedness;
    }

    public void setTerm(String term) { this.term=term; }

    public String getTerm() { return term; }

    /**
     * Returns how connected this term is to the previous term in the query.
     * Default: 0.1. This is always a number between 0 (not connected at all) and 1 (virtually inseparable)
     */
    public float getConnectedness() { return connectedness; }

    public void setConnectedness(float connectedness) { this.connectedness=connectedness; }

    public void setWeight(int weight) { this.weight=weight; }

    public int getWeight() { return weight; }

    /** The significance of this term: 1-term frequency */
    public void setSignificance(float significance) { this.significance=significance; }

    public float getSignificance() { return significance; }

    /** The degree to which this is exactly the term the user specified (1), or a stemmed form (closer to 0) */
    public float getExactness() { return exactness; }

    @Override
    public int hashCode() { return term.hashCode(); }

    @Override
    public boolean equals(Object object) {
        if (! (object instanceof QueryTerm)) return false;

        return this.term.equals(((QueryTerm)object).term);
    }

    @Override
    public String toString() {
        if (connectedness==0.1f) return term;
        return connectedness + ":" + term;
    }

}