Search in sources :

Example 11 with FieldDescription

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

the class QueryProfileProperties method set.

/**
 * Sets a value in this query profile
 *
 * @throws IllegalArgumentException if this property cannot be set in the wrapped query profile
 */
@Override
public void set(CompoundName name, Object value, Map<String, String> context) {
    // TODO: Refactor
    try {
        name = unalias(name, context);
        if (context == null)
            context = Collections.emptyMap();
        if (!profile.isOverridable(name, context))
            return;
        // Check runtime references
        Pair<CompoundName, CompiledQueryProfile> runtimeReference = findReference(name);
        if (runtimeReference != null && !runtimeReference.getSecond().isOverridable(name.rest(runtimeReference.getFirst().size()), context))
            return;
        // Check types
        if (!profile.getTypes().isEmpty()) {
            for (int i = 0; i < name.size(); i++) {
                QueryProfileType type = profile.getType(name.first(i), context);
                if (type == null)
                    continue;
                String localName = name.get(i);
                FieldDescription fieldDescription = type.getField(localName);
                if (fieldDescription == null && type.isStrict())
                    throw new IllegalArgumentException("'" + localName + "' is not declared in " + type + ", and the type is strict");
                if (i == name.size() - 1 && fieldDescription != null) {
                    // at the end of the path, check the assignment type
                    value = fieldDescription.getType().convertFrom(value, profile.getRegistry());
                    if (value == null)
                        throw new IllegalArgumentException("'" + value + "' is not a " + fieldDescription.getType().toInstanceDescription());
                }
            }
        }
        if (value instanceof String && value.toString().startsWith("ref:")) {
            if (profile.getRegistry() == null)
                throw new IllegalArgumentException("Runtime query profile references does not work when the " + "QueryProfileProperties are constructed without a registry");
            String queryProfileId = value.toString().substring(4);
            value = profile.getRegistry().findQueryProfile(queryProfileId);
            if (value == null)
                throw new IllegalArgumentException("Query profile '" + queryProfileId + "' is not found");
        }
        if (value instanceof CompiledQueryProfile) {
            // this will be due to one of the two clauses above
            if (references == null)
                references = new ArrayList<>();
            // references set later has precedence - put first
            references.add(0, new Pair<>(name, (CompiledQueryProfile) value));
        } else {
            if (values == null)
                values = new HashMap<>();
            values.put(name, value);
        }
    } catch (IllegalArgumentException e) {
        // TODO: Nest instead
        throw new IllegalArgumentException("Could not set '" + name + "' to '" + value + "': " + e.getMessage());
    }
}
Also used : CompoundName(com.yahoo.processing.request.CompoundName) CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) QueryProfileType(com.yahoo.search.query.profile.types.QueryProfileType) FieldDescription(com.yahoo.search.query.profile.types.FieldDescription)

Example 12 with FieldDescription

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

the class RankingExpressionShadowingTestCase method queryProfileWith.

private QueryProfileRegistry queryProfileWith(String field, String type) {
    QueryProfileType queryProfileType = new QueryProfileType("root");
    queryProfileType.addField(new FieldDescription(field, type));
    QueryProfileRegistry queryProfileRegistry = new QueryProfileRegistry();
    queryProfileRegistry.getTypeRegistry().register(queryProfileType);
    QueryProfile profile = new QueryProfile("default");
    profile.setType(queryProfileType);
    queryProfileRegistry.register(profile);
    return queryProfileRegistry;
}
Also used : QueryProfile(com.yahoo.search.query.profile.QueryProfile) QueryProfileRegistry(com.yahoo.search.query.profile.QueryProfileRegistry) QueryProfileType(com.yahoo.search.query.profile.types.QueryProfileType) FieldDescription(com.yahoo.search.query.profile.types.FieldDescription)

Example 13 with FieldDescription

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

the class OverrideTestCase method addTypeFields.

