Search in sources :

Example 21 with QueryProfileType

use of com.yahoo.search.query.profile.types.QueryProfileType 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 22 with QueryProfileType

use of com.yahoo.search.query.profile.types.QueryProfileType 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 23 with QueryProfileType

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

the class QueryProfileXMLReader method createQueryProfileTypes.

public List<Element> createQueryProfileTypes(List<NamedReader> queryProfileTypeReaders, QueryProfileTypeRegistry registry) {
    List<Element> queryProfileTypeElements = new ArrayList<>(queryProfileTypeReaders.size());
    for (NamedReader reader : queryProfileTypeReaders) {
        Element root = XML.getDocument(reader).getDocumentElement();
        if (!root.getNodeName().equals("query-profile-type")) {
            throw new IllegalArgumentException("Root tag in '" + reader.getName() + "' must be 'query-profile-type', not '" + root.getNodeName() + "'");
        }
        String idString = root.getAttribute("id");
        if (idString == null || idString.equals(""))
            throw new IllegalArgumentException("'" + reader.getName() + "' has no 'id' attribute in the root element");
        ComponentId id = new ComponentId(idString);
        validateFileNameToId(reader.getName(), id, "query profile type");
        QueryProfileType type = new QueryProfileType(id);
        type.setMatchAsPath(XML.getChild(root, "match") != null);
        type.setStrict(XML.getChild(root, "strict") != null);
        registry.register(type);
        queryProfileTypeElements.add(root);
    }
    return queryProfileTypeElements;
}
Also used : Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) NamedReader(com.yahoo.io.reader.NamedReader) QueryProfileType(com.yahoo.search.query.profile.types.QueryProfileType) ComponentId(com.yahoo.component.ComponentId)

Example 24 with QueryProfileType

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

the class OverrideTestCase method setUp.

@Override
protected void setUp() {
    type = new QueryProfileType(new ComponentId("testtype"));
    user = new QueryProfileType(new ComponentId("user"));
    registry = new QueryProfileTypeRegistry();
    registry.register(type);
    registry.register(user);
    addTypeFields(type);
    addUserFields(user);
}
Also used : QueryProfileTypeRegistry(com.yahoo.search.query.profile.types.QueryProfileTypeRegistry) QueryProfileType(com.yahoo.search.query.profile.types.QueryProfileType) ComponentId(com.yahoo.component.ComponentId)

Example 25 with QueryProfileType

use of com.yahoo.search.query.profile.types.QueryProfileType 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)

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