Search in sources :

Example 1 with SearchHandler

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

the class SearchHandlerTestCase method testInvalidYqlQuery.

@Test
public void testInvalidYqlQuery() throws Exception {
    IOUtils.copyDirectory(new File(testDir, "config_yql"), new File(tempDir), 1);
    generateComponentsConfigForActive();
    configurer.reloadConfig();
    SearchHandler newSearchHandler = fetchSearchHandler(configurer);
    assertTrue("Have a new instance of the search handler", searchHandler != newSearchHandler);
    try (RequestHandlerTestDriver newDriver = new RequestHandlerTestDriver(newSearchHandler)) {
        RequestHandlerTestDriver.MockResponseHandler responseHandler = newDriver.sendRequest("http://localhost/search/?yql=select%20*%20from%20foo%20where%20bar%20%3E%201453501295%27%3B");
        responseHandler.readAll();
        assertThat(responseHandler.getStatus(), is(400));
    }
}
Also used : SearchHandler(com.yahoo.search.handler.SearchHandler) RequestHandlerTestDriver(com.yahoo.container.jdisc.RequestHandlerTestDriver) File(java.io.File) Test(org.junit.Test)

Example 2 with SearchHandler

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

the class SearchHandlerTestCase method testWorkingReconfiguration.

@Test
public synchronized void testWorkingReconfiguration() throws Exception {
    assertJsonResult("http://localhost?query=abc", driver);
    // reconfiguration
    IOUtils.copyDirectory(new File(testDir, "handlers2"), new File(tempDir), 1);
    generateComponentsConfigForActive();
    configurer.reloadConfig();
    // ...and check the resulting config
    SearchHandler newSearchHandler = fetchSearchHandler(configurer);
    assertTrue("Have a new instance of the search handler", searchHandler != newSearchHandler);
    assertNotNull("Have the new search chain", fetchSearchHandler(configurer).getSearchChainRegistry().getChain("hello"));
    assertNull("Don't have the new search chain", fetchSearchHandler(configurer).getSearchChainRegistry().getChain("classLoadingError"));
    try (RequestHandlerTestDriver newDriver = new RequestHandlerTestDriver(searchHandler)) {
        assertJsonResult("http://localhost?query=abc", newDriver);
    }
}
Also used : SearchHandler(com.yahoo.search.handler.SearchHandler) RequestHandlerTestDriver(com.yahoo.container.jdisc.RequestHandlerTestDriver) File(java.io.File) Test(org.junit.Test)

Example 3 with SearchHandler

use of com.yahoo.search.handler.SearchHandler 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 4 with SearchHandler

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

the class ApplicationTest method get_search_handler.

@Test
public void get_search_handler() throws Exception {
    try (ApplicationFacade app = new ApplicationFacade(Application.fromBuilder(new Application.Builder().container("default", new Application.Builder.Container().search(true))))) {
        SearchHandler searchHandler = (SearchHandler) app.getRequestHandlerById("com.yahoo.search.handler.SearchHandler");
        assertNotNull(searchHandler);
    }
}
Also used : SearchHandler(com.yahoo.search.handler.SearchHandler) Test(org.junit.Test)

Example 5 with SearchHandler

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

the class OutputSearchChain method invoke.

public void invoke(Request request) {
    try {
        SearchHandler searchHandler = SearcherUtils.getSearchHandler();
        SearchChainRegistry searchChainRegistry = searchHandler.getSearchChainRegistry();
        SearchChain searchChain = getSearchChain(searchChainRegistry, getSearchChainName(request));
        SearchChainTextRepresentation textRepresentation = new SearchChainTextRepresentation(searchChain, searchChainRegistry);
        request.returnValues().add(new StringValue(textRepresentation.toString()));
    } catch (Exception e) {
        request.setError(1000, Exceptions.toMessageString(e));
    }
}
Also used : SearchHandler(com.yahoo.search.handler.SearchHandler) SearchChainRegistry(com.yahoo.search.searchchain.SearchChainRegistry) SearchChain(com.yahoo.search.searchchain.SearchChain) StringValue(com.yahoo.jrt.StringValue)

Aggregations

SearchHandler (com.yahoo.search.handler.SearchHandler)10 RequestHandlerTestDriver (com.yahoo.container.jdisc.RequestHandlerTestDriver)5 File (java.io.File)5 Test (org.junit.Test)4 Container (com.yahoo.container.Container)3 HandlersConfigurerTestWrapper (com.yahoo.container.core.config.testutil.HandlersConfigurerTestWrapper)3 HttpRequest (com.yahoo.container.jdisc.HttpRequest)2 HttpSearchResponse (com.yahoo.search.handler.HttpSearchResponse)2 ThreadedHttpRequestHandler (com.yahoo.container.jdisc.ThreadedHttpRequestHandler)1 RequestHandler (com.yahoo.jdisc.handler.RequestHandler)1 StringValue (com.yahoo.jrt.StringValue)1 SearchChain (com.yahoo.search.searchchain.SearchChain)1 SearchChainRegistry (com.yahoo.search.searchchain.SearchChainRegistry)1 Before (org.junit.Before)1 Ignore (org.junit.Ignore)1