aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/schema/document/RankType.java
blob: 4940589f76006f58d22234fa23729828790d01a0 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.schema.document;

/**
 * The rank type of a field. For now this is just a container of a string name.
 * This class is immutable.
 *
 * @author  bratseth
 */
public enum RankType {

    /** *implicit* default: No type has been set. */
    DEFAULT,

    // Rank types which can be set explicitly. These are defined for Vespa in NativeRankTypeDefinitionSet
    IDENTITY, ABOUT, TAGS, EMPTY;

    @Override
    public String toString() {
        return "rank type " + name().toLowerCase();
    }

    /**
     * Returns the rank type from a string, regardless of its case.
     *
     * @param  rankTypeName a rank type name in any casing
     * @return the rank type found
     * @throws IllegalArgumentException if not found
     */
    public static RankType fromString(String rankTypeName) {
        try {
            return RankType.valueOf(rankTypeName.toUpperCase());
        }
        catch (IllegalArgumentException e) {
            throw new IllegalArgumentException("Unknown rank type '" + rankTypeName + "'. Supported rank types are " +
                                               "'identity', 'about', 'tags' and 'empty'.");
        }
    }

}