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