summaryrefslogtreecommitdiffstats
path: root/container-search
diff options
context:
space:
mode:
authorJon Marius Venstad <venstad@gmail.com>2021-01-08 14:56:00 +0100
committerJon Marius Venstad <venstad@gmail.com>2021-01-08 14:56:00 +0100
commit6c03f24c2e99f2356ecbbdc38f023593d4c31ec7 (patch)
tree34e98ee8afb94082ccab2ef1120a55593c673d9a /container-search
parente54383571d407c6c2ab4fef87be52a76f04e9a8d (diff)
Prune duplicate prefixes and children before combining them
Diffstat (limited to 'container-search')
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileCompiler.java34
1 files changed, 21 insertions, 13 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileCompiler.java b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileCompiler.java
index c31801a8446..38d302e4db2 100644
--- a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileCompiler.java
+++ b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileCompiler.java
@@ -115,15 +115,17 @@ public class QueryProfileCompiler {
for (var variant : variants)
trie.add(variant);
- trie.forEachPrefixAndChildren((prefixes, children) -> {
- for (var prefix : prefixes)
- if (hasWildcardBeforeEnd(prefix.binding))
- for (var variant : children)
- if ( ! variant.binding.isNull() && variant != prefix) {
- DimensionBinding combined = prefix.binding().combineWith(variant.binding());
- if ( ! combined.isInvalid() )
- expanded.add(new DimensionBindingForPath(combined, prefix.path()));
- }
+ trie.forEachPrefixAndChildren((prefixes, childBindings) -> {
+ Set<DimensionBinding> processed = new HashSet<>();
+ for (DimensionBindingForPath prefix : prefixes)
+ if (processed.add(prefix.binding()))
+ if (hasWildcardBeforeEnd(prefix.binding()))
+ for (DimensionBinding childBinding : childBindings)
+ if (childBinding != prefix.binding()) {
+ DimensionBinding combined = prefix.binding().combineWith(childBinding);
+ if ( ! combined.isInvalid())
+ expanded.add(new DimensionBindingForPath(combined, prefix.path()));
+ }
});
return expanded;
@@ -234,7 +236,7 @@ public class QueryProfileCompiler {
}
/** Performs action on sets of path prefixes against all their (common) children. */
- void forEachPrefixAndChildren(BiConsumer<Collection<DimensionBindingForPath>, Collection<DimensionBindingForPath>> action) {
+ void forEachPrefixAndChildren(BiConsumer<Collection<DimensionBindingForPath>, Collection<DimensionBinding>> action) {
root.visit(action);
}
@@ -248,12 +250,18 @@ public class QueryProfileCompiler {
this.depth = depth;
}
- /** Performs action on the elements of this against all child elements, then returns the union of these two sets. */
- List<DimensionBindingForPath> visit(BiConsumer<Collection<DimensionBindingForPath>, Collection<DimensionBindingForPath>> action) {
- List<DimensionBindingForPath> allChildren = new ArrayList<>(elements);
+ /** Performs action on the elements of this against all child element bindings, then returns the union of these two sets. */
+ Set<DimensionBinding> visit(BiConsumer<Collection<DimensionBindingForPath>, Collection<DimensionBinding>> action) {
+ Set<DimensionBinding> allChildren = new HashSet<>();
for (Node child : children.values())
allChildren.addAll(child.visit(action));
+
+ for (DimensionBindingForPath element : elements)
+ if ( ! element.binding().isNull())
+ allChildren.add(element.binding());
+
action.accept(elements, allChildren);
+
return allChildren;
}