Search in sources :

Example 11 with QueryProfile

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

Example 12 with QueryProfile

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

Example 13 with QueryProfile

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());
}
Also used : QueryProfile(com.yahoo.search.query.profile.QueryProfile) CompiledQueryProfileRegistry(com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry) Query(com.yahoo.search.Query) CompiledQueryProfileRegistry(com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry) QueryProfileRegistry(com.yahoo.search.query.profile.QueryProfileRegistry) QueryProfileType(com.yahoo.search.query.profile.types.QueryProfileType)

Example 14 with QueryProfile

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());
}
Also used : QueryProfile(com.yahoo.search.query.profile.QueryProfile) CompiledQueryProfileRegistry(com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry) Query(com.yahoo.search.Query) CompiledQueryProfileRegistry(com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry) QueryProfileRegistry(com.yahoo.search.query.profile.QueryProfileRegistry) QueryProfileType(com.yahoo.search.query.profile.types.QueryProfileType)

Example 15 with QueryProfile

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

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