Search in sources :

Example 1 with QueryProfileType

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

the class RankProfile method typeContext.

/**
 * Creates a context containing the type information of all constants, attributes and query profiles
 * referable from this rank profile.
 */
public TypeContext<Reference> typeContext(QueryProfileRegistry queryProfiles) {
    MapEvaluationTypeContext context = new MapEvaluationTypeContext(getMacros().values().stream().map(Macro::asExpressionFunction).collect(Collectors.toList()));
    // Add small and large constants, respectively
    getConstants().forEach((k, v) -> context.setType(FeatureNames.asConstantFeature(k), v.type()));
    getSearch().getRankingConstants().forEach((k, v) -> context.setType(FeatureNames.asConstantFeature(k), v.getTensorType()));
    // Add attributes
    getSearch().allFields().forEach(field -> addAttributeFeatureTypes(field, context));
    getSearch().allImportedFields().forEach(field -> addAttributeFeatureTypes(field, context));
    // Add query features from rank profile types reached from the "default" profile
    for (QueryProfileType queryProfileType : queryProfiles.getTypeRegistry().allComponents()) {
        for (FieldDescription field : queryProfileType.declaredFields().values()) {
            TensorType type = field.getType().asTensorType();
            Optional<Reference> feature = Reference.simple(field.getName());
            if (!feature.isPresent() || !feature.get().name().equals("query"))
                continue;
            TensorType existingType = context.getType(feature.get());
            if (!Objects.equals(existingType, context.defaultTypeOf(feature.get())))
                type = existingType.dimensionwiseGeneralizationWith(type).orElseThrow(() -> new IllegalArgumentException(queryProfileType + " contains query feature " + feature.get() + " with type " + field.getType().asTensorType() + ", but this is already defined " + "in another query profile with type " + context.getType(feature.get())));
            context.setType(feature.get(), type);
        }
    }
    return context;
}
Also used : Reference(com.yahoo.searchlib.rankingexpression.Reference) QueryProfileType(com.yahoo.search.query.profile.types.QueryProfileType) TensorType(com.yahoo.tensor.TensorType) FieldDescription(com.yahoo.search.query.profile.types.FieldDescription)

Example 2 with QueryProfileType

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

the class QueryProfiles method createConfig.

private QueryProfilesConfig.Queryprofiletype.Builder createConfig(QueryProfileType profileType) {
    QueryProfilesConfig.Queryprofiletype.Builder qtB = new QueryProfilesConfig.Queryprofiletype.Builder();
    qtB.id(profileType.getId().stringValue());
    if (profileType.isDeclaredStrict())
        qtB.strict(true);
    if (profileType.getDeclaredMatchAsPath())
        qtB.matchaspath(true);
    for (QueryProfileType inherited : profileType.inherited()) qtB.inherit(inherited.getId().stringValue());
    List<FieldDescription> fields = new ArrayList<>(profileType.declaredFields().values());
    Collections.sort(fields);
    for (FieldDescription field : fields) qtB.field(createConfig(field));
    return qtB;
}
Also used : QueryProfilesConfig(com.yahoo.search.query.profile.config.QueryProfilesConfig) QueryProfileType(com.yahoo.search.query.profile.types.QueryProfileType) FieldDescription(com.yahoo.search.query.profile.types.FieldDescription)

Example 3 with QueryProfileType

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

the class RankProfileTestCase method setupQueryProfileTypes.

private static QueryProfileRegistry setupQueryProfileTypes() {
    QueryProfileRegistry registry = new QueryProfileRegistry();
    QueryProfileTypeRegistry typeRegistry = registry.getTypeRegistry();
    QueryProfileType type = new QueryProfileType(new ComponentId("testtype"));
    type.addField(new FieldDescription("ranking.features.query(tensor1)", FieldType.fromString("tensor(x[10])", typeRegistry)), typeRegistry);
    type.addField(new FieldDescription("ranking.features.query(tensor2)", FieldType.fromString("tensor(y{})", typeRegistry)), typeRegistry);
    type.addField(new FieldDescription("ranking.features.invalid(tensor3)", FieldType.fromString("tensor(x{})", typeRegistry)), typeRegistry);
    type.addField(new FieldDescription("ranking.features.query(numeric)", FieldType.fromString("integer", typeRegistry)), typeRegistry);
    typeRegistry.register(type);
    return registry;
}
Also used : QueryProfileTypeRegistry(com.yahoo.search.query.profile.types.QueryProfileTypeRegistry) QueryProfileRegistry(com.yahoo.search.query.profile.QueryProfileRegistry) QueryProfileType(com.yahoo.search.query.profile.types.QueryProfileType) ComponentId(com.yahoo.component.ComponentId) FieldDescription(com.yahoo.search.query.profile.types.FieldDescription)

Example 4 with QueryProfileType

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

the class QueryProfilesTestCase method testQueryProfiles.

