summaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/searchdefinition/document/Stemming.java
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
commit72231250ed81e10d66bfe70701e64fa5fe50f712 (patch)
tree2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /config-model/src/main/java/com/yahoo/searchdefinition/document/Stemming.java
Publish
Diffstat (limited to 'config-model/src/main/java/com/yahoo/searchdefinition/document/Stemming.java')
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/document/Stemming.java72
1 files changed, 72 insertions, 0 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/document/Stemming.java b/config-model/src/main/java/com/yahoo/searchdefinition/document/Stemming.java
new file mode 100644
index 00000000000..f471201f55e
--- /dev/null
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/document/Stemming.java
@@ -0,0 +1,72 @@
+// Copyright 2016 Yahoo Inc. 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"),
+
+ /** Stem as much as possible */
+ ALL("all"),
+
+ /** select shortest possible stem */
+ SHORTEST("shortest"),
+
+ /** index (and query?) 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
+ */
+ 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");
+ }
+ }
+
+ private Stemming(String name) {
+ this.name = name;
+ }
+
+ public String getName() { return name; }
+
+ public String toString() {
+ return "stemming " + name;
+ }
+
+ public StemMode toStemMode() {
+ if (this == Stemming.SHORTEST) {
+ return StemMode.SHORTEST;
+ }
+ if (this == Stemming.MULTIPLE) {
+ return StemMode.ALL;
+ }
+ return StemMode.NONE;
+ }
+
+}