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());
}
}
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());
}
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());
}
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")));
}
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")));
}
Aggregations