Search in sources :

Example 6 with CompiledQueryProfileRegistry

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

the class XmlReadingTestCase method testQueryProfileVariants2.

@Test
public void testQueryProfileVariants2() {
    CompiledQueryProfileRegistry registry = new QueryProfileXMLReader().read("src/test/java/com/yahoo/search/query/profile/config/test/queryprofilevariants2").compile();
    CompiledQueryProfile multi = registry.getComponent("multi");
    {
        Query query = new Query(HttpRequest.createTestRequest("?queryProfile=multi", Method.GET), multi);
        query.validate();
        assertEquals("best", query.properties().get("model.queryString"));
        assertEquals("best", query.getModel().getQueryString());
    }
    {
        Query query = new Query(HttpRequest.createTestRequest("?queryProfile=multi&myindex=default", Method.GET), multi);
        query.validate();
        assertEquals("best", query.properties().get("model.queryString"));
        assertEquals("best", query.getModel().getQueryString());
        assertEquals("default", query.getModel().getDefaultIndex());
    }
    {
        Query query = new Query(HttpRequest.createTestRequest("?queryProfile=multi&myindex=default&myquery=love", Method.GET), multi);
        query.validate();
        assertEquals("love", query.properties().get("model.queryString"));
        assertEquals("love", query.getModel().getQueryString());
        assertEquals("default", query.getModel().getDefaultIndex());
    }
    {
        Query query = new Query(HttpRequest.createTestRequest("?model=querybest", Method.GET), multi);
        query.validate();
        assertEquals("best", query.getModel().getQueryString());
        assertEquals("title", query.properties().get("model.defaultIndex"));
        assertEquals("title", query.getModel().getDefaultIndex());
    }
}
Also used : 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)

Example 7 with CompiledQueryProfileRegistry

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

the class QueryFromProfileTestCase method testQueryFromProfile3.

public void testQueryFromProfile3() {
    QueryProfileRegistry registry = new QueryProfileRegistry();
    QueryProfileType rootType = new QueryProfileType("root");
    rootType.inherited().add(registry.getTypeRegistry().getComponent("native"));
    registry.getTypeRegistry().register(rootType);
    QueryProfile root = new QueryProfile("root");
    root.setType(rootType);
    registry.register(root);
    QueryProfile queryBest = new QueryProfile("querybest");
    queryBest.setType(registry.getTypeRegistry().getComponent("model"));
    queryBest.set("queryString", "best", registry);
    registry.register(queryBest);
    CompiledQueryProfileRegistry cRegistry = registry.compile();
    Query query = new Query(HttpRequest.createTestRequest("?query=overrides&model=querybest", Method.GET), cRegistry.getComponent("root"));
    assertEquals("overrides", query.properties().get("model.queryString"));
    assertEquals("overrides", query.getModel().getQueryTree().toString());
}
Also used : QueryProfile(com.yahoo.search.query.profile.QueryProfile) CompiledQueryProfileRegistry(com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry) Query(com.yahoo.search.Query) CompiledQueryProfileRegistry(com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry) QueryProfileRegistry(com.yahoo.search.query.profile.QueryProfileRegistry) QueryProfileType(com.yahoo.search.query.profile.types.QueryProfileType)

Example 8 with CompiledQueryProfileRegistry

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

the class QueryFromProfileTestCase method testQueryFromProfile2.

public void testQueryFromProfile2() {
    QueryProfileRegistry registry = new QueryProfileRegistry();
    QueryProfileType rootType = new QueryProfileType("root");
    rootType.inherited().add(registry.getTypeRegistry().getComponent("native"));
    registry.getTypeRegistry().register(rootType);
    QueryProfile root = new QueryProfile("root");
    root.setType(rootType);
    registry.register(root);
    QueryProfile queryBest = new QueryProfile("querybest");
    queryBest.setType(registry.getTypeRegistry().getComponent("model"));
    queryBest.set("queryString", "best", registry);
    registry.register(queryBest);
    CompiledQueryProfileRegistry cRegistry = registry.compile();
    Query query = new Query(HttpRequest.createTestRequest("?query=overrides&model=querybest", Method.GET), cRegistry.getComponent("root"));
    assertEquals("overrides", query.properties().get("model.queryString"));
    assertEquals("overrides", query.getModel().getQueryTree().toString());
}
Also used : QueryProfile(com.yahoo.search.query.profile.QueryProfile) CompiledQueryProfileRegistry(com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry) Query(com.yahoo.search.Query) CompiledQueryProfileRegistry(com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry) QueryProfileRegistry(com.yahoo.search.query.profile.QueryProfileRegistry) QueryProfileType(com.yahoo.search.query.profile.types.QueryProfileType)

Example 9 with CompiledQueryProfileRegistry

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

Example 10 with CompiledQueryProfileRegistry

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

the class MandatoryTestCase method testMandatoryNestedInMaps.

/**
 * Same as above except the whole thing is nested in maps
 */
@Test
public void testMandatoryNestedInMaps() {
    Fixture1 fixture = new Fixture1();
    QueryProfile topMap = new QueryProfile("topMap");
    fixture.registry.register(topMap);
    QueryProfile subMap = new QueryProfile("topSubMap");
    topMap.set("subMap", subMap, fixture.registry);
    fixture.registry.register(subMap);
    QueryProfile test = new QueryProfile("test");
    test.setType(fixture.type);
    subMap.set("test", test, fixture.registry);
    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 'subMap.test.myString' is mandatory in query profile 'topMap' but is not set", new Query(HttpRequest.createTestRequest("", Method.GET), cRegistry.getComponent("topMap")));
    // Underspecified request 2
    assertError("Incomplete query: Parameter 'subMap.test.myUserQueryProfile.myUserString' is mandatory in query profile 'topMap' but is not set", new Query(HttpRequest.createTestRequest("?subMap.test.myString=aString", Method.GET), cRegistry.getComponent("topMap")));
    // Fully specified request
    assertError(null, new Query(HttpRequest.createTestRequest("?subMap.test.myString=aString&subMap.test.myUserQueryProfile.myUserString=userString", Method.GET), cRegistry.getComponent("topMap")));
}
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

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