Search in sources :

Example 1 with HttpSearchResponse

use of com.yahoo.search.handler.HttpSearchResponse in project vespa by vespa-engine.

the class QueryProfileIntegrationTestCase method testTyped.

public void testTyped() {
    String configId = "dir:src/test/java/com/yahoo/search/query/profile/config/test/typed";
    System.setProperty("config.id", configId);
    Container container = new Container();
    HandlersConfigurerTestWrapper configurer = new HandlersConfigurerTestWrapper(container, configId);
    SearchHandler searchHandler = (SearchHandler) configurer.getRequestHandlerRegistry().getComponent(SearchHandler.class.getName());
    // Should get "default" query profile containing the "test" search chain containing the "test" searcher
    HttpRequest request = HttpRequest.createTestRequest("search", Method.GET);
    // Cast to access content directly
    HttpSearchResponse response = (HttpSearchResponse) searchHandler.handle(request);
    assertNotNull(response.getResult().hits().get("from:test"));
    // Should get the "test' query profile containing the "default" search chain containing the "default" searcher
    request = HttpRequest.createTestRequest("search?queryProfile=test", Method.GET);
    // Cast to access content directly
    response = (HttpSearchResponse) searchHandler.handle(request);
    assertNotNull(response.getResult().hits().get("from:default"));
    // Should get "default" query profile, but override the search chain to default
    request = HttpRequest.createTestRequest("search?searchChain=default", Method.GET);
    // Cast to access content directly
    response = (HttpSearchResponse) searchHandler.handle(request);
    assertNotNull(response.getResult().hits().get("from:default"));
    // Tests a profile setting hits and offset
    request = HttpRequest.createTestRequest("search?queryProfile=hitsoffset", Method.GET);
    // Cast to access content directly
    response = (HttpSearchResponse) searchHandler.handle(request);
    assertEquals(22, response.getQuery().getHits());
    assertEquals(80, response.getQuery().getOffset());
    // Tests a non-resolved profile request
    request = HttpRequest.createTestRequest("search?queryProfile=none", Method.GET);
    // Cast to access content directly
    response = (HttpSearchResponse) searchHandler.handle(request);
    assertNotNull("Got an error", response.getResult().hits().getError());
    assertEquals("Could not resolve query profile 'none'", response.getResult().hits().getError().getDetailedMessage());
    // Test overriding a sub-profile in the request
    request = HttpRequest.createTestRequest("search?queryProfile=root&sub=newsub", Method.GET);
    // Cast to access content directly
    response = (HttpSearchResponse) searchHandler.handle(request);
    assertEquals("newsubvalue1", response.getQuery().properties().get("sub.value1"));
    assertEquals("newsubvalue2", response.getQuery().properties().get("sub.value2"));
    configurer.shutdown();
}
Also used : SearchHandler(com.yahoo.search.handler.SearchHandler) HttpRequest(com.yahoo.container.jdisc.HttpRequest) Container(com.yahoo.container.Container) HandlersConfigurerTestWrapper(com.yahoo.container.core.config.testutil.HandlersConfigurerTestWrapper) HttpSearchResponse(com.yahoo.search.handler.HttpSearchResponse)

Example 2 with HttpSearchResponse

use of com.yahoo.search.handler.HttpSearchResponse in project vespa by vespa-engine.

the class SearchHandlerTestCase method testResponseBasics.

@Test
public void testResponseBasics() {
    Query q = new Query("?query=dummy&tracelevel=3");
    q.trace("nalle", 1);
    Result r = new Result(q);
    r.hits().addError(ErrorMessage.createUnspecifiedError("bamse"));
    r.hits().add(new Hit("http://localhost/dummy", 0.5));
    HttpSearchResponse s = new HttpSearchResponse(200, r, q, new DefaultRenderer());
    assertEquals("text/xml", s.getContentType());
    assertNull(s.getCoverage());
    assertEquals("query 'dummy'", s.getParsedQuery());
    assertEquals(5000, s.getTiming().getTimeout());
}
Also used : Hit(com.yahoo.search.result.Hit) Query(com.yahoo.search.Query) DefaultRenderer(com.yahoo.search.rendering.DefaultRenderer) HttpSearchResponse(com.yahoo.search.handler.HttpSearchResponse) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 3 with HttpSearchResponse

