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