Search in sources :

Example 1 with Searcher

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

the class FederationSearcher method fill.

@Override
public void fill(Result result, String summaryClass, Execution execution) {
    UniqueExecutionsToResults uniqueExecutionsToResults = new UniqueExecutionsToResults();
    addResultsToFill(result.hits(), result, summaryClass, uniqueExecutionsToResults);
    Set<Entry<Chain<Searcher>, Map<Query, Result>>> resultsForAllChains = uniqueExecutionsToResults.resultsToFill.entrySet();
    int numberOfCallsToFillNeeded = 0;
    for (Entry<Chain<Searcher>, Map<Query, Result>> resultsToFillForAChain : resultsForAllChains) {
        numberOfCallsToFillNeeded += resultsToFillForAChain.getValue().size();
    }
    List<Pair<Result, FutureResult>> futureFilledResults = new ArrayList<>();
    for (Entry<Chain<Searcher>, Map<Query, Result>> resultsToFillForAChain : resultsForAllChains) {
        Chain<Searcher> chain = resultsToFillForAChain.getKey();
        Execution chainExecution = (chain == null) ? execution : new Execution(chain, execution.context());
        for (Entry<Query, Result> resultsToFillForAChainAndQuery : resultsToFillForAChain.getValue().entrySet()) {
            Result resultToFill = resultsToFillForAChainAndQuery.getValue();
            if (numberOfCallsToFillNeeded == 1) {
                chainExecution.fill(resultToFill, summaryClass);
                propagateErrors(resultToFill, result);
            } else {
                AsyncExecution asyncFill = new AsyncExecution(chainExecution);
                futureFilledResults.add(new Pair<>(resultToFill, asyncFill.fill(resultToFill, summaryClass)));
            }
        }
    }
    for (Pair<Result, FutureResult> futureFilledResult : futureFilledResults) {
        // futureFilledResult is a pair of a result to be filled and the future in which that same result is filled
        Optional<Result> filledResult = futureFilledResult.getSecond().getIfAvailable(result.getQuery().getTimeLeft(), TimeUnit.MILLISECONDS);
        if (filledResult.isPresent()) {
            // fill completed
            propagateErrors(filledResult.get(), result);
        } else {
            // fill timed out: Remove these hits as they are incomplete and may cause a race when accessed later
            result.hits().addError(futureFilledResult.getSecond().createTimeoutError());
            for (Iterator<Hit> i = futureFilledResult.getFirst().hits().unorderedDeepIterator(); i.hasNext(); ) {
                // Note that some of these hits may be filled, but as the fill thread may still be working on them
                // and we do not synchronize with it we need to discard all
                Hit removed = result.hits().remove(i.next().getId());
            }
        }
    }
}
Also used : Chain(com.yahoo.component.chain.Chain) Query(com.yahoo.search.Query) AsyncExecution(com.yahoo.search.searchchain.AsyncExecution) Searcher(com.yahoo.search.Searcher) ForkingSearcher(com.yahoo.search.searchchain.ForkingSearcher) ArrayList(java.util.ArrayList) Result(com.yahoo.search.Result) FutureResult(com.yahoo.search.searchchain.FutureResult) Entry(java.util.Map.Entry) Hit(com.yahoo.search.result.Hit) Execution(com.yahoo.search.searchchain.Execution) AsyncExecution(com.yahoo.search.searchchain.AsyncExecution) FutureResult(com.yahoo.search.searchchain.FutureResult) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap) CopyOnWriteHashMap(com.yahoo.concurrent.CopyOnWriteHashMap) Pair(com.yahoo.collections.Pair)

Example 2 with Searcher

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

the class FederationSearcher method getSearchChainGroup.

