Search in sources :

Example 21 with CompiledQueryProfileRegistry

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

the class MandatoryTestCase method testMandatoryUserProfileSetInRequest.

/**
 * Here, no user query profile is referenced in the query profile, but one is chosen in the request
 */
@Test
public void testMandatoryUserProfileSetInRequest() {
    Fixture1 fixture = new Fixture1();
    QueryProfile test = new QueryProfile("test");
    test.setType(fixture.type);
    QueryProfile myUser = new QueryProfile("user");
    myUser.setType(fixture.user);
    myUser.set("myUserInteger", 1, null);
    QueryProfileRegistry registry = new QueryProfileRegistry();
    registry.register(test);
    registry.register(myUser);
    CompiledQueryProfileRegistry cRegistry = registry.compile();
    // Underspecified request 1
    assertError("Incomplete query: Parameter 'myUserQueryProfile' is mandatory in query profile 'test' of type 'testtype' but is not set", new Query(HttpRequest.createTestRequest("?myString=aString", Method.GET), cRegistry.getComponent("test")));
    // Underspecified request 1
    assertError("Incomplete query: Parameter 'myUserQueryProfile.myUserString' is mandatory in query profile 'test' of type 'testtype' but is not set", new Query(HttpRequest.createTestRequest("?myString=aString&myUserQueryProfile=user", Method.GET), cRegistry.getComponent("test")));
    // Fully specified request
    assertError(null, new Query(HttpRequest.createTestRequest("?myString=aString&myUserQueryProfile=user&myUserQueryProfile.myUserString=userString", Method.GET), cRegistry.getComponent("test")));
}
Also used : QueryProfile(com.yahoo.search.query.profile.QueryProfile) CompiledQueryProfileRegistry(com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry) Query(com.yahoo.search.Query) QueryProfileRegistry(com.yahoo.search.query.profile.QueryProfileRegistry) CompiledQueryProfileRegistry(com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry) Test(org.junit.Test)

Example 22 with CompiledQueryProfileRegistry

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

the class MandatoryTestCase method testMandatoryFullySpecifiedQueryProfile.

@Test
public void testMandatoryFullySpecifiedQueryProfile() {
    Fixture1 fixture = new Fixture1();
    QueryProfile test = new QueryProfile("test");
    test.setType(fixture.type);
    test.set("myString", "aString", fixture.registry);
    fixture.registry.register(test);
    QueryProfile myUser = new QueryProfile("user");
    myUser.setType(fixture.user);
    myUser.set("myUserInteger", 1, fixture.registry);
    myUser.set("myUserString", 1, fixture.registry);
    test.set("myUserQueryProfile", myUser, fixture.registry);
    fixture.registry.register(myUser);
    CompiledQueryProfileRegistry cRegistry = fixture.registry.compile();
    // Fully specified request
    assertError(null, new Query(QueryTestCase.httpEncode("?queryProfile=test"), cRegistry.getComponent("test")));
}
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)

Example 23 with CompiledQueryProfileRegistry

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

the class MandatoryTestCase method testMandatoryRequestPropertiesNeeded.

@Test
public void testMandatoryRequestPropertiesNeeded() {
    Fixture1 fixture = new Fixture1();
    QueryProfile test = new QueryProfile("test");
    test.setType(fixture.type);
    fixture.registry.register(test);
    QueryProfile myUser = new QueryProfile("user");
    myUser.setType(fixture.user);
    myUser.set("myUserInteger", 1, fixture.registry);
    test.set("myUserQueryProfile", myUser, fixture.registry);
    fixture.registry.register(myUser);
    CompiledQueryProfileRegistry cRegistry = fixture.registry.compile();
    // Underspecified request 1
    assertError("Incomplete query: Parameter 'myString' is mandatory in query profile 'test' of type 'testtype' but is not set", new Query(HttpRequest.createTestRequest("", Method.GET), cRegistry.getComponent("test")));
    // Underspecified request 2
    assertError("Incomplete query: Parameter 'myUserQueryProfile.myUserString' is mandatory in query profile 'test' of type 'testtype' but is not set", new Query(HttpRequest.createTestRequest("?myString=aString", Method.GET), cRegistry.getComponent("test")));
    // Fully specified request
    assertError(null, new Query(HttpRequest.createTestRequest("?myString=aString&myUserQueryProfile.myUserString=userString", Method.GET), cRegistry.getComponent("test")));
}
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)

Example 24 with CompiledQueryProfileRegistry

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

the class MandatoryTestCase method testNonMandatoryUnderspecifiedUserProfileSetInRequest.

/**
 * Here, a partially specified query profile is added to a non-mandatory field, making the request underspecified
 */
@Test
public void testNonMandatoryUnderspecifiedUserProfileSetInRequest() {
    Fixture1 fixture = new Fixture1();
    QueryProfile test = new QueryProfile("test");
    test.setType(fixture.type);
    fixture.registry.register(test);
    QueryProfile myUser = new QueryProfile("user");
    myUser.setType(fixture.user);
    myUser.set("myUserInteger", 1, fixture.registry);
    myUser.set("myUserString", "userValue", fixture.registry);
    test.set("myUserQueryProfile", myUser, fixture.registry);
    fixture.registry.register(myUser);
    QueryProfile otherUser = new QueryProfile("otherUser");
    otherUser.setType(fixture.user);
    otherUser.set("myUserInteger", 2, fixture.registry);
    fixture.registry.register(otherUser);
    CompiledQueryProfileRegistry cRegistry = fixture.registry.compile();
    // Fully specified request
    assertError(null, new Query(HttpRequest.createTestRequest("?myString=aString", Method.GET), cRegistry.getComponent("test")));
    // Underspecified because an underspecified profile is added
    assertError("Incomplete query: Parameter 'myQueryProfile.myUserString' is mandatory in query profile 'test' of type 'testtype' but is not set", new Query(HttpRequest.createTestRequest("?myString=aString&myQueryProfile=otherUser", Method.GET), cRegistry.getComponent("test")));
    // Back to fully specified
    assertError(null, new Query(HttpRequest.createTestRequest("?myString=aString&myQueryProfile=otherUser&myQueryProfile.myUserString=userString", Method.GET), cRegistry.getComponent("test")));
}
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)

Example 25 with CompiledQueryProfileRegistry

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

Aggregations

CompiledQueryProfileRegistry (com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry)35 Query (com.yahoo.search.Query)33 QueryProfile (com.yahoo.search.query.profile.QueryProfile)22 Test (org.junit.Test)21 CompiledQueryProfile (com.yahoo.search.query.profile.compiled.CompiledQueryProfile)15 QueryProfileXMLReader (com.yahoo.search.query.profile.config.QueryProfileXMLReader)12 QueryProfileRegistry (com.yahoo.search.query.profile.QueryProfileRegistry)7 HttpRequest (com.yahoo.container.jdisc.HttpRequest)3 QueryProfileType (com.yahoo.search.query.profile.types.QueryProfileType)3 QueryProfileConfigurer (com.yahoo.search.query.profile.config.QueryProfileConfigurer)2 HashMap (java.util.HashMap)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 QueryException (com.yahoo.prelude.query.QueryException)1 CompoundName (com.yahoo.processing.request.CompoundName)1 Properties (com.yahoo.search.query.Properties)1 QueryProfileProperties (com.yahoo.search.query.profile.QueryProfileProperties)1 FieldDescription (com.yahoo.search.query.profile.types.FieldDescription)1 Map (java.util.Map)1