@Test
public void testQueryProfiles() throws IOException {
    final boolean mandatory = true;
    final boolean overridable = true;
    QueryProfileRegistry registry = new QueryProfileRegistry();
    QueryProfileTypeRegistry typeRegistry = registry.getTypeRegistry();
    QueryProfileType userType = new QueryProfileType("user");
    userType.setStrict(true);
    userType.addField(new FieldDescription("robot", FieldType.fromString("boolean", typeRegistry), "machine automaton", mandatory, !overridable));
    userType.addField(new FieldDescription("ads", FieldType.fromString("string", typeRegistry), mandatory, overridable));
    userType.addField(new FieldDescription("age", FieldType.fromString("integer", typeRegistry), !mandatory, overridable));
    typeRegistry.register(userType);
    QueryProfileType rootType = new QueryProfileType("root");
    QueryProfileType nativeProfile = typeRegistry.getComponent("native");
    assertNotNull(nativeProfile);
    assertTrue(nativeProfile.isBuiltin());
    rootType.inherited().add(nativeProfile);
    rootType.setMatchAsPath(true);
    rootType.addField(new FieldDescription("user", FieldType.fromString("query-profile:user", typeRegistry), mandatory, overridable));
    typeRegistry.register(rootType);
    QueryProfileType marketType = new QueryProfileType("market");
    marketType.inherited().add(rootType);
    marketType.addField(new FieldDescription("market", FieldType.fromString("string", typeRegistry), !mandatory, !overridable));
    typeRegistry.register(marketType);
    QueryProfile defaultProfile = new QueryProfile("default");
    defaultProfile.set("ranking", "production23", registry);
    defaultProfile.set("representation.defaultIndex", "title", registry);
    defaultProfile.setOverridable("representation.defaultIndex", false, null);
    registry.register(defaultProfile);
    QueryProfile test = new QueryProfile("test");
    test.set("tracelevel", 2, registry);
    registry.register(test);
    QueryProfile genericUser = new QueryProfile("genericUser");
    genericUser.setType(userType);
    genericUser.set("robot", false, registry);
    genericUser.set("ads", "all", registry);
    registry.register(genericUser);
    QueryProfile root = new QueryProfile("root");
    root.setType(rootType);
    root.addInherited(defaultProfile);
    root.addInherited(test);
    root.set("hits", 30, registry);
    root.setOverridable("hits", false, null);
    root.set("unique", "category", registry);
    root.set("user", genericUser, registry);
    root.set("defaultage", "7d", registry);
    registry.register(root);
    QueryProfile marketUser = new QueryProfile("marketUser");
    marketUser.setType(userType);
    marketUser.addInherited(genericUser);
    marketUser.set("ads", "none", registry);
    marketUser.set("age", 25, registry);
    registry.register(marketUser);
    QueryProfile market = new QueryProfile("root/market");
    market.setType(marketType);
    market.addInherited(root);
    market.set("hits", 15, registry);
    market.set("user", marketUser, registry);
    market.set("market", "some market", registry);
    market.set("marketHeading", "Market of %{market}", registry);
    registry.register(market);
    QueryProfile untypedUser = new QueryProfile("untypedUser");
    untypedUser.set("robot", false, registry);
    untypedUser.set("robot.type", "continent-class", registry);
    registry.register(untypedUser);
    assertConfig("query-profiles.cfg", registry);
}
Also used : QueryProfile(com.yahoo.search.query.profile.QueryProfile) QueryProfileTypeRegistry(com.yahoo.search.query.profile.types.QueryProfileTypeRegistry) QueryProfileRegistry(com.yahoo.search.query.profile.QueryProfileRegistry) CompiledQueryProfileRegistry(com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry) QueryProfileType(com.yahoo.search.query.profile.types.QueryProfileType) FieldDescription(com.yahoo.search.query.profile.types.FieldDescription) Test(org.junit.Test)

Example 5 with QueryProfileType

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

the class TensorTransformTestCase method setupQueryProfileTypes.

private static QueryProfileRegistry setupQueryProfileTypes() {
    QueryProfileRegistry registry = new QueryProfileRegistry();
    QueryProfileTypeRegistry typeRegistry = registry.getTypeRegistry();
    QueryProfileType type = new QueryProfileType(new ComponentId("testtype"));
    type.addField(new FieldDescription("ranking.features.query(q)", FieldType.fromString("tensor(x{})", typeRegistry)), typeRegistry);
    type.addField(new FieldDescription("ranking.features.query(n)", FieldType.fromString("integer", typeRegistry)), typeRegistry);
    typeRegistry.register(type);
    return registry;
}
Also used : QueryProfileTypeRegistry(com.yahoo.search.query.profile.types.QueryProfileTypeRegistry) QueryProfileRegistry(com.yahoo.search.query.profile.QueryProfileRegistry) QueryProfileType(com.yahoo.search.query.profile.types.QueryProfileType) ComponentId(com.yahoo.component.ComponentId) FieldDescription(com.yahoo.search.query.profile.types.FieldDescription)

Aggregations

QueryProfileType (com.yahoo.search.query.profile.types.QueryProfileType)28 QueryProfileRegistry (com.yahoo.search.query.profile.QueryProfileRegistry)14 QueryProfile (com.yahoo.search.query.profile.QueryProfile)12 FieldDescription (com.yahoo.search.query.profile.types.FieldDescription)11 ComponentId (com.yahoo.component.ComponentId)7 QueryProfileTypeRegistry (com.yahoo.search.query.profile.types.QueryProfileTypeRegistry)7 CompiledQueryProfileRegistry (com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry)5 CompoundName (com.yahoo.processing.request.CompoundName)4 Query (com.yahoo.search.Query)4 CompiledQueryProfile (com.yahoo.search.query.profile.compiled.CompiledQueryProfile)3 ArrayList (java.util.ArrayList)3 Element (org.w3c.dom.Element)3 NamedReader (com.yahoo.io.reader.NamedReader)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 ComponentSpecification (com.yahoo.component.ComponentSpecification)1 HttpRequest (com.yahoo.container.jdisc.HttpRequest)1 QueryException (com.yahoo.prelude.query.QueryException)1 DimensionalMap (com.yahoo.search.query.profile.compiled.DimensionalMap)1 QueryProfileConfigurer (com.yahoo.search.query.profile.config.QueryProfileConfigurer)1