summaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/search/query
diff options
context:
space:
mode:
Diffstat (limited to 'container-search/src/main/java/com/yahoo/search/query')
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/QueryProfile.java18
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileCompiler.java56
2 files changed, 50 insertions, 24 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfile.java b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfile.java
index 0e6af6113b5..acca2d403be 100644
--- a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfile.java
+++ b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfile.java
@@ -330,21 +330,21 @@ public class QueryProfile extends FreezableSimpleComponent implements Cloneable
return node;
}
- final Object get(CompoundName name,DimensionBinding dimensionBinding) {
- return lookup(name,false,dimensionBinding);
+ final Object get(CompoundName name, DimensionBinding dimensionBinding) {
+ return lookup(name, false, dimensionBinding);
}
/**
* Returns the node at the position prescribed by the given name (without doing substitutions) -
* a primitive value, a substitutable string, a query profile, or null if not found.
*/
- public final Object lookup(String name, Map<String,String> context) {
+ public final Object lookup(String name, Map<String, String> context) {
return lookup(new CompoundName(name),true,DimensionBinding.createFrom(getDimensions(),context));
}
/** Sets a value in this or any nested profile using null as context */
public final void set(String name, Object value, QueryProfileRegistry registry) {
- set(name,value,(Map<String,String>)null, registry);
+ set(name, value, (Map<String, String>)null, registry);
}
/**
@@ -357,16 +357,16 @@ public class QueryProfile extends FreezableSimpleComponent implements Cloneable
* @throws IllegalArgumentException if the given name is illegal given the types of this or any nested query profile
* @throws IllegalStateException if this query profile is frozen
*/
- public final void set(CompoundName name,Object value,Map<String,String> context, QueryProfileRegistry registry) {
+ public final void set(CompoundName name, Object value, Map<String,String> context, QueryProfileRegistry registry) {
set(name, value, DimensionBinding.createFrom(getDimensions(), context), registry);
}
- public final void set(String name,Object value,Map<String,String> context, QueryProfileRegistry registry) {
+ public final void set(String name, Object value, Map<String,String> context, QueryProfileRegistry registry) {
set(new CompoundName(name), value, DimensionBinding.createFrom(getDimensions(), context), registry);
}
- public final void set(String name,Object value,String[] dimensionValues, QueryProfileRegistry registry) {
- set(name,value,DimensionValues.createFrom(dimensionValues), registry);
+ public final void set(String name, Object value, String[] dimensionValues, QueryProfileRegistry registry) {
+ set(name, value, DimensionValues.createFrom(dimensionValues), registry);
}
/**
@@ -382,7 +382,7 @@ public class QueryProfile extends FreezableSimpleComponent implements Cloneable
* @throws IllegalArgumentException if the given name is illegal given the types of this or any nested query profile
* @throws IllegalStateException if this query profile is frozen
*/
- public final void set(String name,Object value,DimensionValues dimensionValues, QueryProfileRegistry registry) {
+ public final void set(String name,Object value, DimensionValues dimensionValues, QueryProfileRegistry registry) {
set(new CompoundName(name), value, DimensionBinding.createFrom(getDimensions(), dimensionValues), registry);
}
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 a7cfaf84e98..f75d04a1311 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
@@ -38,8 +38,7 @@ public class QueryProfileCompiler {
DimensionalMap.Builder<CompoundName, Object> unoverridables = new DimensionalMap.Builder<>();
// Resolve values for each existing variant and combine into a single data structure
- Set<DimensionBindingForPath> variants = new HashSet<>();
- collectVariants(CompoundName.empty, in, DimensionBinding.nullBinding, variants);
+ Set<DimensionBindingForPath> variants = collectVariants(CompoundName.empty, in, DimensionBinding.nullBinding);
variants.add(new DimensionBindingForPath(DimensionBinding.nullBinding, CompoundName.empty)); // if this contains no variants
if (log.isLoggable(Level.FINE))
log.fine("Compiling " + in.toString() + " having " + variants.size() + " variants");
@@ -67,41 +66,68 @@ public class QueryProfileCompiler {
*
* @param profile the profile we are collecting the variants of
* @param currentVariant the variant we must have to arrive at this point in the query profile graph
- * @param allVariants the set of all variants accumulated so far
*/
- private static void collectVariants(CompoundName path, QueryProfile profile, DimensionBinding currentVariant, Set<DimensionBindingForPath> allVariants) {
+ private static Set<DimensionBindingForPath> collectVariants(CompoundName path, QueryProfile profile, DimensionBinding currentVariant) {
+ Set<DimensionBindingForPath> variants = new HashSet<>();
+ variants.addAll(collectVariantsFromValues(path, profile.getContent(), currentVariant));
+ variants.addAll(collectVariantsInThis(path, profile, currentVariant));
+ if (profile instanceof BackedOverridableQueryProfile)
+ variants.addAll(collectVariantsInThis(path, ((BackedOverridableQueryProfile) profile).getBacking(), currentVariant));
+
+ Set<DimensionBindingForPath> parentVariants = new HashSet<>();
for (QueryProfile inheritedProfile : profile.inherited())
- collectVariants(path, inheritedProfile, currentVariant, allVariants);
+ parentVariants = collectVariants(path, inheritedProfile, currentVariant);
+ variants.addAll(parentVariants);
+ variants.addAll(combined(variants, parentVariants)); // parents and children may have different variant dimensions
+ return variants;
+ }
- collectVariantsFromValues(path, profile.getContent(), currentVariant, allVariants);
+ /** Generates a set of all the (legal) combinations of the variants in the given sets */
+ private static Set<DimensionBindingForPath> combined(Set<DimensionBindingForPath> v1s,
+ Set<DimensionBindingForPath> v2s) {
+ Set<DimensionBindingForPath> combinedVariants = new HashSet<>();
+ for (DimensionBindingForPath v1 : v1s) {
+ for (DimensionBindingForPath v2 : v2s) {
+ if ( ! v1.path().equals(v2.path())) continue;
- collectVariantsInThis(path, profile, currentVariant, allVariants);
- if (profile instanceof BackedOverridableQueryProfile)
- collectVariantsInThis(path, ((BackedOverridableQueryProfile) profile).getBacking(), currentVariant, allVariants);
+ DimensionBinding combined = v1.binding().combineWith(v2.binding);
+ if ( combined.isInvalid() ) continue;
+
+ combinedVariants.add(new DimensionBindingForPath(combined, v1.path()));
+ }
+ }
+ return combinedVariants;
}
- private static void collectVariantsInThis(CompoundName path, QueryProfile profile, DimensionBinding currentVariant, Set<DimensionBindingForPath> allVariants) {
+ private static Set<DimensionBindingForPath> collectVariantsInThis(CompoundName path, QueryProfile profile, DimensionBinding currentVariant) {
QueryProfileVariants profileVariants = profile.getVariants();
+ Set<DimensionBindingForPath> variants = new HashSet<>();
if (profileVariants != null) {
for (QueryProfileVariant variant : profile.getVariants().getVariants()) {
DimensionBinding combinedVariant =
DimensionBinding.createFrom(profile.getDimensions(), variant.getDimensionValues()).combineWith(currentVariant);
if (combinedVariant.isInvalid()) continue; // values at this point in the graph are unreachable
- collectVariantsFromValues(path, variant.values(), combinedVariant, allVariants);
+
+ variants.addAll(collectVariantsFromValues(path, variant.values(), combinedVariant));
for (QueryProfile variantInheritedProfile : variant.inherited())
- collectVariants(path, variantInheritedProfile, combinedVariant, allVariants);
+ variants.addAll(collectVariants(path, variantInheritedProfile, combinedVariant));
}
}
+ return variants;
}
- private static void collectVariantsFromValues(CompoundName path, Map<String, Object> values, DimensionBinding currentVariant, Set<DimensionBindingForPath> allVariants) {
+ private static Set<DimensionBindingForPath> collectVariantsFromValues(CompoundName path,
+ Map<String, Object> values,
+ DimensionBinding currentVariant) {
+ Set<DimensionBindingForPath> variants = new HashSet<>();
if ( ! values.isEmpty())
- allVariants.add(new DimensionBindingForPath(currentVariant, path)); // there are actual values for this variant
+ variants.add(new DimensionBindingForPath(currentVariant, path)); // there are actual values for this variant
for (Map.Entry<String, Object> entry : values.entrySet()) {
if (entry.getValue() instanceof QueryProfile)
- collectVariants(path.append(entry.getKey()), (QueryProfile)entry.getValue(), currentVariant, allVariants);
+ variants.addAll(collectVariants(path.append(entry.getKey()), (QueryProfile)entry.getValue(), currentVariant));
}
+ return variants;
}
private static class DimensionBindingForPath {