aboutsummaryrefslogtreecommitdiffstats
path: root/vespajlib
diff options
context:
space:
mode:
authorArne Juul <arnej@yahooinc.com>2023-05-11 11:31:14 +0000
committerArne Juul <arnej@yahooinc.com>2023-05-11 12:34:35 +0000
commit47b370c90715a15939474951fbdb6fad987073e9 (patch)
tree1b8fc8756d2e9b5c9c38b7ee4ca8c82a3cd25e28 /vespajlib
parent5693b9621d9882f0e9a66c7d6441b898cb43f6d9 (diff)
add filtering to hide implicitly added match features
Diffstat (limited to 'vespajlib')
-rw-r--r--vespajlib/src/main/java/com/yahoo/data/access/helpers/MatchFeatureData.java11
-rw-r--r--vespajlib/src/main/java/com/yahoo/data/access/helpers/MatchFeatureFilter.java40
2 files changed, 51 insertions, 0 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/data/access/helpers/MatchFeatureData.java b/vespajlib/src/main/java/com/yahoo/data/access/helpers/MatchFeatureData.java
index f7d72ade20d..4f8bd64f85a 100644
--- a/vespajlib/src/main/java/com/yahoo/data/access/helpers/MatchFeatureData.java
+++ b/vespajlib/src/main/java/com/yahoo/data/access/helpers/MatchFeatureData.java
@@ -13,6 +13,7 @@ import java.util.ArrayList;
import java.util.AbstractMap.SimpleEntry;
import java.util.List;
import java.util.Map;
+import java.util.function.Function;
/**
* MatchFeatureData helps pack match features for hits into
@@ -85,6 +86,16 @@ public class MatchFeatureData {
}
return new Value.DoubleValue(doubleValues[index]);
}
+
+ public HitValue subsetFilter(Function<Hashlet<String,Integer>, Hashlet<String,Integer>> filter) {
+ return new HitValue(filter.apply(hashlet), dataValues, doubleValues);
+ }
+ // used only from subsetFilter() above
+ private HitValue(Hashlet<String,Integer> hashlet, byte[][] dataValues, double[] doubleValues) {
+ this.hashlet = hashlet;
+ this.dataValues = dataValues;
+ this.doubleValues = doubleValues;
+ }
}
public HitValue addHit() {
diff --git a/vespajlib/src/main/java/com/yahoo/data/access/helpers/MatchFeatureFilter.java b/vespajlib/src/main/java/com/yahoo/data/access/helpers/MatchFeatureFilter.java
new file mode 100644
index 00000000000..96451f35504
--- /dev/null
+++ b/vespajlib/src/main/java/com/yahoo/data/access/helpers/MatchFeatureFilter.java
@@ -0,0 +1,40 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.data.access.helpers;
+
+import com.yahoo.collections.Hashlet;
+
+import java.util.Collection;
+import java.util.IdentityHashMap;
+import java.util.function.Function;
+
+/**
+ * Helper class to remove (filter) some names from a Hashlet
+ * @author arnej
+ */
+public class MatchFeatureFilter implements Function<Hashlet<String,Integer>, Hashlet<String,Integer>> {
+
+ private final IdentityHashMap<Hashlet<String,Integer>, Hashlet<String,Integer>> mappings = new IdentityHashMap<>();
+ private final Collection<String> removeList;
+
+ public MatchFeatureFilter(Collection<String> removeList) {
+ this.removeList = removeList;
+ }
+
+ Hashlet<String,Integer> filter(Hashlet<String,Integer> input) {
+ Hashlet<String,Integer> result = new Hashlet<>();
+ result.reserve(input.size());
+ for (int i = 0; i < input.size(); i++) {
+ String k = input.key(i);
+ if (! removeList.contains(k)) {
+ Integer v = input.value(i);
+ result.put(k, v);
+ }
+ }
+ return result;
+ }
+
+ public Hashlet<String,Integer> apply(Hashlet<String,Integer> input) {
+ return mappings.computeIfAbsent(input, k -> filter(k));
+ }
+
+}