Search in sources :

Example 46 with CompiledQueryProfile

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

the class QueryProfileSubstitutionTestCase method testVariants.

public void testVariants() {
    QueryProfile p = new QueryProfile("test");
    p.set("message", "Hello %{world}!", (QueryProfileRegistry) null);
    p.set("world", "world", (QueryProfileRegistry) null);
    p.setDimensions(new String[] { "x" });
    p.set("message", "Halo %{world}!", new String[] { "x1" }, null);
    p.set("world", "Europe", new String[] { "x2" }, null);
    CompiledQueryProfile cp = p.compile(null);
    assertEquals("Hello world!", cp.get("message", QueryProfileVariantsTestCase.toMap("x=x?")));
    assertEquals("Halo world!", cp.get("message", QueryProfileVariantsTestCase.toMap("x=x1")));
    assertEquals("Hello Europe!", cp.get("message", QueryProfileVariantsTestCase.toMap("x=x2")));
}
Also used : CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) QueryProfile(com.yahoo.search.query.profile.QueryProfile) CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile)

Example 47 with CompiledQueryProfile

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

the class QueryProfileTypeTestCase method testTypedOfPrimitivesAssignmentStrict.

public void testTypedOfPrimitivesAssignmentStrict() {
    QueryProfile profile = new QueryProfile("test");
    profile.setType(typeStrict);
    profile.set("myString", "anyValue", registry);
    // Illegal because this is strict
    assertNotPermitted(profile, "nontypedString", "anyValueToo");
    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("myQueryProfile.anyString", "value1", registry);
    profile.set("myQueryProfile.anyDouble", 8.76, registry);
    profile.set("myUserQueryProfile.myUserString", "value2", registry);
    // Illegal because this is strict
    assertNotPermitted(profile, "myUserQueryProfile.anyString", "value3");
    assertWrongType(profile, "integer", "myUserQueryProfile.myUserInteger", "notInteger");
    profile.set("myUserQueryProfile.myUserInteger", 1337, registry);
    // Illegal because this is strict
    assertNotPermitted(profile, "myUserQueryProfile.anyDouble", 9.13);
    CompiledQueryProfile cprofile = profile.compile(null);
    assertEquals("anyValue", cprofile.get("myString"));
    assertNull(cprofile.get("nontypedString"));
    assertEquals(3, cprofile.get("myInteger"));
    assertEquals(4000000000000l, cprofile.get("myLong"));
    assertEquals(3.14f, cprofile.get("myFloat"));
    assertEquals(2.18, cprofile.get("myDouble"));
    assertEquals("value1", cprofile.get("myQueryProfile.anyString"));
    assertEquals(8.76, cprofile.get("myQueryProfile.anyDouble"));
    assertEquals("value2", cprofile.get("myUserQueryProfile.myUserString"));
    assertNull(cprofile.get("myUserQueryProfile.anyString"));
    assertEquals(1337, cprofile.get("myUserQueryProfile.myUserInteger"));
    assertNull(cprofile.get("myUserQueryProfile.anyDouble"));
}
Also used : CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) QueryProfile(com.yahoo.search.query.profile.QueryProfile) CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile)

Example 48 with CompiledQueryProfile

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

the class QueryProfileTypeTestCase method testTypedAssignmentOfQueryProfilesStrict.

/**
 * Tests assigning a subprofile directly
 */
public void testTypedAssignmentOfQueryProfilesStrict() {
    QueryProfile profile = new QueryProfile("test");
    profile.setType(typeStrict);
    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(userStrict);
    myUser.set("myUserString", "userValue1", registry);
    myUser.set("myUserInteger", 442, registry);
    assertWrongType(profile, "reference to a query profile", "myQueryProfile", "aString");
    profile.set("myQueryProfile", map1, registry);
    assertNotPermitted(profile, "someMap", map2);
    assertWrongType(profile, "reference to a query profile of type 'userStrict'", "myUserQueryProfile", map1);
    profile.set("myUserQueryProfile", myUser, registry);
    CompiledQueryProfile cprofile = profile.compile(null);
    assertEquals("value1", cprofile.get("myQueryProfile.key1"));
    assertNull(cprofile.get("someMap.key2"));
    assertEquals("userValue1", cprofile.get("myUserQueryProfile.myUserString"));
    assertEquals(442, cprofile.get("myUserQueryProfile.myUserInteger"));
}
Also used : CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) QueryProfile(com.yahoo.search.query.profile.QueryProfile) CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile)

Aggregations

CompiledQueryProfile (com.yahoo.search.query.profile.compiled.CompiledQueryProfile)48 QueryProfile (com.yahoo.search.query.profile.QueryProfile)37 BackedOverridableQueryProfile (com.yahoo.search.query.profile.BackedOverridableQueryProfile)18 Query (com.yahoo.search.Query)8 CompiledQueryProfileRegistry (com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry)8 Test (org.junit.Test)7 CompoundName (com.yahoo.processing.request.CompoundName)5 QueryProfileXMLReader (com.yahoo.search.query.profile.config.QueryProfileXMLReader)4 HashMap (java.util.HashMap)4 HttpRequest (com.yahoo.container.jdisc.HttpRequest)3 QueryProfileProperties (com.yahoo.search.query.profile.QueryProfileProperties)3 QueryProfileRegistry (com.yahoo.search.query.profile.QueryProfileRegistry)3 QueryProfileType (com.yahoo.search.query.profile.types.QueryProfileType)3 Map (java.util.Map)3 QueryProfileConfigurer (com.yahoo.search.query.profile.config.QueryProfileConfigurer)2 FieldDescription (com.yahoo.search.query.profile.types.FieldDescription)2 HashSet (java.util.HashSet)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Chain (com.yahoo.component.chain.Chain)1 Renderer (com.yahoo.processing.rendering.Renderer)1