use of com.yahoo.search.handler.HttpSearchResponse in project vespa by vespa-engine.

the class QueryProfileIntegrationTestCase method testUntyped.

public void testUntyped() {
    String configId = "dir:src/test/java/com/yahoo/search/query/profile/config/test/untyped";
    System.setProperty("config.id", configId);
    Container container = new Container();
    HandlersConfigurerTestWrapper configurer = new HandlersConfigurerTestWrapper(container, configId);
    SearchHandler searchHandler = (SearchHandler) configurer.getRequestHandlerRegistry().getComponent(SearchHandler.class.getName());
    // Should get "default" query profile containing the "test" search chain containing the "test" searcher
    HttpRequest request = HttpRequest.createTestRequest("search", Method.GET);
    // Cast to access content directly
    HttpSearchResponse response = (HttpSearchResponse) searchHandler.handle(request);
    assertNotNull(response.getResult().hits().get("from:test"));
    // Should get the "test' query profile containing the "default" search chain containing the "default" searcher
    request = HttpRequest.createTestRequest("search?queryProfile=test", Method.GET);
    // Cast to access content directly
    response = (HttpSearchResponse) searchHandler.handle(request);
    assertNotNull(response.getResult().hits().get("from:default"));
    // Should get "default" query profile, but override the search chain to default
    request = HttpRequest.createTestRequest("search?searchChain=default", Method.GET);
    // Cast to access content directly
    response = (HttpSearchResponse) searchHandler.handle(request);
    assertNotNull(response.getResult().hits().get("from:default"));
    // Tests a profile setting hits and offset
    request = HttpRequest.createTestRequest("search?queryProfile=hitsoffset", Method.GET);
    // Cast to access content directly
    response = (HttpSearchResponse) searchHandler.handle(request);
    assertEquals(20, response.getQuery().getHits());
    assertEquals(80, response.getQuery().getOffset());
    // Tests a non-resolved profile request
    request = HttpRequest.createTestRequest("search?queryProfile=none", Method.GET);
    // Cast to access content directly
    response = (HttpSearchResponse) searchHandler.handle(request);
    assertNotNull("Got an error", response.getResult().hits().getError());
    assertEquals("Could not resolve query profile 'none'", response.getResult().hits().getError().getDetailedMessage());
    // Tests that properties in objects owned by query is handled correctly
    request = HttpRequest.createTestRequest("search?query=word&queryProfile=test", Method.GET);
    // Cast to access content directly
    response = (HttpSearchResponse) searchHandler.handle(request);
    assertEquals("index", response.getQuery().getModel().getDefaultIndex());
    assertEquals("index:word", response.getQuery().getModel().getQueryTree().toString());
    configurer.shutdown();
}
Also used : SearchHandler(com.yahoo.search.handler.SearchHandler) HttpRequest(com.yahoo.container.jdisc.HttpRequest) Container(com.yahoo.container.Container) HandlersConfigurerTestWrapper(com.yahoo.container.core.config.testutil.HandlersConfigurerTestWrapper) HttpSearchResponse(com.yahoo.search.handler.HttpSearchResponse)

Aggregations

HttpSearchResponse (com.yahoo.search.handler.HttpSearchResponse)3 Container (com.yahoo.container.Container)2 HandlersConfigurerTestWrapper (com.yahoo.container.core.config.testutil.HandlersConfigurerTestWrapper)2 HttpRequest (com.yahoo.container.jdisc.HttpRequest)2 SearchHandler (com.yahoo.search.handler.SearchHandler)2 Query (com.yahoo.search.Query)1 Result (com.yahoo.search.Result)1 DefaultRenderer (com.yahoo.search.rendering.DefaultRenderer)1 Hit (com.yahoo.search.result.Hit)1 Test (org.junit.Test)1