diff options
Diffstat (limited to 'config-model/src/main/java/com/yahoo/searchdefinition/RankingConstant.java')
-rw-r--r-- | config-model/src/main/java/com/yahoo/searchdefinition/RankingConstant.java | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/RankingConstant.java b/config-model/src/main/java/com/yahoo/searchdefinition/RankingConstant.java index c65e0fad1c7..a2bdc6834c9 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/RankingConstant.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/RankingConstant.java @@ -12,12 +12,20 @@ import java.util.Objects; */ public class RankingConstant { + public enum PathType {FILE, URI}; + /** The search definition-unique name of this constant */ private final String name; private TensorType tensorType = null; - private String fileName = null; + private String path = null; private String fileReference = ""; + public PathType getPathType() { + return pathType; + } + + private PathType pathType = PathType.FILE; + public RankingConstant(String name) { this.name = name; } @@ -25,13 +33,20 @@ public class RankingConstant { public RankingConstant(String name, TensorType type, String fileName) { this(name); this.tensorType = type; - this.fileName = fileName; + this.path = fileName; validate(); } public void setFileName(String fileName) { Objects.requireNonNull(fileName, "Filename cannot be null"); - this.fileName = fileName; + this.path = fileName; + this.pathType = PathType.FILE; + } + + public void setUri(String uri) { + Objects.requireNonNull(uri, "uri cannot be null"); + this.path = uri; + this.pathType = PathType.URI; } /** @@ -43,14 +58,15 @@ public class RankingConstant { public void setType(TensorType tensorType) { this.tensorType = tensorType; } public String getName() { return name; } - public String getFileName() { return fileName; } + public String getFileName() { return path; } + public String getUri() { return path; } public String getFileReference() { return fileReference; } public TensorType getTensorType() { return tensorType; } public String getType() { return tensorType.toString(); } public void validate() { - if (fileName == null || fileName.isEmpty()) - throw new IllegalArgumentException("Ranking constants must have a file."); + if (path == null || path.isEmpty()) + throw new IllegalArgumentException("Ranking constants must have a file or uri."); if (tensorType == null) throw new IllegalArgumentException("Ranking constant '" + name + "' must have a type."); } @@ -58,7 +74,7 @@ public class RankingConstant { public String toString() { StringBuilder b = new StringBuilder(); b.append("constant '").append(name) - .append("' from file '").append(fileName) + .append(pathType == PathType.FILE ? "' from file '" : " from uri ").append(path) .append("' with ref '").append(fileReference) .append("' of type '").append(tensorType) .append("'"); |