Search in sources :

Example 1 with DimensionValues

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);
    }
}
Also used : DimensionValues(com.yahoo.search.query.profile.DimensionValues) Element(org.w3c.dom.Element)

Example 2 with DimensionValues

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

Example 3 with DimensionValues

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

Aggregations

DimensionValues (com.yahoo.search.query.profile.DimensionValues)3 QueryProfile (com.yahoo.search.query.profile.QueryProfile)2 ComponentSpecification (com.yahoo.component.ComponentSpecification)1 CompiledQueryProfile (com.yahoo.search.query.profile.compiled.CompiledQueryProfile)1 Test (org.junit.Test)1 Element (org.w3c.dom.Element)1