summaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/search/query/profile/types/TensorFieldType.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 /container-search/src/main/java/com/yahoo/search/query/profile/types/TensorFieldType.java
Publish
Diffstat (limited to 'container-search/src/main/java/com/yahoo/search/query/profile/types/TensorFieldType.java')
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/types/TensorFieldType.java59
1 files changed, 59 insertions, 0 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/types/TensorFieldType.java b/container-search/src/main/java/com/yahoo/search/query/profile/types/TensorFieldType.java
new file mode 100644
index 00000000000..747cf73acb3
--- /dev/null
+++ b/container-search/src/main/java/com/yahoo/search/query/profile/types/TensorFieldType.java
@@ -0,0 +1,59 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.search.query.profile.types;
+
+import com.yahoo.search.query.profile.QueryProfileRegistry;
+import com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry;
+import com.yahoo.tensor.MapTensor;
+import com.yahoo.tensor.Tensor;
+import com.yahoo.tensor.TensorType;
+
+import java.util.Optional;
+
+/**
+ * A tensor field type in a query profile
+ *
+ * @author bratseth
+ */
+public class TensorFieldType extends FieldType {
+
+ private final Optional<TensorType> type;
+
+ /** Creates a tensor field type with optional information about the kind of tensor this will hold */
+ public TensorFieldType(Optional<TensorType> type) {
+ this.type = type;
+ }
+
+ /** Returns information about the type of tensor this will hold, or empty to allow any kind of tensor */
+ public Optional<TensorType> type() { return type; }
+
+ @Override
+ public Class getValueClass() { return Tensor.class; }
+
+ @Override
+ public String stringValue() { return "tensor"; }
+
+ @Override
+ public String toString() { return "field type " + stringValue(); }
+
+ @Override
+ public String toInstanceDescription() { return "a tensor"; }
+
+ @Override
+ public Object convertFrom(Object o, QueryProfileRegistry registry) {
+ if (o instanceof Tensor) return o;
+ if (o instanceof String) return MapTensor.from((String)o);
+ return null;
+ }
+
+ @Override
+ public Object convertFrom(Object o, CompiledQueryProfileRegistry registry) {
+ return convertFrom(o, (QueryProfileRegistry)null);
+ }
+
+ public static TensorFieldType fromTypeString(String s) {
+ if (s.equals("tensor")) return genericTensorType;
+ return new TensorFieldType(Optional.of(TensorType.fromSpec(s)));
+ }
+
+
+}