aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/searchdefinition/document/Stemming.java
blob: b5a0ecfbe3dcff190b63fcbf6cb34fcdf0fafd3e (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
// 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 com.yahoo.language.process.StemMode;

import java.util.logging.Logger;

/**
 * <p>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.).</p>
 *
 * @author bratseth
 */
public enum Stemming {

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

    /** @deprecated incorrectly don't stem at all */
    @Deprecated
    ALL("all"),

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

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

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

    private static Logger log=Logger.getLogger(Stemming.class.getName());

    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
     */
    @SuppressWarnings("deprecation")
    public static Stemming get(String stemmingName) {
        try {
            Stemming stemming = Stemming.valueOf(stemmingName.toUpperCase());
            if (stemming.equals(ALL)) {
                log.warning("note: stemming ALL is the same as stemming mode SHORTEST");
                stemming = SHORTEST;
            }
            return stemming;
        } catch (IllegalArgumentException e) {
            throw new IllegalArgumentException("'" + stemmingName + "' is not a valid stemming setting");
        }
    }

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

    public String getName() { return name; }

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

    @SuppressWarnings("deprecation")
    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;
            case ALL: return StemMode.SHORTEST; // Intentional; preserve historic behavior
            default: throw new IllegalStateException("Inconvertible stem mode " + this);
        }
    }

}