Search in sources :

Example 16 with QueryProfileType

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

the class PatchMatchingTestCase method testPatchMatching.

public void testPatchMatching() {
    QueryProfileType type = new QueryProfileType("type");
    type.setMatchAsPath(true);
    QueryProfile a = new QueryProfile("a");
    a.setType(type);
    QueryProfile abee = new QueryProfile("a/bee");
    abee.setType(type);
    abee.addInherited(a);
    QueryProfile abeece = new QueryProfile("a/bee/ce");
    abeece.setType(type);
    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 17 with QueryProfileType

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

the class PatchMatchingTestCase method testNoPatchMatching.

public void testNoPatchMatching() {
    QueryProfileType type = new QueryProfileType("type");
    // Default, but set here for clarity
    type.setMatchAsPath(false);
    QueryProfile a = new QueryProfile("a");
    a.setType(type);
    QueryProfile abee = new QueryProfile("a/bee");
    abee.setType(type);
    abee.addInherited(a);
    QueryProfile abeece = new QueryProfile("a/bee/ce");
    abeece.setType(type);
    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());
    // Different from test above
    assertNull(registry.findQueryProfile("a/bee/ce/dee"));
    // Different from test above
    assertNull(registry.findQueryProfile("a/bee/ce/dee/eee/"));
    // Different from test above
    assertNull(registry.findQueryProfile("a/bee/cede"));
    // Different from test above
    assertNull(registry.findQueryProfile("a/foo/bee/cede"));
    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 18 with QueryProfileType

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

the class TypedProfilesConfigurationTestCase method testIt.

/**
 * Asserts that everything is read correctly from this configuration
 */
public void testIt() {
    QueryProfileConfigurer configurer = new QueryProfileConfigurer("file:src/test/java/com/yahoo/search/query/profile/config/test/typed-profiles.cfg");
    QueryProfileRegistry registry = configurer.getCurrentRegistry();
    QueryProfileTypeRegistry types = registry.getTypeRegistry();
    // Assert that each type was read correctly
    QueryProfileType testType = types.getComponent("testtype");
    assertEquals("testtype", testType.getId().getName());
    assertFalse(testType.isStrict());
    assertFalse(testType.getMatchAsPath());
    assertEquals(7, testType.fields().size());
    assertEquals("myString", testType.getField("myString").getName());
    assertTrue(testType.getField("myString").isMandatory());
    assertTrue(testType.getField("myString").isOverridable());
    assertFalse(testType.getField("myInteger").isMandatory());
    assertFalse(testType.getField("myInteger").isOverridable());
    FieldDescription field = testType.getField("myUserQueryProfile");
    assertEquals("reference to a query profile of type 'user'", field.getType().toInstanceDescription());
    assertTrue(field.getAliases().contains("myqp"));
    assertTrue(field.getAliases().contains("user-profile"));
    QueryProfileType testTypeStrict = types.getComponent("testtypestrict");
    assertTrue(testTypeStrict.isStrict());
    assertTrue(testTypeStrict.getMatchAsPath());
    assertEquals(7, testTypeStrict.fields().size());
    assertEquals("reference to a query profile of type 'userstrict'", testTypeStrict.getField("myUserQueryProfile").getType().toInstanceDescription());
    QueryProfileType user = types.getComponent("user");
    assertFalse(user.isStrict());
    assertFalse(user.getMatchAsPath());
    assertEquals(2, user.fields().size());
    assertEquals(String.class, user.getField("myUserString").getType().getValueClass());
    QueryProfileType userStrict = types.getComponent("userstrict");
    assertTrue(userStrict.isStrict());
    assertFalse(userStrict.getMatchAsPath());
    assertEquals(2, userStrict.fields().size());
}
Also used : QueryProfileConfigurer(com.yahoo.search.query.profile.config.QueryProfileConfigurer) QueryProfileTypeRegistry(com.yahoo.search.query.profile.types.QueryProfileTypeRegistry) QueryProfileRegistry(com.yahoo.search.query.profile.QueryProfileRegistry) QueryProfileType(com.yahoo.search.query.profile.types.QueryProfileType) FieldDescription(com.yahoo.search.query.profile.types.FieldDescription)

Example 19 with QueryProfileType

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

the class QueryProfileCompiler method compile.

public static CompiledQueryProfile compile(QueryProfile in, CompiledQueryProfileRegistry registry) {
    DimensionalMap.Builder<CompoundName, Object> values = new DimensionalMap.Builder<>();
    DimensionalMap.Builder<CompoundName, QueryProfileType> types = new DimensionalMap.Builder<>();
    DimensionalMap.Builder<CompoundName, Object> references = new DimensionalMap.Builder<>();
    DimensionalMap.Builder<CompoundName, Object> unoverridables = new DimensionalMap.Builder<>();
    // Resolve values for each existing variant and combine into a single data structure
    Set<DimensionBindingForPath> variants = new HashSet<>();
    collectVariants(CompoundName.empty, in, DimensionBinding.nullBinding, variants);
    // if this contains no variants
    variants.add(new DimensionBindingForPath(DimensionBinding.nullBinding, CompoundName.empty));
    if (log.isLoggable(Level.FINE))
        log.fine("Compiling " + in.toString() + " having " + variants.size() + " variants");
    int i = 0;
    for (DimensionBindingForPath variant : variants) {
        if (log.isLoggable(Level.FINER))
            log.finer("    Compiling variant " + i++ + ": " + variant);
        for (Map.Entry<String, Object> entry : in.listValues(variant.path(), variant.binding().getContext(), null).entrySet()) values.put(variant.path().append(entry.getKey()), variant.binding(), entry.getValue());
        for (Map.Entry<CompoundName, QueryProfileType> entry : in.listTypes(variant.path(), variant.binding().getContext()).entrySet()) types.put(variant.path().append(entry.getKey()), variant.binding(), entry.getValue());
        for (CompoundName reference : in.listReferences(variant.path(), variant.binding().getContext())) // Used as a set; value is ignored
        references.put(variant.path().append(reference), variant.binding(), Boolean.TRUE);
        for (CompoundName name : in.listUnoverridable(variant.path(), variant.binding().getContext())) // Used as a set; value is ignored
        unoverridables.put(variant.path().append(name), variant.binding(), Boolean.TRUE);
    }
    return new CompiledQueryProfile(in.getId(), in.getType(), values.build(), types.build(), references.build(), unoverridables.build(), registry);
}
Also used : CompoundName(com.yahoo.processing.request.CompoundName) CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) DimensionalMap(com.yahoo.search.query.profile.compiled.DimensionalMap) QueryProfileType(com.yahoo.search.query.profile.types.QueryProfileType) Map(java.util.Map) DimensionalMap(com.yahoo.search.query.profile.compiled.DimensionalMap) HashSet(java.util.HashSet)

