Search in sources :

Example 41 with CompiledQueryProfile

use of com.yahoo.search.query.profile.compiled.CompiledQueryProfile 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 42 with CompiledQueryProfile

use of com.yahoo.search.query.profile.compiled.CompiledQueryProfile 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)

Example 43 with CompiledQueryProfile

use of com.yahoo.search.query.profile.compiled.CompiledQueryProfile 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 44 with CompiledQueryProfile

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

the class XmlReadingTestCase method testSystemtest.

/**
 * Tests a subset of the configuration in the system test of this
 */
@Test
public void testSystemtest() {
    String queryString = "?query=test";
    QueryProfileXMLReader reader = new QueryProfileXMLReader();
    CompiledQueryProfileRegistry registry = reader.read("src/test/java/com/yahoo/search/query/profile/config/test/systemtest/").compile();
    HttpRequest request = HttpRequest.createTestRequest(queryString, Method.GET);
    CompiledQueryProfile profile = registry.findQueryProfile("default");
    Query query = new Query(request, profile);
    Properties p = query.properties();
    assertEquals("test", query.getModel().getQueryString());
    assertEquals("test", p.get("query"));
    assertEquals("test", p.get("QueRY"));
    assertEquals("test", p.get("model.queryString"));
    assertEquals("bar", p.get("foo"));
    assertEquals(5, p.get("hits"));
    assertEquals("tit", p.get("subst"));
    assertEquals("le", p.get("subst.end"));
    assertEquals("title", p.get("model.defaultIndex"));
    Map<String, Object> ps = p.listProperties();
    assertEquals(6, ps.size());
    assertEquals("bar", ps.get("foo"));
    assertEquals("5", ps.get("hits"));
    assertEquals("tit", ps.get("subst"));
    assertEquals("le", ps.get("subst.end"));
    assertEquals("title", ps.get("model.defaultIndex"));
    assertEquals("test", ps.get("model.queryString"));
}
Also used : HttpRequest(com.yahoo.container.jdisc.HttpRequest) CompiledQueryProfileRegistry(com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry) CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) Query(com.yahoo.search.Query) QueryProfileXMLReader(com.yahoo.search.query.profile.config.QueryProfileXMLReader) Properties(com.yahoo.search.query.Properties) Test(org.junit.Test)

Example 45 with CompiledQueryProfile

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

the class XmlReadingTestCase method testQueryProfileVariants.

@Test
public void testQueryProfileVariants() {
    String query = "?query=test&dim1=yahoo&dim2=uk&dim3=test";
    QueryProfileXMLReader reader = new QueryProfileXMLReader();
    CompiledQueryProfileRegistry registry = reader.read("src/test/java/com/yahoo/search/query/profile/config/test/news/").compile();
    HttpRequest request = HttpRequest.createTestRequest(query, Method.GET);
    CompiledQueryProfile profile = registry.findQueryProfile("default");
    Query q = new Query(request, profile);
    assertEquals("c", q.properties().get("a.c"));
    assertEquals("b", q.properties().get("a.b"));
}
Also used : HttpRequest(com.yahoo.container.jdisc.HttpRequest) CompiledQueryProfileRegistry(com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry) CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) Query(com.yahoo.search.Query) QueryProfileXMLReader(com.yahoo.search.query.profile.config.QueryProfileXMLReader) Test(org.junit.Test)

Aggregations

CompiledQueryProfile (com.yahoo.search.query.profile.compiled.CompiledQueryProfile)48 QueryProfile (com.yahoo.search.query.profile.QueryProfile)37 BackedOverridableQueryProfile (com.yahoo.search.query.profile.BackedOverridableQueryProfile)18 Query (com.yahoo.search.Query)8 CompiledQueryProfileRegistry (com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry)8 Test (org.junit.Test)7 CompoundName (com.yahoo.processing.request.CompoundName)5 QueryProfileXMLReader (com.yahoo.search.query.profile.config.QueryProfileXMLReader)4 HashMap (java.util.HashMap)4 HttpRequest (com.yahoo.container.jdisc.HttpRequest)3 QueryProfileProperties (com.yahoo.search.query.profile.QueryProfileProperties)3 QueryProfileRegistry (com.yahoo.search.query.profile.QueryProfileRegistry)3 QueryProfileType (com.yahoo.search.query.profile.types.QueryProfileType)3 Map (java.util.Map)3 QueryProfileConfigurer (com.yahoo.search.query.profile.config.QueryProfileConfigurer)2 FieldDescription (com.yahoo.search.query.profile.types.FieldDescription)2 HashSet (java.util.HashSet)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Chain (com.yahoo.component.chain.Chain)1 Renderer (com.yahoo.processing.rendering.Renderer)1