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

import com.yahoo.language.process.StemMode;

/**
 * The stemming setting of a field. This describes how the search engine
 * should transform content of this field into base forms (stems) to increase
 * recall (find "car" when you search for "cars" etc.).
 *
 * @author bratseth
 */
public enum Stemming {

     /** No stemming */
    NONE("none"),

    /** select shortest possible stem */
    SHORTEST("shortest"),

    /** select the "best" stem alternative */
    BEST("best"),

    /** index multiple stems */
    MULTIPLE("multiple");

    private final String name;

    /**
     * Returns the stemming object for the given string.
     * The legal stemming names are the stemming constants in any capitalization.
     *
     * @throws IllegalArgumentException if there is no stemming type with the given name
     */
    public static Stemming get(String stemmingName) {
        try {
            return Stemming.valueOf(stemmingName.toUpperCase());
        } catch (IllegalArgumentException e) {
            throw new IllegalArgumentException("'" + stemmingName + "' is not a valid stemming setting");
        }
    }

    Stemming(String name) {
        this.name = name;
    }

    public String getName() { return name; }

    @Override
    public String toString() {
        return "stemming " + name;
    }

    public StemMode toStemMode() {
        switch(this) {
            case SHORTEST: return StemMode.SHORTEST;
            case MULTIPLE: return StemMode.ALL;
            case BEST : return StemMode.BEST;
            case NONE: return StemMode.NONE;
            default: throw new IllegalStateException("Inconvertible stem mode " + this);
        }
    }

}