Search in sources :

Example 96 with QueryProfile

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));
    }
}
Also used : QueryProfile(com.yahoo.search.query.profile.QueryProfile) Query(com.yahoo.search.Query) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Map(java.util.Map) Test(org.junit.Test)

Example 97 with QueryProfile

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));
}
Also used : QueryProfile(com.yahoo.search.query.profile.QueryProfile) Query(com.yahoo.search.Query) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 98 with QueryProfile

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"));
}
Also used : QueryProfile(com.yahoo.search.query.profile.QueryProfile) Query(com.yahoo.search.Query) Test(org.junit.Test)

Example 99 with QueryProfile

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));
}
Also used : QueryProfile(com.yahoo.search.query.profile.QueryProfile) Query(com.yahoo.search.Query) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 100 with QueryProfile

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"));
}
Also used : QueryProfile(com.yahoo.search.query.profile.QueryProfile) Query(com.yahoo.search.Query) CompiledQueryProfileRegistry(com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry) QueryProfileRegistry(com.yahoo.search.query.profile.QueryProfileRegistry)

Aggregations

QueryProfile (com.yahoo.search.query.profile.QueryProfile)161 CompiledQueryProfile (com.yahoo.search.query.profile.compiled.CompiledQueryProfile)92 Query (com.yahoo.search.Query)63 BackedOverridableQueryProfile (com.yahoo.search.query.profile.BackedOverridableQueryProfile)35 CompiledQueryProfileRegistry (com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry)28 Test (org.junit.Test)26 QueryProfileRegistry (com.yahoo.search.query.profile.QueryProfileRegistry)24 QueryProfileProperties (com.yahoo.search.query.profile.QueryProfileProperties)21 QueryProfileType (com.yahoo.search.query.profile.types.QueryProfileType)12 Properties (com.yahoo.search.query.Properties)8 FieldDescription (com.yahoo.search.query.profile.types.FieldDescription)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)5 SubstituteString (com.yahoo.search.query.profile.SubstituteString)4 QueryProfilesConfig (com.yahoo.search.query.profile.config.QueryProfilesConfig)4 Element (org.w3c.dom.Element)4 QueryException (com.yahoo.prelude.query.QueryException)3 Properties (com.yahoo.processing.request.Properties)3 QueryProfileXMLReader (com.yahoo.search.query.profile.config.QueryProfileXMLReader)3 QueryProfiles (com.yahoo.vespa.model.container.search.QueryProfiles)3 ComponentSpecification (com.yahoo.component.ComponentSpecification)2