use of com.yahoo.search.query.profile.QueryProfile in project vespa by vespa-engine.
the class QueryProfileXMLReader method readFieldValue.
private Object readFieldValue(Element field, String name, String targetDescription, QueryProfileRegistry registry) {
Element ref = XML.getChild(field, "ref");
if (ref != null) {
String referencedName = XML.getValue(ref);
QueryProfile referenced = registry.getComponent(referencedName);
if (referenced == null)
throw new IllegalArgumentException("Could not find query profile '" + referencedName + "' referenced as '" + name + "' in " + targetDescription);
return referenced;
} else {
return XML.getValue(field);
}
}
use of com.yahoo.search.query.profile.QueryProfile 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.QueryProfile in project vespa by vespa-engine.
the class QueryFromProfileTestCase method testQueryFromProfile3.
public void testQueryFromProfile3() {
QueryProfileRegistry registry = new QueryProfileRegistry();
QueryProfileType rootType = new QueryProfileType("root");
rootType.inherited().add(registry.getTypeRegistry().getComponent("native"));
registry.getTypeRegistry().register(rootType);
QueryProfile root = new QueryProfile("root");
root.setType(rootType);
registry.register(root);
QueryProfile queryBest = new QueryProfile("querybest");
queryBest.setType(registry.getTypeRegistry().getComponent("model"));
queryBest.set("queryString", "best", registry);
registry.register(queryBest);
CompiledQueryProfileRegistry cRegistry = registry.compile();
Query query = new Query(HttpRequest.createTestRequest("?query=overrides&model=querybest", Method.GET), cRegistry.getComponent("root"));
assertEquals("overrides", query.properties().get("model.queryString"));
assertEquals("overrides", query.getModel().getQueryTree().toString());
}
use of com.yahoo.search.query.profile.QueryProfile in project vespa by vespa-engine.
the class QueryFromProfileTestCase method testQueryFromProfile2.
public void testQueryFromProfile2() {
QueryProfileRegistry registry = new QueryProfileRegistry();
QueryProfileType rootType = new QueryProfileType("root");
rootType.inherited().add(registry.getTypeRegistry().getComponent("native"));
registry.getTypeRegistry().register(rootType);
QueryProfile root = new QueryProfile("root");
root.setType(rootType);
registry.register(root);
QueryProfile queryBest = new QueryProfile("querybest");
queryBest.setType(registry.getTypeRegistry().getComponent("model"));
queryBest.set("queryString", "best", registry);
registry.register(queryBest);
CompiledQueryProfileRegistry cRegistry = registry.compile();
Query query = new Query(HttpRequest.createTestRequest("?query=overrides&model=querybest", Method.GET), cRegistry.getComponent("root"));
assertEquals("overrides", query.properties().get("model.queryString"));
assertEquals("overrides", query.getModel().getQueryTree().toString());
}
use of com.yahoo.search.query.profile.QueryProfile in project vespa by vespa-engine.
the class QueryProfileGetInComplexStructureMicroBenchmark method createParent.
private QueryProfile createParent(int i) {
QueryProfile main = new QueryProfile("parent" + i);
main.setDimensions(new String[] { "d0" });
String prefix = generatePrefix();
for (int j = 0; j < variantCount; j++) main.set(prefix + "a", "value-" + j + "-inherit" + i, new String[] { "dv" + j }, null);
main.freeze();
return main;
}
Aggregations