Search in sources :

Example 66 with QueryProfileRegistry

use of com.yahoo.search.query.profile.QueryProfileRegistry 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 67 with QueryProfileRegistry

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

the class PatchMatchingTestCase method testPatchMatchingInheritance.

/**
 * Check that the path matching property is inherited to subtypes
 */
public void testPatchMatchingInheritance() {
    QueryProfileType type = new QueryProfileType("type");
    QueryProfileType subType = new QueryProfileType("subType");
    subType.inherited().add(type);
    // Supertype only
    type.setMatchAsPath(true);
    QueryProfile a = new QueryProfile("a");
    a.setType(type);
    QueryProfile abee = new QueryProfile("a/bee");
    abee.setType(subType);
    abee.addInherited(a);
    QueryProfile abeece = new QueryProfile("a/bee/ce");
    abeece.setType(subType);
    abeece.addInherited(abee);
    QueryProfileRegistry registry = new QueryProfileRegistry();
    registry.register(a);
    registry.register(abee);
    registry.register(abeece);
    registry.freeze();
    // No "default" registered
    assertNull(registry.findQueryProfile(null));
    assertEquals("a", registry.findQueryProfile("a").getId().getName());
    assertEquals("a/bee", registry.findQueryProfile("a/bee").getId().getName());
    assertEquals("a/bee/ce", registry.findQueryProfile("a/bee/ce").getId().getName());
    assertEquals("a/bee/ce", registry.findQueryProfile("a/bee/ce/dee").getId().getName());
    assertEquals("a/bee/ce", registry.findQueryProfile("a/bee/ce/dee/eee/").getId().getName());
    assertEquals("a/bee", registry.findQueryProfile("a/bee/cede").getId().getName());
    assertEquals("a", registry.findQueryProfile("a/foo/bee/cede").getId().getName());
    assertNull(registry.findQueryProfile("abee"));
}
Also used : QueryProfile(com.yahoo.search.query.profile.QueryProfile) QueryProfileRegistry(com.yahoo.search.query.profile.QueryProfileRegistry) QueryProfileType(com.yahoo.search.query.profile.types.QueryProfileType)

Example 68 with QueryProfileRegistry

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

the class QueryProfileTypeTestCase method setUp.

@Override
protected void setUp() {
    registry = new QueryProfileRegistry();
    type = new QueryProfileType(new ComponentId("testtype"));
    type.inherited().add(registry.getTypeRegistry().getComponent(new ComponentId("native")));
    typeStrict = new QueryProfileType(new ComponentId("testtypeStrict"));
    typeStrict.setStrict(true);
    user = new QueryProfileType(new ComponentId("user"));
    userStrict = new QueryProfileType(new ComponentId("userStrict"));
    userStrict.setStrict(true);
    registry.getTypeRegistry().register(type);
    registry.getTypeRegistry().register(typeStrict);
    registry.getTypeRegistry().register(user);
    registry.getTypeRegistry().register(userStrict);
    addTypeFields(type, registry.getTypeRegistry());
    type.addField(new FieldDescription("myUserQueryProfile", FieldType.fromString("query-profile:user", registry.getTypeRegistry())));
    addTypeFields(typeStrict, registry.getTypeRegistry());
    typeStrict.addField(new FieldDescription("myUserQueryProfile", FieldType.fromString("query-profile:userStrict", registry.getTypeRegistry())));
    addUserFields(user, registry.getTypeRegistry());
    addUserFields(userStrict, registry.getTypeRegistry());
}
Also used : QueryProfileRegistry(com.yahoo.search.query.profile.QueryProfileRegistry) CompiledQueryProfileRegistry(com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry) QueryProfileType(com.yahoo.search.query.profile.types.QueryProfileType) ComponentId(com.yahoo.component.ComponentId) FieldDescription(com.yahoo.search.query.profile.types.FieldDescription)

Aggregations

QueryProfileRegistry (com.yahoo.search.query.profile.QueryProfileRegistry)68 Test (org.junit.Test)38 QueryProfile (com.yahoo.search.query.profile.QueryProfile)24 CompiledQueryProfileRegistry (com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry)16 RawRankProfile (com.yahoo.searchdefinition.derived.RawRankProfile)16 QueryProfileType (com.yahoo.search.query.profile.types.QueryProfileType)14 Query (com.yahoo.search.Query)11 AttributeFields (com.yahoo.searchdefinition.derived.AttributeFields)11 QueryProfiles (com.yahoo.vespa.model.container.search.QueryProfiles)11 Pair (com.yahoo.collections.Pair)8 QueryProfileXMLReader (com.yahoo.search.query.profile.config.QueryProfileXMLReader)8 Search (com.yahoo.searchdefinition.Search)8 FieldDescription (com.yahoo.search.query.profile.types.FieldDescription)7 RankProfileRegistry (com.yahoo.searchdefinition.RankProfileRegistry)7 BaseDeployLogger (com.yahoo.config.model.application.provider.BaseDeployLogger)6 SDDocumentType (com.yahoo.searchdefinition.document.SDDocumentType)6 SDField (com.yahoo.searchdefinition.document.SDField)5 ComponentId (com.yahoo.component.ComponentId)4 CompiledQueryProfile (com.yahoo.search.query.profile.compiled.CompiledQueryProfile)4 QueryProfileTypeRegistry (com.yahoo.search.query.profile.types.QueryProfileTypeRegistry)4