Search in sources :

Example 11 with CompiledQueryProfileRegistry

use of com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry in project vespa by vespa-engine.

the class QueryProfileTypeTestCase method testTypedOverridingOfQueryProfileReferencesNonStrictThroughQueryNestedInAnUntypedProfile.

/**
 * 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.
 * The whole thing is accessed through a two levels of nontyped top-level profiles
 */
public void testTypedOverridingOfQueryProfileReferencesNonStrictThroughQueryNestedInAnUntypedProfile() {
    QueryProfile topMap = new QueryProfile("topMap");
    QueryProfile subMap = new QueryProfile("topSubMap");
    topMap.set("subMap", subMap, registry);
    QueryProfile test = new QueryProfile("test");
    test.setType(type);
    subMap.set("typeProfile", test, registry);
    QueryProfile myUser = new QueryProfile("myUser");
    myUser.setType(user);
    myUser.set("myUserString", "userValue1", registry);
    myUser.set("myUserInteger", 442, registry);
    test.set("myUserQueryProfile", myUser, registry);
    QueryProfile newUser = new QueryProfile("newUser");
    newUser.setType(user);
    newUser.set("myUserString", "newUserValue1", registry);
    newUser.set("myUserInteger", 845, registry);
    registry.register(topMap);
    registry.register(subMap);
    registry.register(test);
    registry.register(myUser);
    registry.register(newUser);
    CompiledQueryProfileRegistry cRegistry = registry.compile();
    Query query = new Query(HttpRequest.createTestRequest("?subMap.typeProfile.myUserQueryProfile=newUser", com.yahoo.jdisc.http.HttpRequest.Method.GET), cRegistry.getComponent("topMap"));
    assertEquals(0, query.errors().size());
    assertEquals("newUserValue1", query.properties().get("subMap.typeProfile.myUserQueryProfile.myUserString"));
    assertEquals(845, query.properties().get("subMap.typeProfile.myUserQueryProfile.myUserInteger"));
}
Also used : CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) QueryProfile(com.yahoo.search.query.profile.QueryProfile) CompiledQueryProfileRegistry(com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry) Query(com.yahoo.search.Query)

Example 12 with CompiledQueryProfileRegistry

use of com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry in project vespa by vespa-engine.

the class QueryProfileTypeTestCase method testAnonTypedOverridingOfQueryProfileReferencesNonStrictThroughQueryNestedInAnUntypedProfile.

/**
 * Same as previous test but using the untyped myQueryProfile reference instead of the typed myUserQueryProfile
 */
public void testAnonTypedOverridingOfQueryProfileReferencesNonStrictThroughQueryNestedInAnUntypedProfile() {
    QueryProfile topMap = new QueryProfile("topMap");
    QueryProfile subMap = new QueryProfile("topSubMap");
    topMap.set("subMap", subMap, registry);
    QueryProfile test = new QueryProfile("test");
    test.setType(type);
    subMap.set("typeProfile", test, registry);
    QueryProfile myUser = new QueryProfile("myUser");
    myUser.setType(user);
    myUser.set("myUserString", "userValue1", registry);
    myUser.set("myUserInteger", 442, registry);
    test.set("myQueryProfile", myUser, registry);
    QueryProfile newUser = new QueryProfile("newUser");
    newUser.setType(user);
    newUser.set("myUserString", "newUserValue1", registry);
    newUser.set("myUserInteger", 845, registry);
    registry.register(topMap);
    registry.register(subMap);
    registry.register(test);
    registry.register(myUser);
    registry.register(newUser);
    CompiledQueryProfileRegistry cRegistry = registry.compile();
    Query query = new Query(HttpRequest.createTestRequest("?subMap.typeProfile.myQueryProfile=newUser", com.yahoo.jdisc.http.HttpRequest.Method.GET), cRegistry.getComponent("topMap"));
    assertEquals(0, query.errors().size());
    assertEquals("newUserValue1", query.properties().get("subMap.typeProfile.myQueryProfile.myUserString"));
    assertEquals(845, query.properties().get("subMap.typeProfile.myQueryProfile.myUserInteger"));
}
Also used : CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) QueryProfile(com.yahoo.search.query.profile.QueryProfile) CompiledQueryProfileRegistry(com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry) Query(com.yahoo.search.Query)

Example 13 with CompiledQueryProfileRegistry

use of com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry 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"));
}
Also used : CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) QueryProfile(com.yahoo.search.query.profile.QueryProfile) CompiledQueryProfileRegistry(com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry) CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) Query(com.yahoo.search.Query) QueryProfileRegistry(com.yahoo.search.query.profile.QueryProfileRegistry) CompiledQueryProfileRegistry(com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry)

Example 14 with CompiledQueryProfileRegistry

use of com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry 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"));
}
Also used : CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) QueryProfile(com.yahoo.search.query.profile.QueryProfile) CompiledQueryProfileRegistry(com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry) CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) Query(com.yahoo.search.Query)

Example 15 with CompiledQueryProfileRegistry

use of com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry in project vespa by vespa-engine.

the class QueryProfileTypeTestCase method testTypedOfPrimitivesAssignmentNonStrict.

