summaryrefslogtreecommitdiffstats
path: root/container-search
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2017-01-16 23:16:32 +0100
committerGitHub <noreply@github.com>2017-01-16 23:16:32 +0100
commit9efbe90ee02b6b56f1a1208614c20d4b053a3135 (patch)
tree86dc5fcbd4e2244c7a82c2019a77635d33f7b87a /container-search
parent7305314406270fe663b7ef301cd6ad04714dcf9b (diff)
Revert "Revert "Revert "Bratseth/tensor type info in documents"""
Diffstat (limited to 'container-search')
-rw-r--r--container-search/src/test/java/com/yahoo/fs4/test/RankFeaturesTestCase.java27
1 files changed, 12 insertions, 15 deletions
diff --git a/container-search/src/test/java/com/yahoo/fs4/test/RankFeaturesTestCase.java b/container-search/src/test/java/com/yahoo/fs4/test/RankFeaturesTestCase.java
index 5cf9aeda978..8c209438565 100644
--- a/container-search/src/test/java/com/yahoo/fs4/test/RankFeaturesTestCase.java
+++ b/container-search/src/test/java/com/yahoo/fs4/test/RankFeaturesTestCase.java
@@ -5,7 +5,6 @@ import com.yahoo.io.GrowableByteBuffer;
import com.yahoo.search.query.ranking.RankFeatures;
import com.yahoo.search.query.ranking.RankProperties;
import com.yahoo.tensor.Tensor;
-import com.yahoo.tensor.TensorType;
import com.yahoo.tensor.serialization.TypedBinaryFormat;
import com.yahoo.text.Utf8;
import org.junit.Test;
@@ -31,18 +30,16 @@ public class RankFeaturesTestCase {
@Test
public void requireThatSingleTensorIsBinaryEncoded() {
- TensorType type = new TensorType.Builder().mapped("x").mapped("y").mapped("z").build();
- Tensor tensor = Tensor.from(type, "{ {x:a, y:b, z:c}:2.0, {x:a, y:b, z:c2}:3.0 }");
- assertTensorEncodingAndDecoding(type, "query(my_tensor)", "my_tensor", tensor);
- assertTensorEncodingAndDecoding(type, "$my_tensor", "my_tensor", tensor);
+ Tensor tensor = Tensor.from("{ {x:a, y:b, z:c}:2.0, {x:a, y:b, z:c2}:3.0 }");
+ assertTensorEncodingAndDecoding("query(my_tensor)", "my_tensor", tensor);
+ assertTensorEncodingAndDecoding("$my_tensor", "my_tensor", tensor);
}
@Test
public void requireThatMultipleTensorsAreBinaryEncoded() {
- TensorType type = new TensorType.Builder().mapped("x").mapped("y").mapped("z").build();
- Tensor tensor1 = Tensor.from(type, "{ {x:a, y:b, z:c}:2.0, {x:a, y:b, z:c2}:3.0 }");
- Tensor tensor2 = Tensor.from(type, "{ {x:a, y:b, z:c}:5.0 }");
- assertTensorEncodingAndDecoding(type, Arrays.asList(
+ Tensor tensor1 = Tensor.from("{ {x:a, y:b, z:c}:2.0, {x:a, y:b, z:c2}:3.0 }");
+ Tensor tensor2 = Tensor.from("{ {x:a, y:b, z:c}:5.0 }");
+ assertTensorEncodingAndDecoding(Arrays.asList(
new Entry("query(tensor1)", "tensor1", tensor1),
new Entry("$tensor2", "tensor2", tensor2)));
}
@@ -58,11 +55,11 @@ public class RankFeaturesTestCase {
}
}
- private static void assertTensorEncodingAndDecoding(TensorType type, List<Entry> entries) {
+ private static void assertTensorEncodingAndDecoding(List<Entry> entries) {
RankProperties properties = createRankPropertiesWithTensors(entries);
assertEquals(entries.size(), properties.asMap().size());
- Map<String, Object> decodedProperties = decode(type, encode(properties));
+ Map<String, Object> decodedProperties = decode(encode(properties));
assertEquals(entries.size() * 2, properties.asMap().size()); // tensor type info has been added
assertEquals(entries.size() * 2, decodedProperties.size());
for (Entry entry : entries) {
@@ -71,8 +68,8 @@ public class RankFeaturesTestCase {
}
}
- private static void assertTensorEncodingAndDecoding(TensorType type, String key, String normalizedKey, Tensor tensor) {
- assertTensorEncodingAndDecoding(type, Arrays.asList(new Entry(key, normalizedKey, tensor)));
+ private static void assertTensorEncodingAndDecoding(String key, String normalizedKey, Tensor tensor) {
+ assertTensorEncodingAndDecoding(Arrays.asList(new Entry(key, normalizedKey, tensor)));
}
private static RankProperties createRankPropertiesWithTensors(List<Entry> entries) {
@@ -94,7 +91,7 @@ public class RankFeaturesTestCase {
return result;
}
- private static Map<String, Object> decode(TensorType type, byte[] encodedProperties) {
+ private static Map<String, Object> decode(byte[] encodedProperties) {
GrowableByteBuffer buffer = GrowableByteBuffer.wrap(encodedProperties);
byte[] mapNameBytes = new byte[buffer.getInt()];
buffer.get(mapNameBytes);
@@ -109,7 +106,7 @@ public class RankFeaturesTestCase {
if (key.contains(".type")) {
result.put(key, Utf8.toString(value));
} else {
- result.put(key, TypedBinaryFormat.decode(type, value));
+ result.put(key, TypedBinaryFormat.decode(null, value)); // TODO: Pass type
}
}
return result;