Search in sources :

Example 66 with Execution

use of com.yahoo.search.searchchain.Execution in project vespa by vespa-engine.

the class ClusterSearcherTestCase method testThatWeCanSpecifyNumHitsAndHitOffset.

@Test
public void testThatWeCanSpecifyNumHitsAndHitOffset() {
    Execution ex = createExecution();
    // all types
    assertResult(9, Arrays.asList(11.0, 10.0), getResult(0, 2, ex));
    assertResult(9, Arrays.asList(10.0, 9.0), getResult(1, 2, ex));
    assertResult(9, Arrays.asList(9.0, 8.0), getResult(2, 2, ex));
    assertResult(9, Arrays.asList(8.0, 7.0), getResult(3, 2, ex));
    assertResult(9, Arrays.asList(7.0, 6.0), getResult(4, 2, ex));
    assertResult(9, Arrays.asList(6.0, 5.0), getResult(5, 2, ex));
    assertResult(9, Arrays.asList(5.0, 4.0), getResult(6, 2, ex));
    assertResult(9, Arrays.asList(4.0, 3.0), getResult(7, 2, ex));
    assertResult(9, Arrays.asList(3.0), getResult(8, 2, ex));
    assertResult(9, new ArrayList<Double>(), getResult(9, 2, ex));
    assertResult(9, Arrays.asList(11.0, 10.0, 9.0, 8.0, 7.0), getResult(0, 5, ex));
    assertResult(9, Arrays.asList(6.0, 5.0, 4.0, 3.0), getResult(5, 5, ex));
    // restrict=type1
    assertResult(3, Arrays.asList(9.0, 6.0), getResult(0, 2, "&restrict=type1", ex));
    assertResult(3, Arrays.asList(6.0, 3.0), getResult(1, 2, "&restrict=type1", ex));
    assertResult(3, Arrays.asList(3.0), getResult(2, 2, "&restrict=type1", ex));
    assertResult(3, new ArrayList<>(), getResult(3, 2, "&restrict=type1", ex));
}
Also used : Execution(com.yahoo.search.searchchain.Execution) Test(org.junit.Test)

Example 67 with Execution

use of com.yahoo.search.searchchain.Execution in project vespa by vespa-engine.

the class ClusterSearcherTestCase method testNoBackends.

@Test
public void testNoBackends() {
    ClusterSearcher cluster = new ClusterSearcher(new LinkedHashSet<>(Arrays.asList("dummy")));
    try {
        cluster.getMonitor().getConfiguration().setRequestTimeout(100);
        Execution execution = new Execution(cluster, Execution.Context.createContextStub());
        Query query = new Query("query=hello");
        query.setHits(10);
        com.yahoo.search.Result result = execution.search(query);
        assertTrue(result.hits().getError() != null);
        assertEquals("No backends in service. Try later", result.hits().getError().getMessage());
    } finally {
        cluster.deconstruct();
    }
}
Also used : Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) Test(org.junit.Test)

Example 68 with Execution

use of com.yahoo.search.searchchain.Execution in project vespa by vespa-engine.

the class SearchHandler method searchAndFill.

/**
 * Used from container SDK, for internal use only
 */