public void testTypedOfPrimitivesAssignmentNonStrict() {
    QueryProfile profile = new QueryProfile("test");
    profile.setType(type);
    registry.register(profile);
    profile.set("myString", "anyValue", registry);
    // legal because this is not strict
    profile.set("nontypedString", "anyValueToo", registry);
    assertWrongType(profile, "integer", "myInteger", "notInteger");
    assertWrongType(profile, "integer", "myInteger", "1.5");
    profile.set("myInteger", 3, registry);
    assertWrongType(profile, "long", "myLong", "notLong");
    assertWrongType(profile, "long", "myLong", "1.5");
    profile.set("myLong", 4000000000000l, registry);
    assertWrongType(profile, "float", "myFloat", "notFloat");
    profile.set("myFloat", 3.14f, registry);
    assertWrongType(profile, "double", "myDouble", "notDouble");
    profile.set("myDouble", 2.18, registry);
    profile.set("myBoolean", true, registry);
    String tensorString1 = "{{a:a1, b:b1}:1.0, {a:a2, b:b1}:2.0}}";
    profile.set("ranking.features.query(myTensor1)", tensorString1, registry);
    String tensorString2 = "{{x:0, y:0}:1.0, {x:0, y:1}:2.0}}";
    profile.set("ranking.features.query(myTensor2)", tensorString2, registry);
    String tensorString3 = "{{x:x1}:1.0, {x:x2}:2.0}}";
    profile.set("ranking.features.query(myTensor3)", tensorString3, registry);
    // TODO
    profile.set("myQuery", "...", registry);
    profile.set("myQueryProfile.anyString", "value1", registry);
    profile.set("myQueryProfile.anyDouble", 8.76, registry);
    profile.set("myUserQueryProfile.myUserString", "value2", registry);
    // Legal because user is not strict
    profile.set("myUserQueryProfile.anyString", "value3", registry);
    assertWrongType(profile, "integer", "myUserQueryProfile.myUserInteger", "notInteger");
    // Set using alias
    profile.set("myUserQueryProfile.uint", 1337, registry);
    // Legal because user is not strict
    profile.set("myUserQueryProfile.anyDouble", 9.13, registry);
    CompiledQueryProfileRegistry cRegistry = registry.compile();
    QueryProfileProperties properties = new QueryProfileProperties(cRegistry.findQueryProfile("test"));
    assertEquals("anyValue", properties.get("myString"));
    assertEquals("anyValueToo", properties.get("nontypedString"));
    assertEquals(3, properties.get("myInteger"));
    assertEquals(3, properties.get("Int"));
    assertEquals(4000000000000l, properties.get("myLong"));
    assertEquals(3.14f, properties.get("myFloat"));
    assertEquals(2.18, properties.get("myDouble"));
    assertEquals(true, properties.get("myBoolean"));
    assertEquals(Tensor.from(tensorString1), properties.get("ranking.features.query(myTensor1)"));
    assertEquals(Tensor.from("tensor(x[2],y[2])", tensorString2), properties.get("ranking.features.query(myTensor2)"));
    assertEquals(Tensor.from("tensor(x{})", tensorString3), properties.get("ranking.features.query(myTensor3)"));
    // TODO: assertEquals(..., cprofile.get("myQuery"));
    assertEquals("value1", properties.get("myQueryProfile.anyString"));
    assertEquals("value1", properties.get("QP.anyString"));
    assertEquals(8.76, properties.get("myQueryProfile.anyDouble"));
    assertEquals(8.76, properties.get("qp.anyDouble"));
    assertEquals("value2", properties.get("myUserQueryProfile.myUserString"));
    assertEquals("value3", properties.get("myUserQueryProfile.anyString"));
    assertEquals(1337, properties.get("myUserQueryProfile.myUserInteger"));
    assertEquals(1337, properties.get("myUserQueryProfile.uint"));
    assertEquals(9.13, properties.get("myUserQueryProfile.anyDouble"));
    assertNull(properties.get("nonExisting"));
    properties.set("INt", 51);
    assertEquals(51, properties.get("InT"));
    assertEquals(51, properties.get("myInteger"));
}
Also used : CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) QueryProfile(com.yahoo.search.query.profile.QueryProfile) CompiledQueryProfileRegistry(com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) QueryProfileProperties(com.yahoo.search.query.profile.QueryProfileProperties)

Aggregations

CompiledQueryProfileRegistry (com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry)35 Query (com.yahoo.search.Query)33 QueryProfile (com.yahoo.search.query.profile.QueryProfile)22 Test (org.junit.Test)21 CompiledQueryProfile (com.yahoo.search.query.profile.compiled.CompiledQueryProfile)15 QueryProfileXMLReader (com.yahoo.search.query.profile.config.QueryProfileXMLReader)12 QueryProfileRegistry (com.yahoo.search.query.profile.QueryProfileRegistry)7 HttpRequest (com.yahoo.container.jdisc.HttpRequest)3 QueryProfileType (com.yahoo.search.query.profile.types.QueryProfileType)3 QueryProfileConfigurer (com.yahoo.search.query.profile.config.QueryProfileConfigurer)2 HashMap (java.util.HashMap)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 QueryException (com.yahoo.prelude.query.QueryException)1 CompoundName (com.yahoo.processing.request.CompoundName)1 Properties (com.yahoo.search.query.Properties)1 QueryProfileProperties (com.yahoo.search.query.profile.QueryProfileProperties)1 FieldDescription (com.yahoo.search.query.profile.types.FieldDescription)1 Map (java.util.Map)1