use of com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry in project vespa by vespa-engine.
the class QueryProfileTypeTestCase method testTypedAssignmentOfQueryProfileReferencesNonStrict.
/**
* Tests assigning a subprofile as an id string
*/
public void testTypedAssignmentOfQueryProfileReferencesNonStrict() {
QueryProfile profile = new QueryProfile("test");
profile.setType(type);
QueryProfile map1 = new QueryProfile("myMap1");
map1.set("key1", "value1", registry);
QueryProfile map2 = new QueryProfile("myMap2");
map2.set("key2", "value2", registry);
QueryProfile myUser = new QueryProfile("myUser");
myUser.setType(user);
myUser.set("myUserString", "userValue1", registry);
myUser.set("myUserInteger", 442, registry);
registry.register(profile);
registry.register(map1);
registry.register(map2);
registry.register(myUser);
assertWrongType(profile, "reference to a query profile", "myQueryProfile", "aString");
registry.register(map1);
profile.set("myQueryProfile", "myMap1", registry);
registry.register(map2);
// NOTICE: Will set as a string because we cannot know this is a reference
profile.set("someMap", "myMap2", registry);
assertWrongType(profile, "reference to a query profile of type 'user'", "myUserQueryProfile", "myMap1");
registry.register(myUser);
profile.set("myUserQueryProfile", "myUser", registry);
CompiledQueryProfileRegistry cRegistry = registry.compile();
CompiledQueryProfile cprofile = cRegistry.getComponent("test");
assertEquals("value1", cprofile.get("myQueryProfile.key1"));
assertEquals("myMap2", cprofile.get("someMap"));
assertNull("Asking for an value which cannot be completely resolved returns null", cprofile.get("someMap.key2"));
assertEquals("userValue1", cprofile.get("myUserQueryProfile.myUserString"));
assertEquals(442, cprofile.get("myUserQueryProfile.myUserInteger"));
}
use of com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry in project vespa by vespa-engine.
the class QueryProfileTypeTestCase method testTypedAssignmentOfQueryProfileReferencesStrictThroughQuery.
/**
* Tests overriding a subprofile as an id string through the query.
* Here no user profile is set before it is assigned in the query
*/
public void testTypedAssignmentOfQueryProfileReferencesStrictThroughQuery() {
QueryProfile profile = new QueryProfile("test");
profile.setType(typeStrict);
QueryProfile newUser = new QueryProfile("newUser");
newUser.setType(userStrict);
newUser.set("myUserString", "newUserValue1", registry);
newUser.set("myUserInteger", 845, registry);
registry.register(profile);
registry.register(newUser);
CompiledQueryProfileRegistry cRegistry = registry.compile();
Query query = new Query(HttpRequest.createTestRequest("?myUserQueryProfile=newUser", com.yahoo.jdisc.http.HttpRequest.Method.GET), cRegistry.getComponent("test"));
assertEquals(0, query.errors().size());
assertEquals("newUserValue1", query.properties().get("myUserQueryProfile.myUserString"));
assertEquals(845, query.properties().get("myUserQueryProfile.myUserInteger"));
try {
query.properties().set("myUserQueryProfile.someKey", "value");
fail("Should not be allowed to set this");
} catch (IllegalArgumentException e) {
assertEquals("Could not set 'myUserQueryProfile.someKey' to 'value': 'someKey' is not declared in query profile type 'userStrict', and the type is strict", Exceptions.toMessageString(e));
}
}
use of com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry in project vespa by vespa-engine.
the class OverrideTestCase method testUnoverridableQueryProfile.
/**
* Check that a query profile cannot be overridden
*/
public void testUnoverridableQueryProfile() {
QueryProfileRegistry registry = new QueryProfileRegistry();
QueryProfile test = new QueryProfile("test");
test.setType(type);
registry.register(test);
QueryProfile myUser = new QueryProfile("user");
myUser.setType(user);
myUser.set("myUserInteger", 1, registry);
myUser.set("myUserString", "userValue", registry);
test.set("myUserQueryProfile", myUser, registry);
registry.register(myUser);
QueryProfile otherUser = new QueryProfile("otherUser");
otherUser.setType(user);
otherUser.set("myUserInteger", 2, registry);
registry.register(otherUser);
CompiledQueryProfileRegistry cRegistry = registry.compile();
Query query = new Query(HttpRequest.createTestRequest("?myUserQueryprofile=otherUser", Method.GET), cRegistry.getComponent("test"));
assertEquals(0, query.errors().size());
assertEquals(1, query.properties().get("myUserQueryProfile.myUserInteger"));
}
use of com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry in project vespa by vespa-engine.
the class QueryFromProfileTestCase method testQueryFromProfile1.
public void testQueryFromProfile1() {
QueryProfileRegistry registry = new QueryProfileRegistry();
QueryProfile topLevel = new QueryProfile("topLevel");
topLevel.setType(registry.getTypeRegistry().getComponent("native"));
registry.register(topLevel);
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("?model=querybest", Method.GET), cRegistry.getComponent("topLevel"));
assertEquals("best", query.properties().get("model.queryString"));
assertEquals("best", query.getModel().getQueryTree().toString());
}
use of com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry in project vespa by vespa-engine.
the class MandatoryTestCase method testMandatoryInParentTypeWithInheritance.
@Test
public void testMandatoryInParentTypeWithInheritance() {
Fixture2 fixture = new Fixture2();
QueryProfile defaultProfile = new QueryProfile("default");
defaultProfile.setType(fixture.rootType);
QueryProfile mandatoryProfile = new QueryProfile("mandatory");
mandatoryProfile.setType(fixture.rootType);
// The single difference from the test above
mandatoryProfile.addInherited(defaultProfile);
mandatoryProfile.setType(fixture.mandatoryType);
fixture.registry.register(defaultProfile);
fixture.registry.register(mandatoryProfile);
CompiledQueryProfileRegistry cRegistry = fixture.registry.compile();
assertError("Incomplete query: Parameter 'foobar' is mandatory in query profile 'mandatory' of type 'mandatory-type' but is not set", new Query(QueryTestCase.httpEncode("?queryProfile=mandatory"), cRegistry.getComponent("mandatory")));
}
Aggregations