Example 20 with QueryProfileType

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

the class QueryProfileConfigurer method createProfileType.

private static void createProfileType(QueryProfilesConfig.Queryprofiletype config, QueryProfileTypeRegistry registry) {
    QueryProfileType type = new QueryProfileType(config.id());
    type.setStrict(config.strict());
    type.setMatchAsPath(config.matchaspath());
    registry.register(type);
}
Also used : QueryProfileType(com.yahoo.search.query.profile.types.QueryProfileType)

Aggregations

QueryProfileType (com.yahoo.search.query.profile.types.QueryProfileType)28 QueryProfileRegistry (com.yahoo.search.query.profile.QueryProfileRegistry)14 QueryProfile (com.yahoo.search.query.profile.QueryProfile)12 FieldDescription (com.yahoo.search.query.profile.types.FieldDescription)11 ComponentId (com.yahoo.component.ComponentId)7 QueryProfileTypeRegistry (com.yahoo.search.query.profile.types.QueryProfileTypeRegistry)7 CompiledQueryProfileRegistry (com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry)5 CompoundName (com.yahoo.processing.request.CompoundName)4 Query (com.yahoo.search.Query)4 CompiledQueryProfile (com.yahoo.search.query.profile.compiled.CompiledQueryProfile)3 ArrayList (java.util.ArrayList)3 Element (org.w3c.dom.Element)3 NamedReader (com.yahoo.io.reader.NamedReader)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 ComponentSpecification (com.yahoo.component.ComponentSpecification)1 HttpRequest (com.yahoo.container.jdisc.HttpRequest)1 QueryException (com.yahoo.prelude.query.QueryException)1 DimensionalMap (com.yahoo.search.query.profile.compiled.DimensionalMap)1 QueryProfileConfigurer (com.yahoo.search.query.profile.config.QueryProfileConfigurer)1