Search in sources :

Example 1 with QueryProfile

use of com.yahoo.search.query.profile.QueryProfile in project vespa by vespa-engine.

the class QueryProfiles method createConfig.

private QueryProfilesConfig.Queryprofile.Builder createConfig(QueryProfile profile) {
    QueryProfilesConfig.Queryprofile.Builder qB = new QueryProfilesConfig.Queryprofile.Builder();
    qB.id(profile.getId().stringValue());
    if (profile.getType() != null)
        qB.type(profile.getType().getId().stringValue());
    for (QueryProfile inherited : profile.inherited()) qB.inherit(inherited.getId().stringValue());
    if (profile.getVariants() != null) {
        for (String dimension : profile.getVariants().getDimensions()) qB.dimensions(dimension);
    }
    addFieldChildren(qB, profile, "");
    addVariants(qB, profile);
    return qB;
}
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 2 with QueryProfile

use of com.yahoo.search.query.profile.QueryProfile in project vespa by vespa-engine.

the class QueryProfiles method addVariants.

private void addVariants(QueryProfilesConfig.Queryprofile.Builder qB, QueryProfile profile) {
    if (profile.getVariants() == null)
        return;
    DeclaredQueryProfileVariants declaredVariants = new DeclaredQueryProfileVariants(profile);
    for (DeclaredQueryProfileVariants.VariantQueryProfile variant : declaredVariants.getVariantQueryProfiles().values()) {
        QueryProfilesConfig.Queryprofile.Queryprofilevariant.Builder varB = new QueryProfilesConfig.Queryprofile.Queryprofilevariant.Builder();
        for (String dimensionValue : variant.getDimensionValues()) {
            if (dimensionValue == null)
                dimensionValue = "*";
            varB.fordimensionvalues(dimensionValue);
        }
        for (QueryProfile inherited : variant.inherited()) varB.inherit(inherited.getId().stringValue());
        List<Map.Entry<String, Object>> content = new ArrayList<>(variant.getValues().entrySet());
        Collections.sort(content, new MapEntryKeyComparator());
        for (Map.Entry<String, Object> value : content) {
            addVariantField(varB, value, "");
        }
        qB.queryprofilevariant(varB);
    }
}
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) Entry(java.util.Map.Entry)

Example 3 with QueryProfile

use of com.yahoo.search.query.profile.QueryProfile in project vespa by vespa-engine.

the class QueryProfileVariantsTestCase method testExplicitReferenceOverride.

/**
 * For comparison with the above
 */
@Test
public void testExplicitReferenceOverride() throws IOException {
    QueryProfileRegistry registry = new QueryProfileRegistry();
    QueryProfile a1 = new QueryProfile("a1");
    a1.set("b", "a1.b", registry);
    QueryProfile profile = new QueryProfile("test");
    profile.set("a", a1, registry);
    profile.set("a.b", "a.b", registry);
    assertEquals("a.b", profile.get("a.b"));
    registry.register(a1);
    registry.register(profile);
    QueryProfiles profiles = new QueryProfiles(registry);
    assertSerializedConfigFileEquals(root + "explicit-reference-override.cfg", profiles.getConfig().toString());
}
Also used : QueryProfile(com.yahoo.search.query.profile.QueryProfile) QueryProfiles(com.yahoo.vespa.model.container.search.QueryProfiles) QueryProfileRegistry(com.yahoo.search.query.profile.QueryProfileRegistry) Test(org.junit.Test)

Example 4 with QueryProfile

use of com.yahoo.search.query.profile.QueryProfile in project vespa by vespa-engine.

the class QueryProfileVariantsTestCase method testVariantsOfExplicitCompoundWithVariantReference.

@Test
public void testVariantsOfExplicitCompoundWithVariantReference() throws IOException {
    QueryProfileRegistry registry = new QueryProfileRegistry();
    QueryProfile a1 = new QueryProfile("a1");
    a1.set("b", "a1.b", registry);
    QueryProfile a2 = new QueryProfile("a2");
    a2.set("b", "a2.b", registry);
    QueryProfile profile = new QueryProfile("test");
    profile.setDimensions(new String[] { "x" });
    profile.set("a", a1, registry);
    profile.set("a", a2, new String[] { "x1" }, registry);
    profile.set("a.b", "a.b.x1", new String[] { "x1" }, registry);
    profile.set("a.b", "a.b.x2", new String[] { "x2" }, registry);
    registry.register(a1);
    registry.register(a2);
    registry.register(profile);
    QueryProfiles profiles = new QueryProfiles(registry);
    assertSerializedConfigFileEquals(root + "variants-of-explicit-compound-with-reference.cfg", profiles.getConfig().toString());
}
Also used : QueryProfile(com.yahoo.search.query.profile.QueryProfile) QueryProfiles(com.yahoo.vespa.model.container.search.QueryProfiles) QueryProfileRegistry(com.yahoo.search.query.profile.QueryProfileRegistry) Test(org.junit.Test)

Example 5 with QueryProfile

use of com.yahoo.search.query.profile.QueryProfile in project vespa by vespa-engine.

the class QueryProfileVariantsTestCase method testVariantsOfExplicitCompound.

@Test
public void testVariantsOfExplicitCompound() throws IOException {
    QueryProfileRegistry registry = new QueryProfileRegistry();
    QueryProfile a1 = new QueryProfile("a1");
    a1.set("b", "a1.b", registry);
    QueryProfile profile = new QueryProfile("test");
    profile.setDimensions(new String[] { "x" });
    profile.set("a", a1, registry);
    profile.set("a.b", "a.b.x1", new String[] { "x1" }, registry);
    profile.set("a.b", "a.b.x2", new String[] { "x2" }, registry);
    registry.register(a1);
    registry.register(profile);
    QueryProfiles profiles = new QueryProfiles(registry);
    assertSerializedConfigFileEquals(root + "variants-of-explicit-compound.cfg", profiles.getConfig().toString());
}
Also used : QueryProfile(com.yahoo.search.query.profile.QueryProfile) QueryProfiles(com.yahoo.vespa.model.container.search.QueryProfiles) QueryProfileRegistry(com.yahoo.search.query.profile.QueryProfileRegistry) Test(org.junit.Test)

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