use of com.yahoo.search.query.profile.QueryProfile in project vespa by vespa-engine.
the class QueryTestCase method testNonleafInRequestDoesNotOverrideProfile.
@Test
public void testNonleafInRequestDoesNotOverrideProfile() {
QueryProfile testProfile = new QueryProfile("test");
testProfile.set("a.b", "foo", (QueryProfileRegistry) null);
testProfile.freeze();
{
Query q = new Query("?", testProfile.compile(null));
assertEquals("foo", q.properties().get("a.b"));
}
{
Query q = new Query("?a=bar", testProfile.compile(null));
assertEquals("bar", q.properties().get("a"));
assertEquals("foo", q.properties().get("a.b"));
}
}
use of com.yahoo.search.query.profile.QueryProfile in project vespa by vespa-engine.
the class DeclaredQueryProfileVariants method dereferenceCompoundedVariants.
private void dereferenceCompoundedVariants(QueryProfile profile, String prefix) {
// having the variants
for (Map.Entry<String, Object> entry : profile.declaredContent().entrySet()) {
if (!(entry.getValue() instanceof QueryProfile))
continue;
QueryProfile subProfile = (QueryProfile) entry.getValue();
// Export if defined implicitly in this, or if this contains overrides
if (!subProfile.isExplicit() || subProfile instanceof OverridableQueryProfile) {
String entryPrefix = prefix + entry.getKey() + ".";
dereferenceCompoundedVariants(subProfile.getVariants(), entryPrefix);
dereferenceCompoundedVariants(subProfile, entryPrefix);
}
}
if (profile.getVariants() == null)
return;
// We need to do the same dereferencing to overridables pointed to by variants of this
for (Map.Entry<String, QueryProfileVariants.FieldValues> fieldValueEntry : profile.getVariants().getFieldValues().entrySet()) {
for (QueryProfileVariants.FieldValue fieldValue : fieldValueEntry.getValue().asList()) {
if (!(fieldValue.getValue() instanceof QueryProfile))
continue;
QueryProfile subProfile = (QueryProfile) fieldValue.getValue();
// Export if defined implicitly in this, or if this contains overrides
if (!subProfile.isExplicit() || subProfile instanceof OverridableQueryProfile) {
String entryPrefix = prefix + fieldValueEntry.getKey() + ".";
dereferenceCompoundedVariants(subProfile.getVariants(), entryPrefix);
dereferenceCompoundedVariants(subProfile, entryPrefix);
}
}
}
}
use of com.yahoo.search.query.profile.QueryProfile in project vespa by vespa-engine.
the class QueryProfileConfigurer method createProfile.
private static void createProfile(QueryProfilesConfig.Queryprofile config, QueryProfileRegistry registry) {
QueryProfile profile = new QueryProfile(config.id());
try {
String typeId = config.type();
if (typeId != null && !typeId.isEmpty())
profile.setType(registry.getType(typeId));
if (config.dimensions().size() > 0) {
String[] dimensions = new String[config.dimensions().size()];
for (int i = 0; i < config.dimensions().size(); i++) dimensions[i] = config.dimensions().get(i);
profile.setDimensions(dimensions);
}
registry.register(profile);
} 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 QueryProfiles method addField.
private void addField(QueryProfilesConfig.Queryprofile.Builder qpB, QueryProfile profile, Entry<String, Object> field, String namePrefix) {
String fullName = namePrefix + field.getKey();
if (field.getValue() instanceof QueryProfile) {
QueryProfile subProfile = (QueryProfile) field.getValue();
if (!subProfile.isExplicit()) {
// Implicitly defined profile - add content
addFieldChildren(qpB, subProfile, fullName + ".");
} else {
// Reference to an id'ed profile - output reference plus any local overrides
QueryProfilesConfig.Queryprofile.Reference.Builder refB = new QueryProfilesConfig.Queryprofile.Reference.Builder();
createReferenceFieldConfig(refB, profile, fullName, field.getKey(), ((BackedOverridableQueryProfile) subProfile).getBacking().getId().stringValue());
qpB.reference(refB);
addFieldChildren(qpB, subProfile, fullName + ".");
}
} else {
// a primitive
qpB.property(createPropertyFieldConfig(profile, fullName, field.getKey(), field.getValue()));
}
}
use of com.yahoo.search.query.profile.QueryProfile in project vespa by vespa-engine.
the class QueryProfiles method addVariantField.
private void addVariantField(QueryProfilesConfig.Queryprofile.Queryprofilevariant.Builder qpB, Entry<String, Object> field, String namePrefix) {
String fullName = namePrefix + field.getKey();
if (field.getValue() instanceof QueryProfile) {
QueryProfile subProfile = (QueryProfile) field.getValue();
if (!subProfile.isExplicit()) {
// Implicitly defined profile - add content
addVariantFieldChildren(qpB, subProfile, fullName + ".");
} else {
// Reference to an id'ed profile - output reference plus any local overrides
QueryProfilesConfig.Queryprofile.Queryprofilevariant.Reference.Builder refB = new QueryProfilesConfig.Queryprofile.Queryprofilevariant.Reference.Builder();
createVariantReferenceFieldConfig(refB, fullName, ((BackedOverridableQueryProfile) subProfile).getBacking().getId().stringValue());
qpB.reference(refB);
addVariantFieldChildren(qpB, subProfile, fullName + ".");
}
} else {
// a primitive
qpB.property(createVariantPropertyFieldConfig(fullName, field.getValue()));
}
}
Aggregations