Search in sources :

Example 1 with QueryProfileConfigurer

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

the class QueryProfilesTestCase method assertConfig.

protected void assertConfig(String correctFileName, QueryProfileRegistry check) throws IOException {
    assertSerializedConfigFileEquals(root + "/" + correctFileName, com.yahoo.text.StringUtilities.implodeMultiline(com.yahoo.config.ConfigInstance.serialize(new QueryProfiles(check).getConfig())));
    // Also assert that the correct config config can actually be read as a config source
    QueryProfileConfigurer configurer = new QueryProfileConfigurer("file:" + root + "empty.cfg");
    configurer.shutdown();
}
Also used : QueryProfileConfigurer(com.yahoo.search.query.profile.config.QueryProfileConfigurer) QueryProfiles(com.yahoo.vespa.model.container.search.QueryProfiles)

Example 2 with QueryProfileConfigurer

use of com.yahoo.search.query.profile.config.QueryProfileConfigurer 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 3 with QueryProfileConfigurer

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

the class QueryProfileConfigurationTestCase method testVariantConfigurationThroughQueryLookup.

@Test
public void testVariantConfigurationThroughQueryLookup() {
    QueryProfileConfigurer configurer = new QueryProfileConfigurer("file:" + CONFIG_DIR + "query-profile-variants-configuration.cfg");
    CompiledQueryProfileRegistry registry = configurer.getCurrentRegistry().compile();
    CompiledQueryProfile variants1 = registry.getComponent("variants1");
    // Variant 1
    assertEquals("x1.y1.a", new Query(QueryTestCase.httpEncode("?query=foo&x=x1&y=y1"), variants1).properties().get("a"));
    assertEquals("x1.y1.b", new Query(QueryTestCase.httpEncode("?query=foo&x=x1&y=y1"), variants1).properties().get("b"));
    assertEquals("x1.y1.defaultIndex", new Query(QueryTestCase.httpEncode("?query=foo&x=x1&y=y1"), variants1).getModel().getDefaultIndex());
    assertEquals("x1.y?.a", new Query(QueryTestCase.httpEncode("?query=foo&x=x1&y=zz"), variants1).properties().get("a"));
    assertEquals("x1.y?.defaultIndex", new Query(QueryTestCase.httpEncode("?query=foo&x=x1&y=zz"), variants1).getModel().getDefaultIndex());
    assertEquals("x?.y1.a", new Query(QueryTestCase.httpEncode("?query=foo&x=zz&y=y1"), variants1).properties().get("a"));
    assertEquals("x?.y1.defaultIndex", new Query(QueryTestCase.httpEncode("?query=foo&x=zz&y=y1"), variants1).getModel().getDefaultIndex());
    assertEquals("x?.y1.filter", new Query(QueryTestCase.httpEncode("?query=foo&x=zz&y=y1"), variants1).getModel().getFilter());
    assertEquals("a-deflt", new Query(QueryTestCase.httpEncode("?query=foo&x=z1&y=z2"), variants1).properties().get("a"));
    // Variant 2
    CompiledQueryProfile variants2 = registry.getComponent("variants2");
    assertEquals("variant2:y1.c", new Query(QueryTestCase.httpEncode("?query=foo&x=*&y=y1"), variants2).properties().get("c"));
    assertEquals("variant2:y2.c", new Query(QueryTestCase.httpEncode("?query=foo&x=*&y=y2"), variants2).properties().get("c"));
    assertEquals("variant2:c-df", new Query(QueryTestCase.httpEncode("?query=foo&x=*&y=z1"), variants2).properties().get("c"));
    assertEquals("variant2:c-df", new Query(QueryTestCase.httpEncode("?query=foo"), variants2).properties().get("c"));
    assertEquals("variant2:c-df", new Query(QueryTestCase.httpEncode("?query=foo&x=x1"), variants2).properties().get("c"));
    assertNull(new Query(QueryTestCase.httpEncode("?query=foo&x=*&y=y1"), variants2).properties().get("d"));
    // Reference following from variant 1
    assertEquals("variant2:y1.c", new Query(QueryTestCase.httpEncode("?query=foo&x=**&y=y1"), variants1).properties().get("toVariants.c"));
    assertEquals("variant3:c-df", new Query(QueryTestCase.httpEncode("?query=foo&x=x1&y=**"), variants1).properties().get("toVariants.c"));
    assertEquals("variant3:y1.c", new Query(QueryTestCase.httpEncode("?query=foo&x=x1&y=y1"), variants1).properties().get("toVariants.c"));
    assertEquals("variant3:y2.c", new Query(QueryTestCase.httpEncode("?query=foo&x=x1&y=y2"), variants1).properties().get("toVariants.c"));
}
Also used : CompiledQueryProfileRegistry(com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry) CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) Query(com.yahoo.search.Query) QueryProfileConfigurer(com.yahoo.search.query.profile.config.QueryProfileConfigurer) Test(org.junit.Test)