public Result searchAndFill(Query query, Chain<? extends Searcher> searchChain, SearchChainRegistry registry) {
    Result errorResult = validateQuery(query);
    if (errorResult != null)
        return errorResult;
    Renderer<Result> renderer = rendererRegistry.getRenderer(query.getPresentation().getRenderer());
    // here too in which case it will still be "unset" after we set it :-)
    if (query.getPresentation().getSummary() == null && renderer instanceof com.yahoo.search.rendering.Renderer)
        query.getPresentation().setSummary(((com.yahoo.search.rendering.Renderer) renderer).getDefaultSummaryClass());
    Execution execution = new Execution(searchChain, new Execution.Context(registry, indexFacts, specialTokens, rendererRegistry, linguistics));
    query.getModel().setExecution(execution);
    execution.trace().setForceTimestamps(query.properties().getBoolean(FORCE_TIMESTAMPS, false));
    if (query.properties().getBoolean(DETAILED_TIMING_LOGGING, false)) {
        // check and set (instead of set directly) to avoid overwriting stuff from prepareForBreakdownAnalysis()
        execution.context().setDetailedDiagnostics(true);
    }
    Result result = execution.search(query);
    if (result.getTemplating() == null)
        result.getTemplating().setRenderer(renderer);
    ensureQuerySet(result, query);
    execution.fill(result, result.getQuery().getPresentation().getSummary());
    traceExecutionTimes(query, result);
    traceVespaVersion(query);
    traceRequestAttributes(query);
    return result;
}
Also used : Execution(com.yahoo.search.searchchain.Execution) Renderer(com.yahoo.processing.rendering.Renderer) Result(com.yahoo.search.Result)

Example 69 with Execution

use of com.yahoo.search.searchchain.Execution in project vespa by vespa-engine.

the class AsyncExecutionTestCase method testSync.

public void testSync() {
    Query query = new Query("?query=test");
    Searcher searcher = new ResultProducingSearcher();
    Result result = new Execution(searcher, Execution.Context.createContextStub()).search(query);
    assertEquals(1, result.hits().size());
    assertEquals("hello", result.hits().get(0).getField("test"));
}
Also used : Execution(com.yahoo.search.searchchain.Execution) AsyncExecution(com.yahoo.search.searchchain.AsyncExecution) Query(com.yahoo.search.Query) Searcher(com.yahoo.search.Searcher) FutureResult(com.yahoo.search.searchchain.FutureResult) Result(com.yahoo.search.Result)

Example 70 with Execution

use of com.yahoo.search.searchchain.Execution in project vespa by vespa-engine.

the class AsyncExecutionTestCase method testSyncThroughSync.

public void testSyncThroughSync() {
    Query query = new Query("?query=test");
    Searcher searcher = new ResultProducingSearcher();
    Result result = new Execution(new Execution(searcher, Execution.Context.createContextStub())).search(query);
    assertEquals(1, result.hits().size());
    assertEquals("hello", result.hits().get(0).getField("test"));
}
Also used : Execution(com.yahoo.search.searchchain.Execution) AsyncExecution(com.yahoo.search.searchchain.AsyncExecution) Query(com.yahoo.search.Query) Searcher(com.yahoo.search.Searcher) FutureResult(com.yahoo.search.searchchain.FutureResult) Result(com.yahoo.search.Result)

Aggregations

Execution (com.yahoo.search.searchchain.Execution)232 Query (com.yahoo.search.Query)184 Result (com.yahoo.search.Result)127 Test (org.junit.Test)123 Searcher (com.yahoo.search.Searcher)88 Chain (com.yahoo.component.chain.Chain)59 IndexFacts (com.yahoo.prelude.IndexFacts)34 Hit (com.yahoo.search.result.Hit)25 FeedContext (com.yahoo.feedapi.FeedContext)20 MessagePropertyProcessor (com.yahoo.feedapi.MessagePropertyProcessor)20 NullFeedMetric (com.yahoo.feedhandler.NullFeedMetric)20 ClusterList (com.yahoo.vespaclient.ClusterList)20 AndItem (com.yahoo.prelude.query.AndItem)18 WordItem (com.yahoo.prelude.query.WordItem)17 ComponentId (com.yahoo.component.ComponentId)13 GetDocumentReply (com.yahoo.documentapi.messagebus.protocol.GetDocumentReply)13 FastHit (com.yahoo.prelude.fastsearch.FastHit)13 FederationSearcher (com.yahoo.search.federation.FederationSearcher)13 ArrayList (java.util.ArrayList)12 CompositeItem (com.yahoo.prelude.query.CompositeItem)11