Search in sources :

Example 71 with QueryProfile

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

the class OverrideTestCase method testUntypedNestedUnoverridable.

/**
 * Check that non-overridables are protected also in nested untyped references
 */
public void testUntypedNestedUnoverridable() {
    QueryProfileRegistry registry = new QueryProfileRegistry();
    QueryProfile topMap = new QueryProfile("topMap");
    registry.register(topMap);
    QueryProfile subMap = new QueryProfile("topSubMap");
    topMap.set("subMap", subMap, registry);
    registry.register(subMap);
    QueryProfile test = new QueryProfile("test");
    test.setType(type);
    subMap.set("test", test, registry);
    registry.register(test);
    QueryProfile myUser = new QueryProfile("user");
    myUser.setType(user);
    myUser.set("myUserString", "finalValue", registry);
    test.set("myUserQueryProfile", myUser, registry);
    registry.register(myUser);
    registry.freeze();
    Query query = new Query(HttpRequest.createTestRequest("?subMap.test.myUserQueryProfile.myUserString=newValue", Method.GET), registry.compile().getComponent("topMap"));
    assertEquals(0, query.errors().size());
    assertEquals("finalValue", query.properties().get("subMap.test.myUserQueryProfile.myUserString"));
    query.properties().set("subMap.test.myUserQueryProfile.myUserString", "newValue");
    assertEquals("finalValue", query.properties().get("subMap.test.myUserQueryProfile.myUserString"));
}
Also used : QueryProfile(com.yahoo.search.query.profile.QueryProfile) Query(com.yahoo.search.Query) CompiledQueryProfileRegistry(com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry) QueryProfileRegistry(com.yahoo.search.query.profile.QueryProfileRegistry)

Example 72 with QueryProfile

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

the class OverrideTestCase method testInheritedNonOverridableInType.

/**
 * Tests overridability in an inherited field
 */
public void testInheritedNonOverridableInType() {
    QueryProfileRegistry registry = new QueryProfileRegistry();
    QueryProfile test = new QueryProfile("test");
    test.setType(type);
    test.set("myString", "finalString", (QueryProfileRegistry) null);
    registry.register(test);
    QueryProfile profile = new QueryProfile("profile");
    profile.addInherited(test);
    registry.register(profile);
    registry.freeze();
    Query query = new Query(HttpRequest.createTestRequest("?myString=newString", Method.GET), registry.compile().getComponent("test"));
    assertEquals(0, query.errors().size());
    assertEquals("finalString", query.properties().get("myString"));
    query.properties().set("myString", "newString");
    assertEquals("finalString", query.properties().get("myString"));
}
Also used : QueryProfile(com.yahoo.search.query.profile.QueryProfile) Query(com.yahoo.search.Query) CompiledQueryProfileRegistry(com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry) QueryProfileRegistry(com.yahoo.search.query.profile.QueryProfileRegistry)

Example 73 with QueryProfile

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

Example 74 with QueryProfile

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

the class OverrideTestCase method testInheritedNonOverridableInProfile.

/**
 * Tests overridability in an inherited field
 */
public void testInheritedNonOverridableInProfile() {
    QueryProfileRegistry registry = new QueryProfileRegistry();
    QueryProfile test = new QueryProfile("test");
    test.setType(type);
    test.set("myInteger", 1, registry);
    test.setOverridable("myInteger", false, null);
    registry.register(test);
    QueryProfile profile = new QueryProfile("profile");
    profile.addInherited(test);
    registry.register(profile);
    registry.freeze();
    Query query = new Query(HttpRequest.createTestRequest("?myInteger=32", Method.GET), registry.compile().getComponent("test"));
    assertEquals(0, query.errors().size());
    assertEquals(1, query.properties().get("myInteger"));
    query.properties().set("myInteger", 32);
    assertEquals(1, query.properties().get("myInteger"));
}
Also used : QueryProfile(com.yahoo.search.query.profile.QueryProfile) Query(com.yahoo.search.Query) CompiledQueryProfileRegistry(com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry) QueryProfileRegistry(com.yahoo.search.query.profile.QueryProfileRegistry)

Example 75 with QueryProfile

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

the class QueryProfileTypeInheritanceTestCase method testInheritanceStrict.

public void testInheritanceStrict() {
    typeStrict.inherited().add(userStrict);
    typeStrict.freeze();
    userStrict.freeze();
    QueryProfile test = new QueryProfile("test");
    test.setType(typeStrict);
    test.set("myUserInteger", "37", (QueryProfileRegistry) null);
    try {
        test.set("myUnknownInteger", "38", (QueryProfileRegistry) null);
        fail("Should have failed");
    } catch (IllegalArgumentException e) {
        assertEquals("'myUnknownInteger' is not declared in query profile type 'testtypeStrict', and the type is strict", e.getCause().getMessage());
    }
    assertEquals(37, test.get("myUserInteger"));
    assertNull(test.get("myUnknownInteger"));
}
Also used : CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) QueryProfile(com.yahoo.search.query.profile.QueryProfile)

Aggregations

QueryProfile (com.yahoo.search.query.profile.QueryProfile)161 CompiledQueryProfile (com.yahoo.search.query.profile.compiled.CompiledQueryProfile)92 Query (com.yahoo.search.Query)63 BackedOverridableQueryProfile (com.yahoo.search.query.profile.BackedOverridableQueryProfile)35 CompiledQueryProfileRegistry (com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry)28 Test (org.junit.Test)26 QueryProfileRegistry (com.yahoo.search.query.profile.QueryProfileRegistry)24 QueryProfileProperties (com.yahoo.search.query.profile.QueryProfileProperties)21 QueryProfileType (com.yahoo.search.query.profile.types.QueryProfileType)12 Properties (com.yahoo.search.query.Properties)8 FieldDescription (com.yahoo.search.query.profile.types.FieldDescription)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)5 SubstituteString (com.yahoo.search.query.profile.SubstituteString)4 QueryProfilesConfig (com.yahoo.search.query.profile.config.QueryProfilesConfig)4 Element (org.w3c.dom.Element)4 QueryException (com.yahoo.prelude.query.QueryException)3 Properties (com.yahoo.processing.request.Properties)3 QueryProfileXMLReader (com.yahoo.search.query.profile.config.QueryProfileXMLReader)3 QueryProfiles (com.yahoo.vespa.model.container.search.QueryProfiles)3 ComponentSpecification (com.yahoo.component.ComponentSpecification)2