Search in sources :

Example 16 with FieldDescription

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

the class QueryProfileTypeInheritanceTestCase method addUserFields.

private void addUserFields(QueryProfileType user) {
    user.addField(new FieldDescription("myUserString", FieldType.fromString("string", registry), true, false));
    user.addField(new FieldDescription("myUserInteger", FieldType.fromString("integer", registry)));
}
Also used : FieldDescription(com.yahoo.search.query.profile.types.FieldDescription)

Example 17 with FieldDescription

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

the class NameTestCase method assertLegalFieldName.

private void assertLegalFieldName(String name) {
    new QueryProfile(name).set(name, "value", (QueryProfileRegistry) null);
    new FieldDescription(name, FieldType.stringType);
}
Also used : QueryProfile(com.yahoo.search.query.profile.QueryProfile) FieldDescription(com.yahoo.search.query.profile.types.FieldDescription)

Example 18 with FieldDescription

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

the class NameTestCase method assertIllegalFieldName.

/**
 * Checks that this is illegal both for profiles and types
 */
private void assertIllegalFieldName(String name, String expectedHighError, String expectedLowError) {
    try {
        QueryProfile profile = new QueryProfile("test");
        profile.set(name, "anyValue", (QueryProfileRegistry) null);
        fail("Should have failed");
    } catch (IllegalArgumentException e) {
        assertEquals(expectedHighError + ": " + expectedLowError, Exceptions.toMessageString(e));
    }
    try {
        new FieldDescription(name, FieldType.stringType);
        fail("Should have failed");
    } catch (IllegalArgumentException e) {
        assertEquals(expectedLowError, e.getMessage());
    }
}
Also used : QueryProfile(com.yahoo.search.query.profile.QueryProfile) FieldDescription(com.yahoo.search.query.profile.types.FieldDescription)

Example 19 with FieldDescription

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

the class OverrideTestCase method addUserFields.

private void addUserFields(QueryProfileType user) {
    boolean overridable = true;
    user.addField(new FieldDescription("myUserString", FieldType.fromString("string", registry), false, !overridable));
    user.addField(new FieldDescription("myUserInteger", FieldType.fromString("integer", registry)));
}
Also used : FieldDescription(com.yahoo.search.query.profile.types.FieldDescription)

Example 20 with FieldDescription

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

the class XmlReadingTestCase method testValid.

