use of com.yahoo.search.query.profile.DimensionValues in project vespa by vespa-engine.
the class QueryProfileXMLReader method readVariants.
private void readVariants(Element element, QueryProfile profile, QueryProfileRegistry registry) {
for (Element queryProfileVariantElement : XML.getChildren(element, "query-profile")) {
// A "virtual" query profile contained inside another
List<String> dimensions = profile.getDimensions();
if (dimensions == null)
throw new IllegalArgumentException("Cannot create a query profile variant in " + profile + ", as it has not declared any variable dimensions");
String dimensionString = queryProfileVariantElement.getAttribute("for");
String[] dimensionValueArray = makeStarsNull(toArray(dimensionString));
if (dimensions.size() < dimensionValueArray.length)
throw new IllegalArgumentException("Cannot create a query profile variant for '" + dimensionString + "' as only " + dimensions.size() + " dimensions has been defined");
DimensionValues dimensionValues = DimensionValues.createFrom(dimensionValueArray);
String description = "variant '" + dimensionString + "' in " + profile.toString();
readInherited(queryProfileVariantElement, profile, registry, dimensionValues, description);
readFields(queryProfileVariantElement, profile, registry, dimensionValues, description);
}
}
use of com.yahoo.search.query.profile.DimensionValues in project vespa by vespa-engine.
the class QueryProfileConfigurer method fillProfile.
private static void fillProfile(QueryProfilesConfig.Queryprofile config, QueryProfilesConfig queryProfilesConfig, QueryProfileRegistry registry, Set<ComponentId> filled) {
QueryProfile profile = registry.getComponent(new ComponentSpecification(config.id()).toId());
if (filled.contains(profile.getId()))
return;
filled.add(profile.getId());
try {
for (String inheritedId : config.inherit()) {
QueryProfile inherited = registry.getComponent(inheritedId);
if (inherited == null)
throw new IllegalArgumentException("Inherited query profile '" + inheritedId + "' in " + profile + " was not found");
fillProfile(inherited, queryProfilesConfig, registry, filled);
profile.addInherited(inherited);
}
for (QueryProfilesConfig.Queryprofile.Reference referenceConfig : config.reference()) {
QueryProfile referenced = registry.getComponent(referenceConfig.value());
if (referenced == null)
throw new IllegalArgumentException("Query profile '" + referenceConfig.value() + "' referenced as '" + referenceConfig.name() + "' in " + profile + " was not found");
profile.set(referenceConfig.name(), referenced, registry);
if (referenceConfig.overridable() != null && !referenceConfig.overridable().isEmpty())
profile.setOverridable(referenceConfig.name(), BooleanParser.parseBoolean(referenceConfig.overridable()), null);
}
for (QueryProfilesConfig.Queryprofile.Property propertyConfig : config.property()) {
profile.set(propertyConfig.name(), propertyConfig.value(), registry);
if (propertyConfig.overridable() != null && !propertyConfig.overridable().isEmpty())
profile.setOverridable(propertyConfig.name(), BooleanParser.parseBoolean(propertyConfig.overridable()), null);
}
for (QueryProfilesConfig.Queryprofile.Queryprofilevariant variantConfig : config.queryprofilevariant()) {
String[] forDimensionValueArray = new String[variantConfig.fordimensionvalues().size()];
for (int i = 0; i < variantConfig.fordimensionvalues().size(); i++) {
forDimensionValueArray[i] = variantConfig.fordimensionvalues().get(i).trim();
if ("*".equals(forDimensionValueArray[i]))
forDimensionValueArray[i] = null;
}
DimensionValues forDimensionValues = DimensionValues.createFrom(forDimensionValueArray);
for (String inheritedId : variantConfig.inherit()) {
QueryProfile inherited = registry.getComponent(inheritedId);
if (inherited == null)
throw new IllegalArgumentException("Inherited query profile '" + inheritedId + "' in " + profile + " for '" + forDimensionValues + "' was not found");
fillProfile(inherited, queryProfilesConfig, registry, filled);
profile.addInherited(inherited, forDimensionValues);
}
for (QueryProfilesConfig.Queryprofile.Queryprofilevariant.Reference referenceConfig : variantConfig.reference()) {
QueryProfile referenced = registry.getComponent(referenceConfig.value());
if (referenced == null)
throw new IllegalArgumentException("Query profile '" + referenceConfig.value() + "' referenced as '" + referenceConfig.name() + "' in " + profile + " for '" + forDimensionValues + "' was not found");
profile.set(referenceConfig.name(), referenced, forDimensionValues, registry);
}
for (QueryProfilesConfig.Queryprofile.Queryprofilevariant.Property propertyConfig : variantConfig.property()) {
profile.set(propertyConfig.name(), propertyConfig.value(), forDimensionValues, registry);
}
}
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Invalid " + profile, e);
}
}
use of com.yahoo.search.query.profile.DimensionValues in project vespa by vespa-engine.
the class QueryProfileVariantsCloneTestCase method test_that_interior_and_leaf_values_on_a_path_are_preserved_when_cloning.
/**
* Test for Ticket 4882480.
*/
@Test
public void test_that_interior_and_leaf_values_on_a_path_are_preserved_when_cloning() {
Map<String, String> dimensionBinding = createDimensionBinding("location", "norway");
QueryProfile profile = new QueryProfile("profile");
profile.setDimensions(keys(dimensionBinding));
DimensionValues dimensionValues = DimensionValues.createFrom(values(dimensionBinding));
profile.set("interior.leaf", "leafValue", dimensionValues, null);
profile.set("interior", "interiorValue", dimensionValues, null);
CompiledQueryProfile clone = profile.compile(null).clone();
assertEquals(profile.get("interior", dimensionBinding, null), clone.get("interior", dimensionBinding));
assertEquals(profile.get("interior.leaf", dimensionBinding, null), clone.get("interior.leaf", dimensionBinding));
}
Aggregations