use of com.yahoo.search.query.profile.compiled.CompiledQueryProfile in project vespa by vespa-engine.
the class QueryProfileTypeTestCase method testTypedOverridingOfQueryProfileReferencesNonStrictThroughQuery.
/**
* Tests overriding a subprofile as an id string through the query.
* Here there exists a user profile already, and then a new one is overwritten
*/
public void testTypedOverridingOfQueryProfileReferencesNonStrictThroughQuery() {
QueryProfile profile = new QueryProfile("test");
profile.setType(type);
QueryProfile myUser = new QueryProfile("myUser");
myUser.setType(user);
myUser.set("myUserString", "userValue1", registry);
myUser.set("myUserInteger", 442, registry);
QueryProfile newUser = new QueryProfile("newUser");
newUser.setType(user);
newUser.set("myUserString", "newUserValue1", registry);
newUser.set("myUserInteger", 845, registry);
QueryProfileRegistry registry = new QueryProfileRegistry();
registry.register(profile);
registry.register(myUser);
registry.register(newUser);
CompiledQueryProfileRegistry cRegistry = registry.compile();
CompiledQueryProfile cprofile = cRegistry.getComponent("test");
Query query = new Query(HttpRequest.createTestRequest("?myUserQueryProfile=newUser", com.yahoo.jdisc.http.HttpRequest.Method.GET), cprofile);
assertEquals(0, query.errors().size());
assertEquals("newUserValue1", query.properties().get("myUserQueryProfile.myUserString"));
assertEquals(845, query.properties().get("myUserQueryProfile.myUserInteger"));
}
use of com.yahoo.search.query.profile.compiled.CompiledQueryProfile in project vespa by vespa-engine.
the class QueryProfileTypeTestCase method testTypedAssignmentOfQueryProfileReferencesNonStrictThroughQuery.
/**
* 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 testTypedAssignmentOfQueryProfileReferencesNonStrictThroughQuery() {
QueryProfile profile = new QueryProfile("test");
profile.setType(type);
QueryProfile newUser = new QueryProfile("newUser");
newUser.setType(user);
newUser.set("myUserString", "newUserValue1", registry);
newUser.set("myUserInteger", 845, registry);
registry.register(profile);
registry.register(newUser);
CompiledQueryProfileRegistry cRegistry = registry.compile();
CompiledQueryProfile cprofile = cRegistry.getComponent("test");
Query query = new Query(HttpRequest.createTestRequest("?myUserQueryProfile=newUser", com.yahoo.jdisc.http.HttpRequest.Method.GET), cprofile);
assertEquals(0, query.errors().size());
assertEquals("newUserValue1", query.properties().get("myUserQueryProfile.myUserString"));
assertEquals(845, query.properties().get("myUserQueryProfile.myUserInteger"));
}
use of com.yahoo.search.query.profile.compiled.CompiledQueryProfile 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.CompiledQueryProfile in project vespa by vespa-engine.
the class ParametersTestCase method createProfile.
public CompiledQueryProfile createProfile() {
QueryProfileRegistry registry = new QueryProfileRegistry();
QueryProfile profile = new QueryProfile("test");
profile.set("model.filter", "+year:2001", registry);
profile.set("model.language", "en", registry);
return registry.compile().findQueryProfile("test");
}
use of com.yahoo.search.query.profile.compiled.CompiledQueryProfile in project vespa by vespa-engine.
the class QueryProfileTypeInheritanceTestCase method testInheritance.
public void testInheritance() {
type.inherited().add(user);
type.freeze();
user.freeze();
assertFalse(type.isOverridable("myUserString"));
assertEquals("myUserInteger", type.getField("myUserInteger").getName());
QueryProfile test = new QueryProfile("test");
test.setType(type);
test.set("myUserInteger", "37", (QueryProfileRegistry) null);
test.set("myUnknownInteger", "38", (QueryProfileRegistry) null);
CompiledQueryProfile ctest = test.compile(null);
assertEquals(37, ctest.get("myUserInteger"));
assertEquals("38", ctest.get("myUnknownInteger"));
}
Aggregations