Search in sources :

Example 46 with QueryProfile

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

the class QueryProfileVariantsTestCase method testSimple.

public void testSimple() {
    QueryProfile profile = new QueryProfile("a");
    profile.set("a", "a.deflt", (QueryProfileRegistry) null);
    profile.setDimensions(new String[] { "x", "y", "z" });
    profile.set("a", "a.1.*.*", new String[] { "x1", null, null }, null);
    profile.set("a", "a.1.*.1", new String[] { "x1", null, "z1" }, null);
    profile.set("a", "a.1.*.5", new String[] { "x1", null, "z5" }, null);
    profile.set("a", "a.1.1.*", new String[] { "x1", "y1", null }, null);
    profile.set("a", "a.1.5.*", new String[] { "x1", "y5", null }, null);
    profile.set("a", "a.1.1.1", new String[] { "x1", "y1", "z1" }, null);
    profile.set("a", "a.2.1.1", new String[] { "x2", "y1", "z1" }, null);
    profile.set("a", "a.1.2.2", new String[] { "x1", "y2", "z2" }, null);
    profile.set("a", "a.1.2.3", new String[] { "x1", "y2", "z3" }, null);
    // Same as ,null,null
    profile.set("a", "a.2.*.*", new String[] { "x2" }, null);
    CompiledQueryProfile cprofile = profile.compile(null);
    // Perfect matches
    assertGet("a.deflt", "a", new String[] { null, null, null }, profile, cprofile);
    assertGet("a.1.*.*", "a", new String[] { "x1", null, null }, profile, cprofile);
    assertGet("a.1.1.*", "a", new String[] { "x1", "y1", null }, profile, cprofile);
    assertGet("a.1.5.*", "a", new String[] { "x1", "y5", null }, profile, cprofile);
    assertGet("a.1.*.1", "a", new String[] { "x1", null, "z1" }, profile, cprofile);
    assertGet("a.1.*.5", "a", new String[] { "x1", null, "z5" }, profile, cprofile);
    assertGet("a.1.1.1", "a", new String[] { "x1", "y1", "z1" }, profile, cprofile);
    assertGet("a.2.1.1", "a", new String[] { "x2", "y1", "z1" }, profile, cprofile);
    assertGet("a.1.2.2", "a", new String[] { "x1", "y2", "z2" }, profile, cprofile);
    assertGet("a.1.2.3", "a", new String[] { "x1", "y2", "z3" }, profile, cprofile);
    assertGet("a.2.*.*", "a", new String[] { "x2", null, null }, profile, cprofile);
    // Wildcard matches
    assertGet("a.deflt", "a", new String[] { "x?", "y?", "z?" }, profile, cprofile);
    assertGet("a.deflt", "a", new String[] { "x?", "y1", "z1" }, profile, cprofile);
    assertGet("a.1.*.*", "a", new String[] { "x1", "y?", "z?" }, profile, cprofile);
    assertGet("a.1.*.*", "a", new String[] { "x1", "y?", "z?" }, profile, cprofile);
    assertGet("a.1.1.*", "a", new String[] { "x1", "y1", "z?" }, profile, cprofile);
    assertGet("a.1.*.1", "a", new String[] { "x1", "y?", "z1" }, profile, cprofile);
    assertGet("a.1.5.*", "a", new String[] { "x1", "y5", "z?" }, profile, cprofile);
    assertGet("a.1.*.5", "a", new String[] { "x1", "y?", "z5" }, profile, cprofile);
    // Left dimension gets precedence
    assertGet("a.1.5.*", "a", new String[] { "x1", "y5", "z5" }, profile, cprofile);
    assertGet("a.2.*.*", "a", new String[] { "x2", "y?", "z?" }, profile, cprofile);
}
Also used : CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) QueryProfile(com.yahoo.search.query.profile.QueryProfile) BackedOverridableQueryProfile(com.yahoo.search.query.profile.BackedOverridableQueryProfile) CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile)

Example 47 with QueryProfile

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

the class QueryProfileVariantsTestCase method testVariantInheritanceOverridesBaseInheritanceMixed.

public void testVariantInheritanceOverridesBaseInheritanceMixed() {
    QueryProfile root = new QueryProfile("root");
    root.set("model.defaultIndex", "default", (QueryProfileRegistry) null);
    QueryProfile multi = new QueryProfile("multi");
    multi.setDimensions(new String[] { "x" });
    multi.set("model.defaultIndex", "title", (QueryProfileRegistry) null);
    multi.set("model.queryString", "modelQuery", (QueryProfileRegistry) null);
    multi.addInherited(root, new String[] { "x1" });
    multi.set("model.queryString", "modelVariantQuery", new String[] { "x1" }, null);
    CompiledQueryProfile cmulti = multi.compile(null);
    assertEquals("default", cmulti.get("model.defaultIndex", toMap("x=x1")));
    assertEquals("modelVariantQuery", cmulti.get("model.queryString", toMap("x=x1")));
}
Also used : CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) QueryProfile(com.yahoo.search.query.profile.QueryProfile) BackedOverridableQueryProfile(com.yahoo.search.query.profile.BackedOverridableQueryProfile) CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile)

