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;
}
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;
}
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;
}
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);
}
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;
}
Aggregations