summaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/searchdefinition/document/BooleanIndexDefinition.java
blob: efe4d1ade5c5e783a28b70c01d3b67cb77ea85f1 (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
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.searchdefinition.document;

import java.util.OptionalDouble;
import java.util.OptionalInt;
import java.util.OptionalLong;

/**
 * Encapsulates values required for native implementation of boolean search.
 *
 * @author <a href="mailto:lesters@yahoo-inc.com">Lester Solbakken</a>
 * @since 5.2
 */
public final class BooleanIndexDefinition
{
    public static final int DEFAULT_ARITY = 8;
    public static final long DEFAULT_UPPER_BOUND = Long.MAX_VALUE;
    public static final long DEFAULT_LOWER_BOUND = Long.MIN_VALUE;
    public static final double DEFAULT_DENSE_POSTING_LIST_THRESHOLD = 0.4;

    private final OptionalInt arity;   // mandatory field value
    private final OptionalLong lowerBound;
    private final OptionalLong upperBound;
    private final OptionalDouble densePostingListThreshold;

    public BooleanIndexDefinition(OptionalInt arity, OptionalLong lowerBound,
                                  OptionalLong upperBound, OptionalDouble densePostingListThreshold) {
        this.arity = arity;
        this.lowerBound = lowerBound;
        this.upperBound = upperBound;
        this.densePostingListThreshold = densePostingListThreshold;
    }

    public int getArity() {
        return arity.getAsInt();
    }

    public boolean hasArity() {
        return arity.isPresent();
    }

    public long getLowerBound() {
        return lowerBound.orElse(DEFAULT_LOWER_BOUND);
    }

    public boolean hasLowerBound() {
        return lowerBound.isPresent();
    }

    public long getUpperBound() {
        return upperBound.orElse(DEFAULT_UPPER_BOUND);
    }

    public boolean hasUpperBound() {
        return upperBound.isPresent();
    }

    public double getDensePostingListThreshold() {
        return densePostingListThreshold.orElse(DEFAULT_DENSE_POSTING_LIST_THRESHOLD);
    }

    public boolean hasDensePostingListThreshold() {
        return densePostingListThreshold.isPresent();
    }

    @Override
    public String toString() {
        return "BooleanIndexDefinition [arity=" + arity + ", lowerBound="
                + lowerBound + ", upperBound=" + upperBound + ", densePostingListThreshold="
                + densePostingListThreshold + "]";
    }

}