Search in sources :

Example 86 with QueryProfile

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"));
    }
}
Also used : QueryProfile(com.yahoo.search.query.profile.QueryProfile) Query(com.yahoo.search.Query) Test(org.junit.Test)

Example 87 with QueryProfile

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);
            }
        }
    }
}
Also used : OverridableQueryProfile(com.yahoo.search.query.profile.OverridableQueryProfile) QueryProfile(com.yahoo.search.query.profile.QueryProfile) OverridableQueryProfile(com.yahoo.search.query.profile.OverridableQueryProfile) QueryProfileVariants(com.yahoo.search.query.profile.QueryProfileVariants)

Example 88 with QueryProfile

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);
    }
}
Also used : QueryProfile(com.yahoo.search.query.profile.QueryProfile)

Example 89 with QueryProfile

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()));
    }
}
Also used : QueryProfile(com.yahoo.search.query.profile.QueryProfile) BackedOverridableQueryProfile(com.yahoo.search.query.profile.BackedOverridableQueryProfile) QueryProfilesConfig(com.yahoo.search.query.profile.config.QueryProfilesConfig) SubstituteString(com.yahoo.search.query.profile.SubstituteString)

Example 90 with QueryProfile

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()));
    }
}
Also used : QueryProfile(com.yahoo.search.query.profile.QueryProfile) BackedOverridableQueryProfile(com.yahoo.search.query.profile.BackedOverridableQueryProfile) QueryProfilesConfig(com.yahoo.search.query.profile.config.QueryProfilesConfig) SubstituteString(com.yahoo.search.query.profile.SubstituteString)

Aggregations

QueryProfile (com.yahoo.search.query.profile.QueryProfile)161 CompiledQueryProfile (com.yahoo.search.query.profile.compiled.CompiledQueryProfile)92 Query (com.yahoo.search.Query)63 BackedOverridableQueryProfile (com.yahoo.search.query.profile.BackedOverridableQueryProfile)35 CompiledQueryProfileRegistry (com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry)28 Test (org.junit.Test)26 QueryProfileRegistry (com.yahoo.search.query.profile.QueryProfileRegistry)24 QueryProfileProperties (com.yahoo.search.query.profile.QueryProfileProperties)21 QueryProfileType (com.yahoo.search.query.profile.types.QueryProfileType)12 Properties (com.yahoo.search.query.Properties)8 FieldDescription (com.yahoo.search.query.profile.types.FieldDescription)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)5 SubstituteString (com.yahoo.search.query.profile.SubstituteString)4 QueryProfilesConfig (com.yahoo.search.query.profile.config.QueryProfilesConfig)4 Element (org.w3c.dom.Element)4 QueryException (com.yahoo.prelude.query.QueryException)3 Properties (com.yahoo.processing.request.Properties)3 QueryProfileXMLReader (com.yahoo.search.query.profile.config.QueryProfileXMLReader)3 QueryProfiles (com.yahoo.vespa.model.container.search.QueryProfiles)3 ComponentSpecification (com.yahoo.component.ComponentSpecification)2