use of com.yahoo.search.query.profile.QueryProfile in project vespa by vespa-engine.
the class QueryTestCase method testQueryPropertyListingAndTrace.
@Test
public void testQueryPropertyListingAndTrace() {
QueryProfile defaultProfile = new QueryProfile("default");
defaultProfile.setDimensions(new String[] { "x" });
defaultProfile.set("a.b", "a.b-x1-value", new String[] { "x1" }, null);
defaultProfile.set("a.b", "a.b-x2-value", new String[] { "x2" }, null);
defaultProfile.freeze();
{
Query q = new Query(QueryTestCase.httpEncode("?tracelevel=9&x=x1"), defaultProfile.compile(null));
Map<String, Object> propertyList = q.properties().listProperties();
assertEquals(3, propertyList.size());
assertEquals("a.b-x1-value", propertyList.get("a.b"));
String trace = q.getContext(false).getTrace().toString();
String[] traceLines = trace.split("\n");
assertTrue(contains("a.b=a.b-x1-value (value from query profile)", traceLines));
}
{
Query q = new Query(QueryTestCase.httpEncode("?tracelevel=9&x=x1"), defaultProfile.compile(null));
Map<String, Object> propertyList = q.properties().listProperties("a");
assertEquals(1, propertyList.size());
assertEquals("a.b-x1-value", propertyList.get("b"));
}
{
Query q = new Query(QueryTestCase.httpEncode("?tracelevel=9&x=x2"), defaultProfile.compile(null));
Map<String, Object> propertyList = q.properties().listProperties();
assertEquals(3, propertyList.size());
assertEquals("a.b-x2-value", propertyList.get("a.b"));
String trace = q.getContext(false).getTrace().toString();
String[] traceLines = trace.split("\n");
assertTrue(contains("a.b=a.b-x2-value (value from query profile)", traceLines));
}
}
use of com.yahoo.search.query.profile.QueryProfile in project vespa by vespa-engine.
the class QueryTestCase method testQueryPropertyResolveTracing.
@Test
public void testQueryPropertyResolveTracing() {
QueryProfile testProfile = new QueryProfile("test");
testProfile.setOverridable("u", false, null);
testProfile.set("d", "e", null);
testProfile.set("u", "11", null);
testProfile.set("foo.bar", "wiz", null);
Query q = new Query(QueryTestCase.httpEncode("?query=a:>5&a=b&traceLevel=5&sources=a,b&u=12&foo.bar2=wiz2&c.d=foo&queryProfile=test"), testProfile.compile(null));
String trace = q.getContext(false).getTrace().toString();
String[] traceLines = trace.split("\n");
for (String line : traceLines) System.out.println(line);
assertTrue(contains("query=a:>5 (value from request)", traceLines));
assertTrue(contains("traceLevel=5 (value from request)", traceLines));
assertTrue(contains("a=b (value from request)", traceLines));
assertTrue(contains("sources=[a, b] (value from request)", traceLines));
assertTrue(contains("d=e (value from query profile)", traceLines));
assertTrue(contains("u=11 (value from query profile - unoverridable, ignoring request value)", traceLines));
}
use of com.yahoo.search.query.profile.QueryProfile in project vespa by vespa-engine.
the class QueryTestCase method testQueryPropertyReplacement.
@Test
public void testQueryPropertyReplacement() {
QueryProfile defaultProfile = new QueryProfile("default");
defaultProfile.set("model.queryString", "myquery", (QueryProfileRegistry) null);
defaultProfile.set("queryUrl", "http://provider:80?query=%{model.queryString}", (QueryProfileRegistry) null);
defaultProfile.freeze();
Query q1 = new Query(QueryTestCase.httpEncode(""), defaultProfile.compile(null));
assertEquals("myquery", q1.getModel().getQueryString());
assertEquals("http://provider:80?query=myquery", q1.properties().get("queryUrl"));
Query q2 = new Query(QueryTestCase.httpEncode("?model.queryString=foo"), defaultProfile.compile(null));
assertEquals("foo", q2.getModel().getQueryString());
assertEquals("http://provider:80?query=foo", q2.properties().get("queryUrl"));
Query q3 = new Query(QueryTestCase.httpEncode("?query=foo"), defaultProfile.compile(null));
assertEquals("foo", q3.getModel().getQueryString());
assertEquals("http://provider:80?query=foo", q3.properties().get("queryUrl"));
Query q4 = new Query(QueryTestCase.httpEncode("?query=foo"), defaultProfile.compile(null));
q4.getModel().setQueryString("bar");
assertEquals("http://provider:80?query=bar", q4.properties().get("queryUrl"));
}
use of com.yahoo.search.query.profile.QueryProfile in project vespa by vespa-engine.
the class QueryTestCase method testQueryPropertyResolveTracing2.
@Test
public void testQueryPropertyResolveTracing2() {
QueryProfile defaultProfile = new QueryProfile("default");
defaultProfile.freeze();
Query q = new Query(QueryTestCase.httpEncode("?query=dvd&a.b=foo&tracelevel=9"), defaultProfile.compile(null));
String trace = q.getContext(false).getTrace().toString();
String[] traceLines = trace.split("\n");
assertTrue(contains("query=dvd (value from request)", traceLines));
assertTrue(contains("a.b=foo (value from request)", traceLines));
}
use of com.yahoo.search.query.profile.QueryProfile in project vespa by vespa-engine.
the class OverrideTestCase method testSimpleUnoverridable.
/**
* Check that a simple non-overridable string cannot be overridden
*/
public void testSimpleUnoverridable() {
QueryProfileRegistry registry = new QueryProfileRegistry();
QueryProfile test = new QueryProfile("test");
test.setType(type);
test.set("myString", "finalString", (QueryProfileRegistry) null);
registry.register(test);
registry.freeze();
// Assert request assignment does not work
Query query = new Query(HttpRequest.createTestRequest("?myString=newValue", Method.GET), registry.compile().getComponent("test"));
assertEquals(0, query.errors().size());
assertEquals("finalString", query.properties().get("myString"));
// Assert direct assignment does not work
query.properties().set("myString", "newValue");
assertEquals("finalString", query.properties().get("myString"));
}
Aggregations