private void addTypeFields(QueryProfileType type) {
    boolean overridable = true;
    type.addField(new FieldDescription("myString", FieldType.fromString("string", registry), false, !overridable));
    type.addField(new FieldDescription("myInteger", FieldType.fromString("integer", registry)));
    type.addField(new FieldDescription("myLong", FieldType.fromString("long", registry)));
    type.addField(new FieldDescription("myFloat", FieldType.fromString("float", registry)));
    type.addField(new FieldDescription("myDouble", FieldType.fromString("double", registry)));
    type.addField(new FieldDescription("myQueryProfile", FieldType.fromString("query-profile", registry)));
    type.addField(new FieldDescription("myUserQueryProfile", FieldType.fromString("query-profile:user", registry), false, !overridable));
}
Also used : FieldDescription(com.yahoo.search.query.profile.types.FieldDescription)

Example 14 with FieldDescription

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

the class QueryProfileTypeInheritanceTestCase method setUp.

@Override
protected void setUp() {
    type = new QueryProfileType(new ComponentId("testtype"));
    typeStrict = new QueryProfileType(new ComponentId("testtypeStrict"));
    typeStrict.setStrict(true);
    user = new QueryProfileType(new ComponentId("user"));
    userStrict = new QueryProfileType(new ComponentId("userStrict"));
    userStrict.setStrict(true);
    registry = new QueryProfileTypeRegistry();
    registry.register(type);
    registry.register(typeStrict);
    registry.register(user);
    registry.register(userStrict);
    addTypeFields(type);
    type.addField(new FieldDescription("myUserQueryProfile", FieldType.fromString("query-profile:user", registry)));
    addTypeFields(typeStrict);
    typeStrict.addField(new FieldDescription("myUserQueryProfile", FieldType.fromString("query-profile:userStrict", registry)));
    addUserFields(user);
    addUserFields(userStrict);
}
Also used : QueryProfileTypeRegistry(com.yahoo.search.query.profile.types.QueryProfileTypeRegistry) QueryProfileType(com.yahoo.search.query.profile.types.QueryProfileType) ComponentId(com.yahoo.component.ComponentId) FieldDescription(com.yahoo.search.query.profile.types.FieldDescription)

Example 15 with FieldDescription

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

the class QueryProfileTypeInheritanceTestCase method addTypeFields.

private void addTypeFields(QueryProfileType type) {
    type.addField(new FieldDescription("myString", FieldType.fromString("string", registry)));
    type.addField(new FieldDescription("myInteger", FieldType.fromString("integer", registry)));
    type.addField(new FieldDescription("myLong", FieldType.fromString("long", registry)));
    type.addField(new FieldDescription("myFloat", FieldType.fromString("float", registry)));
    type.addField(new FieldDescription("myDouble", FieldType.fromString("double", registry)));
    type.addField(new FieldDescription("myQueryProfile", FieldType.fromString("query-profile", registry)));
}
Also used : FieldDescription(com.yahoo.search.query.profile.types.FieldDescription)

Aggregations

FieldDescription (com.yahoo.search.query.profile.types.FieldDescription)22 QueryProfileType (com.yahoo.search.query.profile.types.QueryProfileType)11 QueryProfileRegistry (com.yahoo.search.query.profile.QueryProfileRegistry)7 QueryProfile (com.yahoo.search.query.profile.QueryProfile)5 QueryProfileTypeRegistry (com.yahoo.search.query.profile.types.QueryProfileTypeRegistry)5 ComponentId (com.yahoo.component.ComponentId)4 CompiledQueryProfileRegistry (com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry)3 CompoundName (com.yahoo.processing.request.CompoundName)2 CompiledQueryProfile (com.yahoo.search.query.profile.compiled.CompiledQueryProfile)2 FieldType (com.yahoo.search.query.profile.types.FieldType)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 HttpRequest (com.yahoo.container.jdisc.HttpRequest)1 Query (com.yahoo.search.Query)1 QueryProfileConfigurer (com.yahoo.search.query.profile.config.QueryProfileConfigurer)1 QueryProfileXMLReader (com.yahoo.search.query.profile.config.QueryProfileXMLReader)1 QueryProfilesConfig (com.yahoo.search.query.profile.config.QueryProfilesConfig)1 QueryProfileFieldType (com.yahoo.search.query.profile.types.QueryProfileFieldType)1 Reference (com.yahoo.searchlib.rankingexpression.Reference)1 TensorType (com.yahoo.tensor.TensorType)1