Example 48 with QueryProfile

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

the class QueryProfileVariantsTestCase method testListVariantPropertiesNoCompounds.

public void testListVariantPropertiesNoCompounds() {
    QueryProfile parent1 = new QueryProfile("parent1");
    // Defined everywhere
    parent1.set("a", "parent1-a", (QueryProfileRegistry) null);
    // Defined everywhere, but no variants
    parent1.set("b", "parent1-b", (QueryProfileRegistry) null);
    // Defined in both parents only
    parent1.set("c", "parent1-c", (QueryProfileRegistry) null);
    QueryProfile parent2 = new QueryProfile("parent2");
    parent2.set("a", "parent2-a", (QueryProfileRegistry) null);
    parent2.set("b", "parent2-b", (QueryProfileRegistry) null);
    parent2.set("c", "parent2-c", (QueryProfileRegistry) null);
    // Defined in second parent only
    parent2.set("d", "parent2-d", (QueryProfileRegistry) null);
    QueryProfile main = new QueryProfile("main");
    main.setDimensions(new String[] { "x", "y" });
    main.addInherited(parent1);
    main.addInherited(parent2);
    main.set("a", "main-a", (QueryProfileRegistry) null);
    main.set("a", "main-a-x1", new String[] { "x1" }, null);
    // Defined in two variants only
    main.set("e", "main-e-x1", new String[] { "x1" }, null);
    // Defined in one variants only
    main.set("f", "main-f-x1", new String[] { "x1" }, null);
    main.set("a", "main-a-x1.y1", new String[] { "x1", "y1" }, null);
    main.set("a", "main-a-x1.y2", new String[] { "x1", "y2" }, null);
    main.set("e", "main-e-x1.y2", new String[] { "x1", "y2" }, null);
    // Defined in one variant only
    main.set("g", "main-g-x1.y2", new String[] { "x1", "y2" }, null);
    main.set("b", "main-b", (QueryProfileRegistry) null);
    QueryProfile inheritedVariant1 = new QueryProfile("inheritedVariant1");
    inheritedVariant1.set("a", "inheritedVariant1-a", (QueryProfileRegistry) null);
    // Only defined in two inherited variants
    inheritedVariant1.set("h", "inheritedVariant1-h", (QueryProfileRegistry) null);
    QueryProfile inheritedVariant2 = new QueryProfile("inheritedVariant2");
    inheritedVariant2.set("a", "inheritedVariant2-a", (QueryProfileRegistry) null);
    // Only defined in two inherited variants
    inheritedVariant2.set("h", "inheritedVariant2-h", (QueryProfileRegistry) null);
    // Only defined in one inherited variant
    inheritedVariant2.set("i", "inheritedVariant2-i", (QueryProfileRegistry) null);
    QueryProfile inheritedVariant3 = new QueryProfile("inheritedVariant3");
    // Only defined in one inherited variant, but inherited twice
    inheritedVariant3.set("j", "inheritedVariant3-j", (QueryProfileRegistry) null);
    main.addInherited(inheritedVariant1, new String[] { "x1" });
    main.addInherited(inheritedVariant3, new String[] { "x1" });
    main.addInherited(inheritedVariant2, new String[] { "x1", "y2" });
    main.addInherited(inheritedVariant3, new String[] { "x1", "y2" });
    // Runtime-ify
    Properties properties = new QueryProfileProperties(main.compile(null));
    int expectedBaseSize = 4;
    // No context
    Map<String, Object> listed = properties.listProperties();
    assertEquals(expectedBaseSize, listed.size());
    assertEquals("main-a", listed.get("a"));
    assertEquals("main-b", listed.get("b"));
    assertEquals("parent1-c", listed.get("c"));
    assertEquals("parent2-d", listed.get("d"));
    // Context x=x1
    listed = properties.listProperties(toMap(main, new String[] { "x1" }));
    assertEquals(expectedBaseSize + 4, listed.size());
    assertEquals("main-a-x1", listed.get("a"));
    assertEquals("main-b", listed.get("b"));
    assertEquals("parent1-c", listed.get("c"));
    assertEquals("parent2-d", listed.get("d"));
    assertEquals("main-e-x1", listed.get("e"));
    assertEquals("main-f-x1", listed.get("f"));
    assertEquals("inheritedVariant1-h", listed.get("h"));
    assertEquals("inheritedVariant3-j", listed.get("j"));
    // Context x=x1,y=y1
    listed = properties.listProperties(toMap(main, new String[] { "x1", "y1" }));
    assertEquals(expectedBaseSize + 4, listed.size());
    assertEquals("main-a-x1.y1", listed.get("a"));
    assertEquals("main-b", listed.get("b"));
    assertEquals("parent1-c", listed.get("c"));
    assertEquals("parent2-d", listed.get("d"));
    assertEquals("main-e-x1", listed.get("e"));
    assertEquals("main-f-x1", listed.get("f"));
    assertEquals("inheritedVariant1-h", listed.get("h"));
    assertEquals("inheritedVariant3-j", listed.get("j"));
    // Context x=x1,y=y2
    listed = properties.listProperties(toMap(main, new String[] { "x1", "y2" }));
    assertEquals(expectedBaseSize + 6, listed.size());
    assertEquals("main-a-x1.y2", listed.get("a"));
    assertEquals("main-b", listed.get("b"));
    assertEquals("parent1-c", listed.get("c"));
    assertEquals("parent2-d", listed.get("d"));
    assertEquals("main-e-x1.y2", listed.get("e"));
    assertEquals("main-f-x1", listed.get("f"));
    assertEquals("main-g-x1.y2", listed.get("g"));
    assertEquals("inheritedVariant2-h", listed.get("h"));
    assertEquals("inheritedVariant2-i", listed.get("i"));
    assertEquals("inheritedVariant3-j", listed.get("j"));
    // Context x=x1,y=y3
    listed = properties.listProperties(toMap(main, new String[] { "x1", "y3" }));
    assertEquals(expectedBaseSize + 4, listed.size());
    assertEquals("main-a-x1", listed.get("a"));
    assertEquals("main-b", listed.get("b"));
    assertEquals("parent1-c", listed.get("c"));
    assertEquals("parent2-d", listed.get("d"));
    assertEquals("main-e-x1", listed.get("e"));
    assertEquals("main-f-x1", listed.get("f"));
    assertEquals("inheritedVariant1-h", listed.get("h"));
    assertEquals("inheritedVariant3-j", listed.get("j"));
    // Context x=x2,y=y1
    listed = properties.listProperties(toMap(main, new String[] { "x2", "y1" }));
    assertEquals(expectedBaseSize, listed.size());
    assertEquals("main-a", listed.get("a"));
    assertEquals("main-b", listed.get("b"));
    assertEquals("parent1-c", listed.get("c"));
    assertEquals("parent2-d", listed.get("d"));
}
Also used : CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) QueryProfile(com.yahoo.search.query.profile.QueryProfile) BackedOverridableQueryProfile(com.yahoo.search.query.profile.BackedOverridableQueryProfile) QueryProfileProperties(com.yahoo.search.query.profile.QueryProfileProperties) Properties(com.yahoo.search.query.Properties) QueryProfileProperties(com.yahoo.search.query.profile.QueryProfileProperties)

