Search in sources :

Example 6 with QueryProfileType

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

the class QueryProfileXMLReader method readInheritedTypes.

private void readInheritedTypes(Element element, QueryProfileType type, QueryProfileTypeRegistry registry) {
    String inheritedString = element.getAttribute("inherits");
    if (inheritedString == null || inheritedString.equals(""))
        return;
    for (String inheritedId : inheritedString.split(" ")) {
        inheritedId = inheritedId.trim();
        if (inheritedId.equals(""))
            continue;
        QueryProfileType inheritedType = registry.getComponent(inheritedId);
        if (inheritedType == null)
            throw new IllegalArgumentException("Could not resolve inherited query profile type '" + inheritedId);
        type.inherited().add(inheritedType);
    }
}
Also used : QueryProfileType(com.yahoo.search.query.profile.types.QueryProfileType)

Example 7 with QueryProfileType

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

the class QueryProfileXMLReader method fillQueryProfileTypes.

public void fillQueryProfileTypes(List<Element> queryProfileTypeElements, QueryProfileTypeRegistry registry) {
    for (Element element : queryProfileTypeElements) {
        QueryProfileType type = registry.getComponent(new ComponentSpecification(element.getAttribute("id")).toId());
        try {
            readInheritedTypes(element, type, registry);
            readFieldDefinitions(element, type, registry);
        } catch (RuntimeException e) {
            throw new IllegalArgumentException("Error reading " + type, e);
        }
    }
}
Also used : ComponentSpecification(com.yahoo.component.ComponentSpecification) Element(org.w3c.dom.Element) QueryProfileType(com.yahoo.search.query.profile.types.QueryProfileType)

Example 8 with QueryProfileType

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

the class QueryProfileXMLReader method createQueryProfiles.

public List<Element> createQueryProfiles(List<NamedReader> queryProfileReaders, QueryProfileRegistry registry) {
    List<Element> queryProfileElements = new ArrayList<>(queryProfileReaders.size());
    for (NamedReader reader : queryProfileReaders) {
        Element root = XML.getDocument(reader).getDocumentElement();
        if (!root.getNodeName().equals("query-profile")) {
            throw new IllegalArgumentException("Root tag in '" + reader.getName() + "' must be 'query-profile', not '" + root.getNodeName() + "'");
        }
        String idString = root.getAttribute("id");
        if (idString == null || idString.equals(""))
            throw new IllegalArgumentException("Query profile '" + reader.getName() + "' has no 'id' attribute in the root element");
        ComponentId id = new ComponentId(idString);
        validateFileNameToId(reader.getName(), id, "query profile");
        QueryProfile queryProfile = new QueryProfile(id);
        String typeId = root.getAttribute("type");
        if (typeId != null && !typeId.equals("")) {
            QueryProfileType type = registry.getType(typeId);
            if (type == null)
                throw new IllegalArgumentException("Query profile '" + reader.getName() + "': Type id '" + typeId + "' can not be resolved");
            queryProfile.setType(type);
        }
        Element dimensions = XML.getChild(root, "dimensions");
        if (dimensions != null)
            queryProfile.setDimensions(toArray(XML.getValue(dimensions)));
        registry.register(queryProfile);
        queryProfileElements.add(root);
    }
    return queryProfileElements;
}
Also used : QueryProfile(com.yahoo.search.query.profile.QueryProfile) 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 9 with QueryProfileType

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

the class QueryProfileProperties method unalias.

CompoundName unalias(CompoundName name, Map<String, String> context) {
    if (profile.getTypes().isEmpty())
        return name;
    CompoundName unaliasedName = name;
    for (int i = 0; i < name.size(); i++) {
        QueryProfileType type = profile.getType(name.first(i), context);
        if (type == null)
            continue;
        // TODO: Make never null
        if (type.aliases() == null)
            continue;
        if (type.aliases().isEmpty())
            continue;
        String localName = name.get(i);
        String unaliasedLocalName = type.unalias(localName);
        unaliasedName = unaliasedName.set(i, unaliasedLocalName);
    }
    return unaliasedName;
}
Also used : CompoundName(com.yahoo.processing.request.CompoundName) QueryProfileType(com.yahoo.search.query.profile.types.QueryProfileType)

Example 10 with QueryProfileType

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

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