Search in sources :

Example 71 with Hit

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

the class GroupingExecutor method fill.

@Override
public void fill(Result result, String summaryClass, Execution execution) {
    Map<String, Result> summaryMap = new HashMap<>();
    for (Iterator<Hit> it = result.hits().unorderedDeepIterator(); it.hasNext(); ) {
        Hit hit = it.next();
        Object metaData = hit.getSearcherSpecificMetaData(this);
        if (metaData != null && metaData instanceof String) {
            // Use the summary class specified by grouping, set in HitConverter, for the first fill request
            // after grouping. This assumes the first fill request is using the default summary class,
            // which may be a fragile assumption. But currently we cannot do better because the difference
            // between explicit and implicit summary class in fill is erased by the Execution.
            // 
            // We reset the summary class here such that following fill calls will execute with the
            // summary class they specify
            summaryClass = (String) metaData;
            hit.setSearcherSpecificMetaData(this, null);
        }
        Result summaryResult = summaryMap.get(summaryClass);
        if (summaryResult == null) {
            summaryResult = new Result(result.getQuery());
            summaryMap.put(summaryClass, summaryResult);
        }
        summaryResult.hits().add(hit);
    }
    for (Map.Entry<String, Result> entry : summaryMap.entrySet()) {
        Result res = entry.getValue();
        execution.fill(res, entry.getKey());
        ErrorMessage err = res.hits().getError();
        if (err != null) {
            result.hits().addError(err);
        }
    }
    Result defaultResult = summaryMap.get(ExpressionConverter.DEFAULT_SUMMARY_NAME);
    if (defaultResult != null) {
        // "default" to signal the same
        for (Hit hit : defaultResult.hits()) {
            hit.setFilled(null);
        }
    }
}
Also used : GroupingListHit(com.yahoo.prelude.fastsearch.GroupingListHit) Hit(com.yahoo.search.result.Hit) HashMap(java.util.HashMap) ErrorMessage(com.yahoo.search.result.ErrorMessage) HashMap(java.util.HashMap) Map(java.util.Map) Result(com.yahoo.search.Result)

Example 72 with Hit

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

the class HitConverter method convertFs4Hit.

private Hit convertFs4Hit(String summaryClass, FS4Hit groupHit) {
    FastHit hit = new FastHit();
    hit.setRelevance(groupHit.getRank());
    hit.setGlobalId(groupHit.getGlobalId());
    hit.setPartId(groupHit.getPath(), 0);
    hit.setDistributionKey(groupHit.getDistributionKey());
    hit.setFillable();
    hit.setSearcherSpecificMetaData(searcher, summaryClass);
    Hit ctxHit = (Hit) groupHit.getContext();
    if (ctxHit == null) {
        throw new NullPointerException("Hit has no context.");
    }
    hit.setSource(ctxHit.getSource());
    hit.setSourceNumber(ctxHit.getSourceNumber());
    hit.setQuery(ctxHit.getQuery());
    if (ctxHit instanceof GroupingListHit) {
        // in a live system the ctxHit can only by GroupingListHit, but because the code used Hit prior to version
        // 5.10 we need to check to avoid breaking existing unit tests -- both internally and with customers
        QueryPacketData queryPacketData = ((GroupingListHit) ctxHit).getQueryPacketData();
        if (queryPacketData != null) {
            hit.setQueryPacketData(queryPacketData);
        }
    }
    return hit;
}
Also used : FS4Hit(com.yahoo.searchlib.aggregation.FS4Hit) Hit(com.yahoo.search.result.Hit) GroupingListHit(com.yahoo.prelude.fastsearch.GroupingListHit) VdsHit(com.yahoo.searchlib.aggregation.VdsHit) FastHit(com.yahoo.prelude.fastsearch.FastHit) FastHit(com.yahoo.prelude.fastsearch.FastHit) QueryPacketData(com.yahoo.fs4.QueryPacketData) GroupingListHit(com.yahoo.prelude.fastsearch.GroupingListHit)

Example 73 with Hit

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

the class MockResultSearcher method search.

@Override
public Result search(Query query, Execution execution) {
    Result result = new Result(query);
    result.hits().add(new Hit("hasQuery", query));
    return result;
}
Also used : Hit(com.yahoo.search.result.Hit) Result(com.yahoo.search.Result)

Example 74 with Hit

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

the class FederationSearcher method mergeResult.

private void mergeResult(Query query, Target target, Result mergedResults, Result result) {
    target.modifyTargetResult(result);
    ComponentId searchChainId = target.getId();
    Chain<Searcher> searchChain = target.getChain();
    mergedResults.mergeWith(result);
    HitGroup group = result.hits();
    group.setId("source:" + searchChainId.getName());
    group.setSearcherSpecificMetaData(this, searchChain);
    // Set hit groups as non-meta as a default
    group.setMeta(false);
    // Set hit group as auxiliary so that it doesn't contribute to count
    group.setAuxiliary(true);
    group.setSource(searchChainId.getName());
    group.setQuery(result.getQuery());
    for (Iterator<Hit> it = group.unorderedDeepIterator(); it.hasNext(); ) {
        Hit hit = it.next();
        hit.setSearcherSpecificMetaData(this, searchChain);
        hit.setSource(searchChainId.stringValue());
        // See HTTPBackendSearcher, where this hit is created
        if (hit.isMeta() && hit.types().contains("logging")) {
            // Augment this hit with count fields
            hit.setField(LOG_COUNT_PREFIX + "deep", result.getDeepHitCount());
            hit.setField(LOG_COUNT_PREFIX + "total", result.getTotalHitCount());
            int offset = result.getQuery().getOffset();
            hit.setField(LOG_COUNT_PREFIX + "first", offset + 1);
            hit.setField(LOG_COUNT_PREFIX + "last", result.getConcreteHitCount() + offset);
        }
    }
    if (query.getTraceLevel() >= 4)
        query.trace("Got " + group.getConcreteSize() + " hits from " + group.getId(), false, 4);
    mergedResults.hits().add(group);
}
Also used : Hit(com.yahoo.search.result.Hit) Searcher(com.yahoo.search.Searcher) ForkingSearcher(com.yahoo.search.searchchain.ForkingSearcher) ComponentId(com.yahoo.component.ComponentId) HitGroup(com.yahoo.search.result.HitGroup)

Example 75 with Hit

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

the class HTTPClientSearcher method search.

/**
 * Implements a search towards the connection chosen by the cluster searcher for this query
 */
@Override
public Result search(Query query, Execution execution, Connection connection) {
    Hit requestMeta = doHttpRequest(query, connection);
    Result result = execution.search(query);
    result.hits().add(requestMeta);
    return result;
}
Also used : Hit(com.yahoo.search.result.Hit) Result(com.yahoo.search.Result)

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