use of com.yahoo.search.query.profile.QueryProfile in project vespa by vespa-engine.
the class QueryProfilesTestCase method testQueryProfiles.
@Test
public void testQueryProfiles() throws IOException {
final boolean mandatory = true;
final boolean overridable = true;
QueryProfileRegistry registry = new QueryProfileRegistry();
QueryProfileTypeRegistry typeRegistry = registry.getTypeRegistry();
QueryProfileType userType = new QueryProfileType("user");
userType.setStrict(true);
userType.addField(new FieldDescription("robot", FieldType.fromString("boolean", typeRegistry), "machine automaton", mandatory, !overridable));
userType.addField(new FieldDescription("ads", FieldType.fromString("string", typeRegistry), mandatory, overridable));
userType.addField(new FieldDescription("age", FieldType.fromString("integer", typeRegistry), !mandatory, overridable));
typeRegistry.register(userType);
QueryProfileType rootType = new QueryProfileType("root");
QueryProfileType nativeProfile = typeRegistry.getComponent("native");
assertNotNull(nativeProfile);
assertTrue(nativeProfile.isBuiltin());
rootType.inherited().add(nativeProfile);
rootType.setMatchAsPath(true);
rootType.addField(new FieldDescription("user", FieldType.fromString("query-profile:user", typeRegistry), mandatory, overridable));
typeRegistry.register(rootType);
QueryProfileType marketType = new QueryProfileType("market");
marketType.inherited().add(rootType);
marketType.addField(new FieldDescription("market", FieldType.fromString("string", typeRegistry), !mandatory, !overridable));
typeRegistry.register(marketType);
QueryProfile defaultProfile = new QueryProfile("default");
defaultProfile.set("ranking", "production23", registry);
defaultProfile.set("representation.defaultIndex", "title", registry);
defaultProfile.setOverridable("representation.defaultIndex", false, null);
registry.register(defaultProfile);
QueryProfile test = new QueryProfile("test");
test.set("tracelevel", 2, registry);
registry.register(test);
QueryProfile genericUser = new QueryProfile("genericUser");
genericUser.setType(userType);
genericUser.set("robot", false, registry);
genericUser.set("ads", "all", registry);
registry.register(genericUser);
QueryProfile root = new QueryProfile("root");
root.setType(rootType);
root.addInherited(defaultProfile);
root.addInherited(test);
root.set("hits", 30, registry);
root.setOverridable("hits", false, null);
root.set("unique", "category", registry);
root.set("user", genericUser, registry);
root.set("defaultage", "7d", registry);
registry.register(root);
QueryProfile marketUser = new QueryProfile("marketUser");
marketUser.setType(userType);
marketUser.addInherited(genericUser);
marketUser.set("ads", "none", registry);
marketUser.set("age", 25, registry);
registry.register(marketUser);
QueryProfile market = new QueryProfile("root/market");
market.setType(marketType);
market.addInherited(root);
market.set("hits", 15, registry);
market.set("user", marketUser, registry);
market.set("market", "some market", registry);
market.set("marketHeading", "Market of %{market}", registry);
registry.register(market);
QueryProfile untypedUser = new QueryProfile("untypedUser");
untypedUser.set("robot", false, registry);
untypedUser.set("robot.type", "continent-class", registry);
registry.register(untypedUser);
assertConfig("query-profiles.cfg", registry);
}
use of com.yahoo.search.query.profile.QueryProfile in project vespa by vespa-engine.
the class XmlReadingTestCase method testBasicsWithProfile.
@Test
public void testBasicsWithProfile() {
QueryProfile p = new QueryProfile("default");
p.set("a", "foo", null);
Query q = new Query(HttpRequest.createTestRequest("?query=test", Method.GET), p.compile(null));
assertEquals("test", q.properties().get("query"));
assertEquals("test", q.properties().get("QueRY"));
assertEquals("test", q.properties().get("model.queryString"));
assertEquals("test", q.getModel().getQueryString());
}
use of com.yahoo.search.query.profile.QueryProfile in project vespa by vespa-engine.
the class FederationSearcherTestCase method assertSelects.
private void assertSelects(String providerName, SearchChainRegistry registry) {
QueryProfile profile = new QueryProfile("test");
profile.set("source.news.provider", providerName, null);
Query query = new Query(QueryTestCase.httpEncode("?query=test&model.sources=news"), profile.compile(null));
Result result = new Execution(registry.getComponent("default"), Execution.Context.createContextStub(registry, null)).search(query);
assertEquals(1, result.hits().size());
assertNotNull(result.hits().get(providerName + ":1"));
}
use of com.yahoo.search.query.profile.QueryProfile 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.QueryProfile in project vespa by vespa-engine.
the class QueryProfileXMLReader method fillQueryProfiles.
public void fillQueryProfiles(List<Element> queryProfileElements, QueryProfileRegistry registry) {
for (Element element : queryProfileElements) {
// Lookup by exact id
QueryProfile profile = registry.getComponent(new ComponentSpecification(element.getAttribute("id")).toId());
try {
readInherited(element, profile, registry, null, profile.toString());
readFields(element, profile, registry, null, profile.toString());
readVariants(element, profile, registry);
} catch (RuntimeException e) {
throw new IllegalArgumentException("Error reading " + profile, e);
}
}
}
Aggregations