Example 4 with QueryProfileConfigurer

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

the class QueryProfileConfigurationTestCase method testVariantConfiguration.

@Test
public void testVariantConfiguration() {
    QueryProfileConfigurer configurer = new QueryProfileConfigurer("file:" + CONFIG_DIR + "query-profile-variants-configuration.cfg");
    // Variant 1
    QueryProfile variants1 = configurer.getCurrentRegistry().getComponent("variants1");
    assertGet("x1.y1.a", "a", new String[] { "x1", "y1" }, variants1);
    assertGet("x1.y1.b", "b", new String[] { "x1", "y1" }, variants1);
    assertGet("x1.y?.a", "a", new String[] { "x1", "zz" }, variants1);
    assertGet("x?.y1.a", "a", new String[] { "zz", "y1" }, variants1);
    assertGet("a-deflt", "a", new String[] { "z1", "z2" }, variants1);
    // ...inherited
    assertGet("parent1-value", "parent1", new String[] { "x1", "y1" }, variants1);
    assertGet("parent2-value", "parent2", new String[] { "x1", "y1" }, variants1);
    assertGet(null, "parent1", new String[] { "x1", "y2" }, variants1);
    assertGet(null, "parent2", new String[] { "x1", "y2" }, variants1);
    // Variant 2
    QueryProfile variants2 = configurer.getCurrentRegistry().getComponent("variants2");
    assertGet("variant2:y1.c", "c", new String[] { "*", "y1" }, variants2);
    assertGet("variant2:y2.c", "c", new String[] { "*", "y2" }, variants2);
    assertGet("variant2:c-df", "c", new String[] { "*", "z1" }, variants2);
    assertGet("variant2:c-df", "c", new String[] {}, variants2);
    assertGet("variant2:c-df", "c", new String[] { "*" }, variants2);
    assertGet(null, "d", new String[] { "*", "y1" }, variants2);
    // Reference following from variant 1
    assertGet("variant2:y1.c", "toVariants.c", new String[] { "**", "y1" }, variants1);
    assertGet("variant3:c-df", "toVariants.c", new String[] { "x1", "**" }, variants1);
    // variant3 by order priority
    assertGet("variant3:y1.c", "toVariants.c", new String[] { "x1", "y1" }, variants1);
    assertGet("variant3:y2.c", "toVariants.c", new String[] { "x1", "y2" }, variants1);
}
Also used : CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) QueryProfile(com.yahoo.search.query.profile.QueryProfile) QueryProfileConfigurer(com.yahoo.search.query.profile.config.QueryProfileConfigurer) Test(org.junit.Test)

Example 5 with QueryProfileConfigurer

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

the class QueryProfileConfigurationTestCase method testBug3197426.

@Test
public void testBug3197426() {
    QueryProfileConfigurer configurer = new QueryProfileConfigurer("file:" + CONFIG_DIR + "bug3197426.cfg");
    CompiledQueryProfile profile = configurer.getCurrentRegistry().getComponent("default").compile(null);
    Map<String, Object> properties = new QueryProfileProperties(profile).listProperties("source.image");
    assertEquals("yes", properties.get("mlr"));
    assertEquals("zh-Hant", properties.get("language"));
    assertEquals("tw", properties.get("custid2"));
    assertEquals("4", properties.get("hits"));
    assertEquals("0", properties.get("offset"));
    assertEquals("image", properties.get("catalog"));
    assertEquals("yahoo", properties.get("custid1"));
    assertEquals("utf-8", properties.get("encoding"));
    assertEquals("all", properties.get("imquality"));
    assertEquals("all", properties.get("dimensions"));
    assertEquals("1", properties.get("flickr"));
    assertEquals("yes", properties.get("ocr"));
}
Also used : CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) QueryProfileConfigurer(com.yahoo.search.query.profile.config.QueryProfileConfigurer) QueryProfileProperties(com.yahoo.search.query.profile.QueryProfileProperties) Test(org.junit.Test)

Aggregations

QueryProfileConfigurer (com.yahoo.search.query.profile.config.QueryProfileConfigurer)7 Test (org.junit.Test)5 CompiledQueryProfile (com.yahoo.search.query.profile.compiled.CompiledQueryProfile)4 Query (com.yahoo.search.Query)2 QueryProfile (com.yahoo.search.query.profile.QueryProfile)2 CompiledQueryProfileRegistry (com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry)2 QueryProfileProperties (com.yahoo.search.query.profile.QueryProfileProperties)1 QueryProfileRegistry (com.yahoo.search.query.profile.QueryProfileRegistry)1 FieldDescription (com.yahoo.search.query.profile.types.FieldDescription)1 QueryProfileType (com.yahoo.search.query.profile.types.QueryProfileType)1 QueryProfileTypeRegistry (com.yahoo.search.query.profile.types.QueryProfileTypeRegistry)1 QueryProfiles (com.yahoo.vespa.model.container.search.QueryProfiles)1