Search in sources :

Example 66 with QueryProfile

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"));
}
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)

Example 67 with QueryProfile

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));
    }
}
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 68 with QueryProfile

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

Example 69 with QueryProfile

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

Example 70 with QueryProfile

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'");
}
Also used : 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