private Result getSearchChainGroup(Hit hit, Result result, UniqueExecutionsToResults uniqueExecutionsToResults) {
    @SuppressWarnings("unchecked") Chain<Searcher> chain = (Chain<Searcher>) hit.getSearcherSpecificMetaData(this);
    Query query = hit.getQuery() != null ? hit.getQuery() : result.getQuery();
    return uniqueExecutionsToResults.get(chain, query);
}
Also used : Chain(com.yahoo.component.chain.Chain) Query(com.yahoo.search.Query) Searcher(com.yahoo.search.Searcher) ForkingSearcher(com.yahoo.search.searchchain.ForkingSearcher)

Example 3 with Searcher

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

the class SearchChainTextRepresentation method outputChain.

private void outputChain(IndentStringBuilder str, Chain<Searcher> chain) {
    if (chain == null) {
        str.append(" [Unresolved Searchchain]");
    } else {
        str.append(chain.getId()).append(" [Searchchain] ");
        Block block = new Block(str);
        for (Searcher searcher : chain.components()) outputSearcher(str, searcher);
        block.close();
    }
}
Also used : ForkingSearcher(com.yahoo.search.searchchain.ForkingSearcher) Searcher(com.yahoo.search.Searcher)

Example 4 with Searcher

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

the class FastSearcherTestCase method testPing.

@Test
public void testPing() throws IOException, InterruptedException {
    Logger.getLogger(FastSearcher.class.getName()).setLevel(Level.ALL);
    BackendTestCase.MockServer server = new BackendTestCase.MockServer();
    FS4ResourcePool listeners = new FS4ResourcePool(new Fs4Config(new Fs4Config.Builder()));
    Backend backend = listeners.getBackend(server.host.getHostString(), server.host.getPort());
    FastSearcher fastSearcher = new FastSearcher(backend, new FS4ResourcePool(1), new MockDispatcher(Collections.emptyList()), new SummaryParameters(null), new ClusterParams("testhittype"), new CacheParams(0, 0.0d), documentdbInfoConfig);
    server.dispatch.packetData = BackendTestCase.PONG;
    server.dispatch.setNoChannel();
    Chain<Searcher> chain = new Chain<>(fastSearcher);
    Execution e = new Execution(chain, Execution.Context.createContextStub());
    Pong pong = e.ping(new Ping());
    assertTrue(pong.getPongPacket().isPresent());
    assertEquals(127, pong.getPongPacket().get().getDocstamp());
    backend.shutdown();
    server.dispatch.socket.close();
    server.dispatch.connection.close();
    server.worker.join();
    pong.setPingInfo("blbl");
    assertEquals("Result of pinging using blbl", pong.toString());
}
Also used : Chain(com.yahoo.component.chain.Chain) Searcher(com.yahoo.search.Searcher) Fs4Config(com.yahoo.container.search.Fs4Config) MockBackend(com.yahoo.prelude.fastsearch.test.fs4mock.MockBackend) Execution(com.yahoo.search.searchchain.Execution) Ping(com.yahoo.prelude.Ping) Pong(com.yahoo.prelude.Pong) Test(org.junit.Test)

Example 5 with Searcher

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

the class PageTemplateSearcherTestCase method testSearcher.

