Search in sources :

Example 6 with Hit

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

the class FastSearcher method doPartialFill.

/**
 * Perform a partial docsum fill for a temporary result
 * representing a partition of the complete fill request.
 *
 * @param result result containing a partition of the unfilled hits
 * @param summaryClass the summary class we want to fill with
 */
protected void doPartialFill(Result result, String summaryClass) {
    if (result.isFilled(summaryClass))
        return;
    Query query = result.getQuery();
    traceQuery(getName(), "fill", query, query.getOffset(), query.getHits(), 2, quotedSummaryClass(summaryClass));
    if (wantsRPCSummaryFill(query)) {
        CompressionType compression = CompressionType.valueOf(query.properties().getString(dispatchCompression, "LZ4").toUpperCase());
        fillSDDocName(result);
        dispatcher.fill(result, summaryClass, compression);
        return;
    }
    CacheKey cacheKey = null;
    PacketWrapper packetWrapper = null;
    if (getCacheControl().useCache(query)) {
        cacheKey = fetchCacheKeyFromHits(result.hits(), summaryClass);
        if (cacheKey == null) {
            QueryPacket queryPacket = QueryPacket.create(query);
            cacheKey = new CacheKey(queryPacket);
        }
        packetWrapper = cacheLookupTwoPhase(cacheKey, result, summaryClass);
    }
    FS4Channel channel = chooseBackend(query).openChannel();
    channel.setQuery(query);
    Packet[] receivedPackets;
    try {
        DocsumPacketKey[] packetKeys;
        if (countFastHits(result) > 0) {
            packetKeys = getPacketKeys(result, summaryClass, false);
            if (packetKeys.length == 0) {
                receivedPackets = new Packet[0];
            } else {
                try {
                    receivedPackets = fetchSummaries(channel, result, summaryClass);
                } catch (InvalidChannelException e) {
                    result.hits().addError(ErrorMessage.createBackendCommunicationError("Invalid channel " + getName() + " (summary fetch)"));
                    return;
                } catch (ChannelTimeoutException e) {
                    result.hits().addError(ErrorMessage.createTimeout("timeout waiting for summaries from " + getName()));
                    return;
                } catch (IOException e) {
                    result.hits().addError(ErrorMessage.createBackendCommunicationError("IO error while talking on channel " + getName() + " (summary fetch): " + e.getMessage()));
                    return;
                }
                if (receivedPackets.length == 0) {
                    result.hits().addError(ErrorMessage.createBackendCommunicationError(getName() + " got no packets back (summary fetch)"));
                    return;
                }
            }
        } else {
            packetKeys = new DocsumPacketKey[0];
            receivedPackets = new Packet[0];
        }
        int skippedHits;
        try {
            FillHitsResult fillHitsResult = fillHits(result, receivedPackets, summaryClass);
            skippedHits = fillHitsResult.skippedHits;
            if (fillHitsResult.error != null) {
                result.hits().addError(ErrorMessage.createTimeout(fillHitsResult.error));
                return;
            }
        } catch (TimeoutException e) {
            result.hits().addError(ErrorMessage.createTimeout(e.getMessage()));
            return;
        } catch (IOException e) {
            result.hits().addError(ErrorMessage.createBackendCommunicationError("Error filling hits with summary fields, source: " + getName() + " Exception thrown: " + e.getMessage()));
            return;
        }
        if (skippedHits == 0 && packetWrapper != null) {
            cacheControl.updateCacheEntry(cacheKey, query, packetKeys, receivedPackets);
        }
        if (skippedHits > 0)
            result.hits().addError(com.yahoo.search.result.ErrorMessage.createEmptyDocsums("Missing hit data for summary '" + summaryClass + "' for " + skippedHits + " hits"));
        result.analyzeHits();
        if (query.getTraceLevel() >= 3) {
            int hitNumber = 0;
            for (Iterator<com.yahoo.search.result.Hit> i = hitIterator(result); i.hasNext(); ) {
                com.yahoo.search.result.Hit hit = i.next();
                if (!(hit instanceof FastHit))
                    continue;
                FastHit fastHit = (FastHit) hit;
                String traceMsg = "Hit: " + (hitNumber++) + " from " + (fastHit.isCached() ? "cache" : "backend");
                if (!fastHit.isFilled(summaryClass))
                    traceMsg += ". Error, hit, not filled";
                query.trace(traceMsg, false, 3);
            }
        }
    } finally {
        channel.close();
    }
}
Also used : Query(com.yahoo.search.Query) QueryPacket(com.yahoo.fs4.QueryPacket) ChannelTimeoutException(com.yahoo.fs4.ChannelTimeoutException) QueryResultPacket(com.yahoo.fs4.QueryResultPacket) QueryPacket(com.yahoo.fs4.QueryPacket) PongPacket(com.yahoo.fs4.PongPacket) BasicPacket(com.yahoo.fs4.BasicPacket) GetDocSumsPacket(com.yahoo.fs4.GetDocSumsPacket) Packet(com.yahoo.fs4.Packet) PingPacket(com.yahoo.fs4.PingPacket) IOException(java.io.IOException) InvalidChannelException(com.yahoo.fs4.mplex.InvalidChannelException) Hit(com.yahoo.search.result.Hit) Hit(com.yahoo.search.result.Hit) FS4Channel(com.yahoo.fs4.mplex.FS4Channel) ChannelTimeoutException(com.yahoo.fs4.ChannelTimeoutException) CompressionType(com.yahoo.compress.CompressionType)

