use of com.yahoo.search.query.profile.QueryProfile 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.QueryProfile 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.QueryProfile in project vespa by vespa-engine.
the class RequestContextPropertiesTestCase method testIt.
public void testIt() {
QueryProfile p = new QueryProfile("test");
p.setDimensions(new String[] { "x" });
p.set("a", "a-default", (QueryProfileRegistry) null);
p.set("a", "a-x1", new String[] { "x1" }, null);
p.set("a", "a-+x1", new String[] { "+x1" }, null);
Query q1 = new Query(QueryTestCase.httpEncode("?query=foo"), p.compile(null));
assertEquals("a-default", q1.properties().get("a"));
Query q2 = new Query(QueryTestCase.httpEncode("?query=foo&x=x1"), p.compile(null));
assertEquals("a-x1", q2.properties().get("a"));
Query q3 = new Query(QueryTestCase.httpEncode("?query=foo&x=+x1"), p.compile(null));
assertEquals("a-+x1", q3.properties().get("a"));
}
use of com.yahoo.search.query.profile.QueryProfile 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.QueryProfile in project vespa by vespa-engine.
the class NameTestCase method testFieldNames.
public void testFieldNames() {
assertLegalFieldName("aB");
try {
QueryProfile profile = new QueryProfile("test");
profile.set("a.", "anyValue", (QueryProfileRegistry) null);
fail("Should have failed");
} catch (IllegalArgumentException e) {
assertEquals("'a.' is not a legal compound name. Names can not end with a dot.", e.getMessage());
}
assertLegalFieldName("_a_b");
assertLegalFieldName("a_b");
assertLegalFieldName("a/b");
assertLegalFieldName("/a/b");
assertLegalFieldName("/a/b/");
assertIllegalFieldName("");
assertIllegalFieldName("aBc.dooEee.ce_d.-some-other.moreHere", "Could not set 'aBc.dooEee.ce_d.-some-other.moreHere' to 'anyValue'", "Illegal name '-some-other'");
}
Aggregations