Search in sources :

Example 11 with Hit

use of com.yahoo.search.result.Hit 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 12 with Hit

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

the class HTTPClientSearcher method doHttpRequest.

private Hit doHttpRequest(Query query, Connection connection) {
    URI uri;
    // Create default meta hit for holding logging information
    Hit requestMeta = createRequestMeta();
    query.properties().set(REQUEST_META_CARRIER, requestMeta);
    query.trace("Created request information hit", false, 9);
    try {
        uri = getURI(query, connection);
    } catch (MalformedURLException e) {
        query.errors().add(createMalformedUrlError(query, e));
        return requestMeta;
    } catch (URISyntaxException e) {
        query.errors().add(createMalformedUrlError(query, e));
        return requestMeta;
    }
    HttpEntity entity;
    try {
        if (query.getTraceLevel() >= 1)
            query.trace("Fetching " + uri.toString(), false, 1);
        entity = getEntity(uri, requestMeta, query);
    } catch (IOException e) {
        query.errors().add(ErrorMessage.createBackendCommunicationError("Error when trying to connect to HTTP backend in " + this + " using " + connection + " for " + query + ": " + Exceptions.toMessageString(e)));
        return requestMeta;
    } catch (TimeoutException e) {
        query.errors().add(ErrorMessage.createTimeout("HTTP traffic timed out in " + this + " for " + query + ": " + e.getMessage()));
        return requestMeta;
    }
    if (entity == null) {
        query.errors().add(ErrorMessage.createBackendCommunicationError("No result from connecting to HTTP backend in " + this + " using " + connection + " for " + query));
        return requestMeta;
    }
    try {
        query = handleResponse(entity, query);
    } catch (IOException e) {
        query.errors().add(ErrorMessage.createBackendCommunicationError("Error when trying to consume input in " + this + ": " + Exceptions.toMessageString(e)));
    } finally {
        cleanupHttpEntity(entity);
    }
    return requestMeta;
}
Also used : Hit(com.yahoo.search.result.Hit) MalformedURLException(java.net.MalformedURLException) HttpEntity(org.apache.http.HttpEntity) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URI(java.net.URI)

Example 13 with Hit

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

the class Dispatcher method hitsByNode.

/**
 * Return a map of hits by their search node (partition) id
 */
private static ListMap<Integer, FastHit> hitsByNode(Result result) {
    ListMap<Integer, FastHit> hitsByPartition = new ListMap<>();
    for (Iterator<Hit> i = result.hits().unorderedDeepIterator(); i.hasNext(); ) {
        Hit h = i.next();
        if (!(h instanceof FastHit))
            continue;
        FastHit hit = (FastHit) h;
        hitsByPartition.put(hit.getDistributionKey(), hit);
    }
    return hitsByPartition;
}
Also used : FastHit(com.yahoo.prelude.fastsearch.FastHit) Hit(com.yahoo.search.result.Hit) FastHit(com.yahoo.prelude.fastsearch.FastHit) ListMap(com.yahoo.collections.ListMap)

Example 14 with Hit

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

the class PageTemplateSet method hit.

@Override
public void hit(Context context, XMLWriter writer) throws IOException {
    Hit hit = (Hit) context.get("hit");
    if (!hit.isMeta() && !writer.isIn("content"))
        writer.openTag("content");
    super.hit(context, writer);
}
Also used : Hit(com.yahoo.search.result.Hit)

Example 15 with Hit

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

the class GroupedResultTestCase method testGroupedResult.

public void testGroupedResult() {
    Result result = new Result(new Query("?query=foo"));
    HitGroup hitGroup1 = new HitGroup("group1", 300);
    hitGroup1.add(new Hit("group1.1", 200));
    HitGroup hitGroup2 = new HitGroup("group2", 600);
    Hit topLevelHit1 = new Hit("toplevel.1", 500);
    Hit topLevelHit2 = new Hit("toplevel.2", 700);
    result.hits().add(hitGroup1);
    result.hits().add(topLevelHit1);
    result.hits().add(hitGroup2);
    result.hits().add(topLevelHit2);
    hitGroup1.add(new Hit("group1.2", 800));
    hitGroup2.add(new Hit("group2.1", 800));
    hitGroup2.add(new Hit("group2.2", 300));
    hitGroup2.add(new Hit("group2.3", 500));
    // Should have 7 concrete hits, ordered as
    // toplevel.2
    // group2
    // group2.1
    // group2.3
    // group2.2
    // toplevel.1
    // group1
    // group1.2
    // group1.1
    // Assert this:
    assertEquals(7, result.getConcreteHitCount());
    assertEquals(4, result.getHitCount());
    Hit topLevel2 = result.hits().get(0);
    assertEquals("toplevel.2", topLevel2.getId().stringValue());
    HitGroup returnedGroup2 = (HitGroup) result.hits().get(1);
    assertEquals(3, returnedGroup2.getConcreteSize());
    assertEquals(3, returnedGroup2.size());
    assertEquals("group2.1", returnedGroup2.get(0).getId().stringValue());
    assertEquals("group2.3", returnedGroup2.get(1).getId().stringValue());
    assertEquals("group2.2", returnedGroup2.get(2).getId().stringValue());
    Hit topLevel1 = result.hits().get(2);
    assertEquals("toplevel.1", topLevel1.getId().stringValue());
    HitGroup returnedGroup1 = (HitGroup) result.hits().get(3);
    assertEquals(2, returnedGroup1.getConcreteSize());
    assertEquals(2, returnedGroup1.size());
    assertEquals("group1.2", returnedGroup1.get(0).getId().stringValue());
    assertEquals("group1.1", returnedGroup1.get(1).getId().stringValue());
}
Also used : Hit(com.yahoo.search.result.Hit) Query(com.yahoo.search.Query) Result(com.yahoo.search.Result) HitGroup(com.yahoo.search.result.HitGroup)

Aggregations

Hit (com.yahoo.search.result.Hit)127 Result (com.yahoo.search.Result)72 Query (com.yahoo.search.Query)52 FastHit (com.yahoo.prelude.fastsearch.FastHit)42 Test (org.junit.Test)41 Execution (com.yahoo.search.searchchain.Execution)25 HitGroup (com.yahoo.search.result.HitGroup)21 Searcher (com.yahoo.search.Searcher)17 JSONString (com.yahoo.prelude.hitfield.JSONString)13 GroupingListHit (com.yahoo.prelude.fastsearch.GroupingListHit)12 ErrorHit (com.yahoo.search.result.ErrorHit)10 Relevance (com.yahoo.search.result.Relevance)10 HashMap (java.util.HashMap)9 DocumentSourceSearcher (com.yahoo.prelude.searcher.DocumentSourceSearcher)8 Group (com.yahoo.search.grouping.result.Group)8 ComponentId (com.yahoo.component.ComponentId)7 Chain (com.yahoo.component.chain.Chain)7 FS4Hit (com.yahoo.searchlib.aggregation.FS4Hit)6 VdsHit (com.yahoo.searchlib.aggregation.VdsHit)6 GroupList (com.yahoo.search.grouping.result.GroupList)5