@Test
public void testValid() {
    QueryProfileRegistry registry = new QueryProfileXMLReader().read("src/test/java/com/yahoo/search/query/profile/config/test/validxml");
    CompiledQueryProfileRegistry cRegistry = registry.compile();
    QueryProfileType rootType = registry.getType("rootType");
    assertEquals(1, rootType.inherited().size());
    assertEquals("native", rootType.inherited().get(0).getId().getName());
    assertTrue(rootType.isStrict());
    assertTrue(rootType.getMatchAsPath());
    FieldDescription timeField = rootType.getField("time");
    assertTrue(timeField.isMandatory());
    assertEquals("long", timeField.getType().toInstanceDescription());
    FieldDescription userField = rootType.getField("user");
    assertFalse(userField.isMandatory());
    assertEquals("reference to a query profile of type 'user'", userField.getType().toInstanceDescription());
    QueryProfileType user = registry.getType("user");
    assertEquals(0, user.inherited().size());
    assertFalse(user.isStrict());
    assertFalse(user.getMatchAsPath());
    assertTrue(userField.isOverridable());
    FieldDescription ageField = user.getField("age");
    assertTrue(ageField.isMandatory());
    assertEquals("integer", ageField.getType().toInstanceDescription());
    FieldDescription robotField = user.getField("robot");
    assertFalse(robotField.isMandatory());
    assertFalse(robotField.isOverridable());
    assertEquals("boolean", robotField.getType().toInstanceDescription());
    CompiledQueryProfile defaultProfile = cRegistry.getComponent("default");
    assertNull(defaultProfile.getType());
    assertEquals("20", defaultProfile.get("hits"));
    assertFalse(defaultProfile.isOverridable(new CompoundName("hits"), null));
    assertFalse(defaultProfile.isOverridable(new CompoundName("user.trusted"), null));
    assertEquals("false", defaultProfile.get("user.trusted"));
    CompiledQueryProfile referencingProfile = cRegistry.getComponent("referencingModelSettings");
    assertNull(referencingProfile.getType());
    assertEquals("some query", referencingProfile.get("model.queryString"));
    assertEquals("aDefaultIndex", referencingProfile.get("model.defaultIndex"));
    // Request parameters here should be ignored
    HttpRequest request = HttpRequest.createTestRequest("?query=foo&user.trusted=true&default-index=title", Method.GET);
    Query query = new Query(request, defaultProfile);
    assertEquals("false", query.properties().get("user.trusted"));
    assertEquals("default", query.getModel().getDefaultIndex());
    assertEquals("default", query.properties().get("default-index"));
    CompiledQueryProfile rootProfile = cRegistry.getComponent("root");
    assertEquals("rootType", rootProfile.getType().getId().getName());
    assertEquals(30, rootProfile.get("hits"));
    assertEquals(3, rootProfile.get("traceLevel"));
    assertTrue(rootProfile.isOverridable(new CompoundName("hits"), null));
    QueryProfile someUser = registry.getComponent("someUser");
    assertEquals("5", someUser.get("sub.test"));
    assertEquals(18, someUser.get("age"));
    // aliases
    assertEquals(18, someUser.get("alder"));
    assertEquals(18, someUser.get("anno"));
    assertEquals(18, someUser.get("aLdER"));
    assertEquals(18, someUser.get("ANNO"));
    // Only aliases are case insensitive
    assertNull(someUser.get("Age"));
    Map<String, String> context = new HashMap<>();
    context.put("x", "x1");
    assertEquals(37, someUser.get("alder", context, null));
    assertEquals(37, someUser.get("anno", context, null));
    assertEquals(37, someUser.get("aLdER", context, null));
    assertEquals(37, someUser.get("ANNO", context, null));
    assertEquals("male", someUser.get("gender", context, null));
    assertEquals("male", someUser.get("sex", context, null));
    assertEquals("male", someUser.get("Sex", context, null));
    // Only aliases are case insensitive
    assertNull(someUser.get("Gender", context, null));
}
Also used : HttpRequest(com.yahoo.container.jdisc.HttpRequest) CompoundName(com.yahoo.processing.request.CompoundName) CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) QueryProfile(com.yahoo.search.query.profile.QueryProfile) Query(com.yahoo.search.Query) HashMap(java.util.HashMap) QueryProfileXMLReader(com.yahoo.search.query.profile.config.QueryProfileXMLReader) FieldDescription(com.yahoo.search.query.profile.types.FieldDescription) CompiledQueryProfileRegistry(com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry) CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) QueryProfileRegistry(com.yahoo.search.query.profile.QueryProfileRegistry) CompiledQueryProfileRegistry(com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry) QueryProfileType(com.yahoo.search.query.profile.types.QueryProfileType) Test(org.junit.Test)

Aggregations

FieldDescription (com.yahoo.search.query.profile.types.FieldDescription)22 QueryProfileType (com.yahoo.search.query.profile.types.QueryProfileType)11 QueryProfileRegistry (com.yahoo.search.query.profile.QueryProfileRegistry)7 QueryProfile (com.yahoo.search.query.profile.QueryProfile)5 QueryProfileTypeRegistry (com.yahoo.search.query.profile.types.QueryProfileTypeRegistry)5 ComponentId (com.yahoo.component.ComponentId)4 CompiledQueryProfileRegistry (com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry)3 CompoundName (com.yahoo.processing.request.CompoundName)2 CompiledQueryProfile (com.yahoo.search.query.profile.compiled.CompiledQueryProfile)2 FieldType (com.yahoo.search.query.profile.types.FieldType)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 HttpRequest (com.yahoo.container.jdisc.HttpRequest)1 Query (com.yahoo.search.Query)1 QueryProfileConfigurer (com.yahoo.search.query.profile.config.QueryProfileConfigurer)1 QueryProfileXMLReader (com.yahoo.search.query.profile.config.QueryProfileXMLReader)1 QueryProfilesConfig (com.yahoo.search.query.profile.config.QueryProfilesConfig)1 QueryProfileFieldType (com.yahoo.search.query.profile.types.QueryProfileFieldType)1 Reference (com.yahoo.searchlib.rankingexpression.Reference)1 TensorType (com.yahoo.tensor.TensorType)1