public void testSearcher() {
    PageTemplateSearcher s = new PageTemplateSearcher(createPageTemplateRegistry(), new FirstChoiceResolver());
    Chain<Searcher> chain = new Chain<>(s, new MockFederator());
    {
        // No template specified, should use default
        Result result = new Execution(chain, Execution.Context.createContextStub()).search(new Query("?query=foo&page.resolver=native.deterministic"));
        assertSources("source1 source2", result);
    }
    {
        Result result = new Execution(chain, Execution.Context.createContextStub()).search(new Query("?query=foo&page.id=oneSource&page.resolver=native.deterministic"));
        assertSources("source1", result);
    }
    {
        Result result = new Execution(chain, Execution.Context.createContextStub()).search(new Query("?query=foo&page.id=twoSources&model.sources=source1&page.resolver=native.deterministic"));
        assertSources("source1", result);
    }
    {
        Query query = new Query("?query=foo&page.resolver=native.deterministic");
        addIntentModelSpecifyingSource3(query);
        Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
        assertSources("source1 source2", result);
    }
    {
        Query query = new Query("?query=foo&page.id=twoSourcesAndAny&page.resolver=native.deterministic");
        addIntentModelSpecifyingSource3(query);
        Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
        assertSources("source1 source2 source3", result);
    }
    {
        Query query = new Query("?query=foo&page.id=anySource&page.resolver=native.deterministic");
        addIntentModelSpecifyingSource3(query);
        Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
        assertSources("source3", result);
    }
    {
        Query query = new Query("?query=foo&page.id=anySource&page.resolver=native.deterministic");
        Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
        assertTrue(query.getModel().getSources().isEmpty());
        assertNotNull(result.hits().get("source1"));
        assertNotNull(result.hits().get("source2"));
        assertNotNull(result.hits().get("source3"));
    }
    {
        Query query = new Query("?query=foo&page.id=choiceOfSources&page.resolver=native.deterministic");
        Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
        assertSources("source1 source2", "source2", result);
    }
    {
        Query query = new Query("?query=foo&page.id=choiceOfSources&page.resolver=test.firstChoice");
        Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
        assertSources("source1 source2", "source1", result);
    }
    {
        // Specifying two templates, should pick the last
        Query query = new Query("?query=foo&page.id=threeSources+oneSource&page.resolver=native.deterministic");
        Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
        assertSources("source1 source2 source3", "source1", result);
    }
    {
        // Specifying two templates as a list, should override the page.id setting
        Query query = new Query("?query=foo&page.id=anySource&page.resolver=native.deterministic");
        query.properties().set("page.idList", Arrays.asList("oneSource", "threeSources"));
        Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
        assertSources("source1 source2 source3", "source1 source2 source3", result);
    }
    {
        try {
            Query query = new Query("?query=foo&page.id=oneSource+choiceOfSources&page.resolver=noneSuch");
            new Execution(chain, Execution.Context.createContextStub()).search(query);
            fail("Expected exception");
        } catch (IllegalArgumentException e) {
            assertEquals("No page template resolver 'noneSuch'", e.getMessage());
        }
    }
}
Also used : Chain(com.yahoo.component.chain.Chain) Execution(com.yahoo.search.searchchain.Execution) PageTemplateSearcher(com.yahoo.search.pagetemplates.PageTemplateSearcher) Query(com.yahoo.search.Query) Searcher(com.yahoo.search.Searcher) PageTemplateSearcher(com.yahoo.search.pagetemplates.PageTemplateSearcher) Result(com.yahoo.search.Result)

Aggregations

Searcher (com.yahoo.search.Searcher)130 Result (com.yahoo.search.Result)94 Execution (com.yahoo.search.searchchain.Execution)88 Query (com.yahoo.search.Query)82 Test (org.junit.Test)74 Chain (com.yahoo.component.chain.Chain)57 FeedContext (com.yahoo.feedapi.FeedContext)20 MessagePropertyProcessor (com.yahoo.feedapi.MessagePropertyProcessor)20 NullFeedMetric (com.yahoo.feedhandler.NullFeedMetric)20 ClusterList (com.yahoo.vespaclient.ClusterList)20 Hit (com.yahoo.search.result.Hit)17 DocumentSourceSearcher (com.yahoo.search.searchchain.testutil.DocumentSourceSearcher)14 HashMap (java.util.HashMap)14 GetDocumentReply (com.yahoo.documentapi.messagebus.protocol.GetDocumentReply)13 FederationSearcher (com.yahoo.search.federation.FederationSearcher)11 FieldCollapsingSearcher (com.yahoo.prelude.searcher.FieldCollapsingSearcher)10 ArrayList (java.util.ArrayList)10 AsyncExecution (com.yahoo.search.searchchain.AsyncExecution)9 ComponentId (com.yahoo.component.ComponentId)8 FastHit (com.yahoo.prelude.fastsearch.FastHit)8