Example 7 with Hit

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

the class BlendingSearcher method blendResults.

/**
 * Produce a single blended result list from a group of hitgroups.
 *
 * It is assumed that the results are ordered in hitgroups. If not, the blend will not be performed
 */
protected Result blendResults(Result result, Query q, int offset, int hits, Execution execution) {
    // Assert that there are more than one hitgroup and that there are only hitgroups on the lowest level
    boolean foundNonGroup = false;
    Iterator<Hit> hitIterator = result.hits().iterator();
    List<HitGroup> groups = new ArrayList<>();
    while (hitIterator.hasNext()) {
        Hit hit = hitIterator.next();
        if (hit instanceof HitGroup) {
            groups.add((HitGroup) hit);
            hitIterator.remove();
        } else if (!hit.isMeta()) {
            foundNonGroup = true;
        }
    }
    if (foundNonGroup) {
        result.hits().addError(ErrorMessage.createUnspecifiedError("Blendingsearcher could not blend - there are toplevel hits" + " that are not hitgroups"));
        return result;
    }
    if (groups.size() == 0) {
        return result;
    } else if (groups.size() == 1) {
        result.hits().addAll(groups.get(0).asUnorderedHits());
        result.hits().setOrderer(groups.get(0).getOrderer());
        return result;
    } else {
        if (documentId != null) {
            return blendResultsUniquely(result, q, offset, hits, groups, execution);
        } else {
            return blendResultsDirectly(result, q, offset, hits, groups, execution);
        }
    }
}
Also used : Hit(com.yahoo.search.result.Hit) HitGroup(com.yahoo.search.result.HitGroup)

Example 8 with Hit

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

the class DocumentSourceSearcher method addDefaultResults.

private void addDefaultResults() {
    Query q = new Query("?query=default");
    Result r = new Result(q);
    r.hits().add(new Hit("http://default-1.html"));
    r.hits().add(new Hit("http://default-2.html"));
    r.hits().add(new Hit("http://default-3.html"));
    r.hits().add(new Hit("http://default-4.html"));
    defaultFilledResult = r;
    addResultSet(q, r);
}
Also used : Hit(com.yahoo.search.result.Hit) Query(com.yahoo.search.Query) Result(com.yahoo.search.Result)

Example 9 with Hit

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

the class JuniperSearcher method highlight.

private void highlight(boolean bolding, Iterator<Hit> hitsToHighlight, String summaryClass, IndexFacts.Session indexFacts) {
    while (hitsToHighlight.hasNext()) {
        Hit sniffHit = hitsToHighlight.next();
        if (!(sniffHit instanceof FastHit))
            continue;
        FastHit hit = (FastHit) sniffHit;
        if (summaryClass != null && !hit.isFilled(summaryClass))
            continue;
        Object searchDefinitionField = hit.getField(MAGIC_FIELD);
        if (searchDefinitionField == null)
            continue;
        String searchDefinitionName = searchDefinitionField.toString();
        for (String fieldName : hit.fields().keySet()) {
            Index index = indexFacts.getIndex(fieldName, searchDefinitionName);
            if (index.getDynamicSummary() || index.getHighlightSummary())
                insertTags(hit.buildHitField(fieldName, true, true), bolding, index.getDynamicSummary());
        }
    }
}
Also used : FastHit(com.yahoo.prelude.fastsearch.FastHit) Hit(com.yahoo.search.result.Hit) FastHit(com.yahoo.prelude.fastsearch.FastHit) Index(com.yahoo.prelude.Index)

Example 10 with Hit

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

the class JuniperSearcher method fill.

@Override
public void fill(Result result, String summaryClass, Execution execution) {
    Result workResult = result;
    final int worstCase = workResult.getHitCount();
    final List<Hit> hits = new ArrayList<>(worstCase);
    for (final Iterator<Hit> i = workResult.hits().deepIterator(); i.hasNext(); ) {
        final Hit sniffHit = i.next();
        if (!(sniffHit instanceof FastHit))
            continue;
        final FastHit hit = (FastHit) sniffHit;
        if (hit.isFilled(summaryClass))
            continue;
        hits.add(hit);
    }
    execution.fill(workResult, summaryClass);
    highlight(workResult.getQuery().getPresentation().getBolding(), hits.iterator(), summaryClass, execution.context().getIndexFacts().newSession(result.getQuery()));
}
Also used : FastHit(com.yahoo.prelude.fastsearch.FastHit) Hit(com.yahoo.search.result.Hit) FastHit(com.yahoo.prelude.fastsearch.FastHit) ArrayList(java.util.ArrayList) 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