Search in sources :

Example 6 with SearchHandler

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

the class SearcherUtils method getSearchHandler.

// Return value is never null
static SearchHandler getSearchHandler() {
    SearchHandler searchHandler = (SearchHandler) Container.get().getRequestHandlerRegistry().getComponent("com.yahoo.search.handler.SearchHandler");
    ensureNotNull("The standard search handler is not available.", searchHandler);
    return searchHandler;
}
Also used : SearchHandler(com.yahoo.search.handler.SearchHandler)

Example 7 with SearchHandler

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

the class SearchHandlerTestCase method testFailedReconfiguration.

@Test
// TODO: Must be done at the ConfiguredApplication level, not handlers configurer? Also, this must be rewritten as the above
@Ignore
public synchronized void testFailedReconfiguration() throws Exception {
    assertXmlResult(driver);
    // attempt reconfiguration
    IOUtils.copyDirectory(new File(testDir, "handlersInvalid"), new File(tempDir), 1);
    generateComponentsConfigForActive();
    configurer.reloadConfig();
    SearchHandler newSearchHandler = fetchSearchHandler(configurer);
    RequestHandler newMockHandler = configurer.getRequestHandlerRegistry().getComponent("com.yahoo.search.handler.test.MockHandler");
    assertTrue("Reconfiguration failed: Kept the existing instance of the search handler", searchHandler == newSearchHandler);
    assertNull("Reconfiguration failed: No mock handler", newMockHandler);
    try (RequestHandlerTestDriver newDriver = new RequestHandlerTestDriver(searchHandler)) {
        assertXmlResult(newDriver);
    }
}
Also used : SearchHandler(com.yahoo.search.handler.SearchHandler) RequestHandler(com.yahoo.jdisc.handler.RequestHandler) ThreadedHttpRequestHandler(com.yahoo.container.jdisc.ThreadedHttpRequestHandler) RequestHandlerTestDriver(com.yahoo.container.jdisc.RequestHandlerTestDriver) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with SearchHandler

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

the class SearchHandlerTestCase method startUp.

@Before
public void startUp() throws IOException {
    File cfgDir = tempfolder.newFolder("SearchHandlerTestCase");
    tempDir = cfgDir.getAbsolutePath();
    configId = "dir:" + tempDir;
    // make configs active
    IOUtils.copyDirectory(new File(testDir), cfgDir, 1);
    generateComponentsConfigForActive();
    configurer = new HandlersConfigurerTestWrapper(new Container(), configId);
    searchHandler = (SearchHandler) configurer.getRequestHandlerRegistry().getComponent(SearchHandler.class.getName());
    driver = new RequestHandlerTestDriver(searchHandler);
}
Also used : SearchHandler(com.yahoo.search.handler.SearchHandler) Container(com.yahoo.container.Container) HandlersConfigurerTestWrapper(com.yahoo.container.core.config.testutil.HandlersConfigurerTestWrapper) RequestHandlerTestDriver(com.yahoo.container.jdisc.RequestHandlerTestDriver) File(java.io.File) Before(org.junit.Before)

Example 9 with SearchHandler

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

the class SearchHandlerTestCase method driverWithConfig.

private RequestHandlerTestDriver driverWithConfig(String configDirectory) throws Exception {
    IOUtils.copyDirectory(new File(testDir, configDirectory), new File(tempDir), 1);
    generateComponentsConfigForActive();
    configurer.reloadConfig();
    SearchHandler newSearchHandler = fetchSearchHandler(configurer);
    assertTrue("Should have a new instance of the search handler", searchHandler != newSearchHandler);
    return new RequestHandlerTestDriver(newSearchHandler);
}
Also used : SearchHandler(com.yahoo.search.handler.SearchHandler) RequestHandlerTestDriver(com.yahoo.container.jdisc.RequestHandlerTestDriver) File(java.io.File)

Example 10 with SearchHandler

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

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