summaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/searchdefinition/RankingConstants.java
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@oath.com>2018-08-24 12:40:33 +0200
committerJon Bratseth <bratseth@oath.com>2018-08-24 12:40:33 +0200
commit0d36001a8827c287e0605f3be9b3ef2d6e53778c (patch)
treeb0e3c03871d88e675bfada80d07bdb389d1d084f /config-model/src/main/java/com/yahoo/searchdefinition/RankingConstants.java
parentb88fd2c2b9c3e220b6884da0392a3602fb3aa994 (diff)
Separate out ranking constants
Diffstat (limited to 'config-model/src/main/java/com/yahoo/searchdefinition/RankingConstants.java')
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/RankingConstants.java36
1 files changed, 36 insertions, 0 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/RankingConstants.java b/config-model/src/main/java/com/yahoo/searchdefinition/RankingConstants.java
new file mode 100644
index 00000000000..164cb7f808e
--- /dev/null
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/RankingConstants.java
@@ -0,0 +1,36 @@
+// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.searchdefinition;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Constant values for ranking/model execution tied to a search definition, or globally to an application
+ * package
+ *
+ * @author bratseth
+ */
+public class RankingConstants {
+
+ private final Map<String, RankingConstant> constants = new HashMap<>();
+
+ public void add(RankingConstant constant) {
+ constant.validate();
+ String name = constant.getName();
+ if (constants.containsKey(name))
+ throw new IllegalArgumentException("Ranking constant '" + name + "' defined twice");
+ constants.put(name, constant);
+ }
+
+ /** Returns the ranking constant with the given name, or null if not present */
+ public RankingConstant get(String name) {
+ return constants.get(name);
+ }
+
+ /** Returns a read-only map of the ranking constants in this indexed by name */
+ public Map<String, RankingConstant> asMap() {
+ return Collections.unmodifiableMap(constants);
+ }
+
+}