Example 49 with QueryProfile

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

the class QueryProfileVariantsTestCase method testVariantInheritanceOverridesBaseInheritanceComplexSimplified.

public void testVariantInheritanceOverridesBaseInheritanceComplexSimplified() {
    QueryProfile root = new QueryProfile("root");
    root.set("model.defaultIndex", "default", (QueryProfileRegistry) null);
    QueryProfile multi = new QueryProfile("multi");
    multi.setDimensions(new String[] { "x" });
    multi.set("model.defaultIndex", "title", (QueryProfileRegistry) null);
    multi.addInherited(root, new String[] { "x1" });
    assertEquals("default", multi.compile(null).get("model.defaultIndex", toMap("x=x1")));
}
Also used : CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) QueryProfile(com.yahoo.search.query.profile.QueryProfile) BackedOverridableQueryProfile(com.yahoo.search.query.profile.BackedOverridableQueryProfile)

Example 50 with QueryProfile

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

the class MandatoryTestCase method testMandatoryInParentType.

@Test
public void testMandatoryInParentType() {
    Fixture2 fixture = new Fixture2();
    QueryProfile defaultProfile = new QueryProfile("default");
    defaultProfile.setType(fixture.rootType);
    QueryProfile mandatoryProfile = new QueryProfile("mandatory");
    mandatoryProfile.setType(fixture.rootType);
    mandatoryProfile.setType(fixture.mandatoryType);
    fixture.registry.register(defaultProfile);
    fixture.registry.register(mandatoryProfile);
    CompiledQueryProfileRegistry cRegistry = fixture.registry.compile();
    assertError("Incomplete query: Parameter 'foobar' is mandatory in query profile 'mandatory' of type 'mandatory-type' but is not set", new Query(QueryTestCase.httpEncode("?queryProfile=mandatory"), cRegistry.getComponent("mandatory")));
}
Also used : QueryProfile(com.yahoo.search.query.profile.QueryProfile) CompiledQueryProfileRegistry(com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry) Query(com.yahoo.search.Query) Test(org.junit.Test)

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