Search in sources :

Example 16 with CompoundName

use of com.yahoo.processing.request.CompoundName 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)

Example 17 with CompoundName

use of com.yahoo.processing.request.CompoundName in project vespa by vespa-engine.

the class QueryProfileTypeTestCase method assertNotPermitted.

private void assertNotPermitted(QueryProfile profile, String name, Object value) {
    String localName = new CompoundName(name).last();
    try {
        profile.set(name, value, registry);
        fail("Should fail setting " + name + " to " + value);
    } catch (IllegalArgumentException e) {
        assertTrue(Exceptions.toMessageString(e).startsWith("Could not set '" + name + "' to '" + value + "': '" + localName + "' is not declared"));
    }
}
Also used : CompoundName(com.yahoo.processing.request.CompoundName) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString)

Example 18 with CompoundName

use of com.yahoo.processing.request.CompoundName in project vespa by vespa-engine.

the class PropertyMap method listProperties.

@Override
public Map<String, Object> listProperties(CompoundName path, Map<String, String> context, Properties substitution) {
    Map<String, Object> map = super.listProperties(path, context, substitution);
    for (Map.Entry<CompoundName, Object> entry : properties.entrySet()) {
        if (!entry.getKey().hasPrefix(path))
            continue;
        CompoundName propertyName = entry.getKey().rest(path.size());
        if (propertyName.isEmpty())
            continue;
        map.put(propertyName.toString(), entry.getValue());
    }
    return map;
}
Also used : CompoundName(com.yahoo.processing.request.CompoundName) Map(java.util.Map) HashMap(java.util.HashMap)

Example 19 with CompoundName

use of com.yahoo.processing.request.CompoundName in project vespa by vespa-engine.

the class CompoundNameTestCase method testAsList.

@Test
public void testAsList() {
    assertEquals("[one]", new CompoundName("one").asList().toString());
    assertEquals("[one, two, three]", new CompoundName("one.two.three").asList().toString());
}
Also used : CompoundName(com.yahoo.processing.request.CompoundName) Test(org.junit.Test)

Example 20 with CompoundName

use of com.yahoo.processing.request.CompoundName in project vespa by vespa-engine.

the class CompoundNameTestCase method testFirstRest.

@Test
public void testFirstRest() {
    assertEquals(CompoundName.empty, CompoundName.empty.rest());
    CompoundName n = new CompoundName("on.two.three");
    assertEquals("on", n.first());
    assertEquals("two.three", n.rest().toString());
    n = n.rest();
    assertEquals("two", n.first());
    assertEquals("three", n.rest().toString());
    n = n.rest();
    assertEquals("three", n.first());
    assertEquals("", n.rest().toString());
    n = n.rest();
    assertEquals("", n.first());
    assertEquals("", n.rest().toString());
    n = n.rest();
    assertEquals("", n.first());
    assertEquals("", n.rest().toString());
}
Also used : CompoundName(com.yahoo.processing.request.CompoundName) Test(org.junit.Test)

Aggregations

CompoundName (com.yahoo.processing.request.CompoundName)22 Test (org.junit.Test)7 CompiledQueryProfile (com.yahoo.search.query.profile.compiled.CompiledQueryProfile)6 HashMap (java.util.HashMap)6 Map (java.util.Map)5 QueryProfileType (com.yahoo.search.query.profile.types.QueryProfileType)4 PropertyMap (com.yahoo.processing.request.properties.PropertyMap)2 FieldDescription (com.yahoo.search.query.profile.types.FieldDescription)2 HashSet (java.util.HashSet)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 HttpRequest (com.yahoo.container.jdisc.HttpRequest)1 Request (com.yahoo.processing.Request)1 Properties (com.yahoo.processing.request.Properties)1 Query (com.yahoo.search.Query)1 ModelObjectMap (com.yahoo.search.query.profile.ModelObjectMap)1 QueryProfile (com.yahoo.search.query.profile.QueryProfile)1 QueryProfileProperties (com.yahoo.search.query.profile.QueryProfileProperties)1 QueryProfileRegistry (com.yahoo.search.query.profile.QueryProfileRegistry)1 SubstituteString (com.yahoo.search.query.profile.SubstituteString)1 CompiledQueryProfileRegistry (com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry)1