Search in sources :

Example 1 with DocsumPacket

use of com.yahoo.fs4.DocsumPacket in project vespa by vespa-engine.

the class VespaBackEndSearcher method cacheLookupTwoPhase.

protected PacketWrapper cacheLookupTwoPhase(CacheKey cacheKey, Result result, String summaryClass) {
    Query query = result.getQuery();
    PacketWrapper packetWrapper = cacheControl.lookup(cacheKey, query);
    if (packetWrapper == null) {
        return null;
    }
    if (packetWrapper.getNumPackets() != 0) {
        for (Iterator<Hit> i = hitIterator(result); i.hasNext(); ) {
            Hit hit = i.next();
            if (hit instanceof FastHit) {
                FastHit fastHit = (FastHit) hit;
                DocsumPacketKey key = new DocsumPacketKey(fastHit.getGlobalId(), fastHit.getPartId(), summaryClass);
                if (fillHit(fastHit, (DocsumPacket) packetWrapper.getPacket(key), summaryClass).ok) {
                    fastHit.setCached(true);
                }
            }
        }
        result.hits().setSorted(false);
        result.analyzeHits();
    }
    return packetWrapper;
}
Also used : ErrorHit(com.yahoo.search.result.ErrorHit) Hit(com.yahoo.search.result.Hit) DocsumPacket(com.yahoo.fs4.DocsumPacket) Query(com.yahoo.search.Query)

Example 2 with DocsumPacket

use of com.yahoo.fs4.DocsumPacket in project vespa by vespa-engine.

the class VdsStreamingSearcher method doSearch2.

@Override
public Result doSearch2(Query query, QueryPacket queryPacket, CacheKey cacheKey, Execution execution) {
    // TODO refactor this method into smaller methods, it's hard to see the actual code
    lazyTrace(query, 7, "Routing to storage cluster ", getStorageClusterRouteSpec());
    if (route == null) {
        route = Route.parse(getStorageClusterRouteSpec());
    }
    lazyTrace(query, 8, "Route is ", route);
    lazyTrace(query, 7, "doSearch2(): query docsum class=", query.getPresentation().getSummary(), ", default docsum class=", getDefaultDocsumClass());
    if (query.getPresentation().getSummary() == null) {
        lazyTrace(query, 6, "doSearch2(): No summary class specified in query, using default: ", getDefaultDocsumClass());
        query.getPresentation().setSummary(getDefaultDocsumClass());
    } else {
        lazyTrace(query, 6, "doSearch2(): Summary class has been specified in query: ", query.getPresentation().getSummary());
    }
    lazyTrace(query, 8, "doSearch2(): rank properties=", query.getRanking());
    lazyTrace(query, 8, "doSearch2(): sort specification=", query.getRanking().getSorting() == null ? null : query.getRanking().getSorting().fieldOrders());
    int documentSelectionQueryParameterCount = 0;
    if (query.properties().getString(streamingUserid) != null)
        documentSelectionQueryParameterCount++;
    if (query.properties().getString(streamingGroupname) != null)
        documentSelectionQueryParameterCount++;
    if (query.properties().getString(streamingSelection) != null)
        documentSelectionQueryParameterCount++;
    if (documentSelectionQueryParameterCount != 1) {
        return new Result(query, ErrorMessage.createBackendCommunicationError("Streaming search needs one and " + "only one of these query parameters to be set: streaming.userid, streaming.groupname, " + "streaming.selection"));
    }
    query.trace("Routing to search cluster " + getSearchClusterConfigId(), 4);
    Visitor visitor = visitorFactory.createVisitor(query, getSearchClusterConfigId(), route);
    try {
        visitor.doSearch();
    } catch (ParseException e) {
        return new Result(query, ErrorMessage.createBackendCommunicationError("Failed to parse document selection string: " + e.getMessage() + "'."));
    } catch (TokenMgrError e) {
        return new Result(query, ErrorMessage.createBackendCommunicationError("Failed to tokenize document selection string: " + e.getMessage() + "'."));
    } catch (TimeoutException e) {
        return new Result(query, ErrorMessage.createTimeout(e.getMessage()));
    } catch (InterruptedException | IllegalArgumentException e) {
        return new Result(query, ErrorMessage.createBackendCommunicationError(e.getMessage()));
    }
    lazyTrace(query, 8, "offset=", query.getOffset(), ", hits=", query.getHits());
    Result result = new Result(query);
    // Sorted on rank
    List<SearchResult.Hit> hits = visitor.getHits();
    Map<String, DocumentSummary.Summary> summaryMap = visitor.getSummaryMap();
    lazyTrace(query, 7, "total hit count = ", visitor.getTotalHitCount(), ", returned hit count = ", hits.size(), ", summary count = ", summaryMap.size());
    result.setTotalHitCount(visitor.getTotalHitCount());
    query.trace(visitor.getStatistics().toString(), false, 2);
    query.getContext(true).setProperty(STREAMING_STATISTICS, visitor.getStatistics());
    Packet[] summaryPackets = new Packet[hits.size()];
    int index = 0;
    boolean skippedEarlierResult = false;
    for (SearchResult.Hit hit : hits) {
        if (!verifyDocId(hit.getDocId(), query, skippedEarlierResult)) {
            skippedEarlierResult = true;
            continue;
        }
        FastHit fastHit = buildSummaryHit(query, hit);
        result.hits().add(fastHit);
        DocumentSummary.Summary summary = summaryMap.get(hit.getDocId());
        if (summary != null) {
            DocsumPacket dp = new DocsumPacket(summary.getSummary());
            // log.log(LogLevel.SPAM, "DocsumPacket: " + dp);
            summaryPackets[index] = dp;
        } else {
            return new Result(query, ErrorMessage.createBackendCommunicationError("Did not find summary for hit with document id " + hit.getDocId()));
        }
        index++;
    }
    if (result.isFilled(query.getPresentation().getSummary())) {
        lazyTrace(query, 8, "Result is filled for summary class ", query.getPresentation().getSummary());
    } else {
        lazyTrace(query, 8, "Result is not filled for summary class ", query.getPresentation().getSummary());
    }
    List<Grouping> groupingList = visitor.getGroupings();
    lazyTrace(query, 8, "Grouping list=", groupingList);
    if (!groupingList.isEmpty()) {
        GroupingListHit groupHit = new GroupingListHit(groupingList, getDocsumDefinitionSet(query));
        result.hits().add(groupHit);
    }
    int skippedHits;
    try {
        FillHitsResult fillHitsResult = fillHits(result, summaryPackets, query.getPresentation().getSummary());
        skippedHits = fillHitsResult.skippedHits;
        if (fillHitsResult.error != null) {
            result.hits().addError(ErrorMessage.createTimeout(fillHitsResult.error));
            return result;
        }
    } catch (TimeoutException e) {
        result.hits().addError(ErrorMessage.createTimeout(e.getMessage()));
        return result;
    } catch (IOException e) {
        return new Result(query, ErrorMessage.createBackendCommunicationError("Error filling hits with summary fields"));
    }
    if (skippedHits == 0) {
        // TODO: cache results or result.analyzeHits(); ?
        query.trace("All hits have been filled", 4);
    } else {
        lazyTrace(query, 8, "Skipping some hits for query: ", result.getQuery());
    }
    lazyTrace(query, 8, "Returning result ", result);
    if (skippedHits > 0) {
        getLogger().info("skipping " + skippedHits + " hits for query: " + result.getQuery());
        result.hits().addError(com.yahoo.search.result.ErrorMessage.createTimeout("Missing hit summary data for " + skippedHits + " hits"));
    }
    return result;
}
Also used : IdString(com.yahoo.document.idstring.IdString) Result(com.yahoo.search.Result) SearchResult(com.yahoo.vdslib.SearchResult) TimeoutException(com.yahoo.prelude.fastsearch.TimeoutException) DocsumPacket(com.yahoo.fs4.DocsumPacket) QueryPacket(com.yahoo.fs4.QueryPacket) Packet(com.yahoo.fs4.Packet) DocsumPacket(com.yahoo.fs4.DocsumPacket) TokenMgrError(com.yahoo.document.select.parser.TokenMgrError) SearchResult(com.yahoo.vdslib.SearchResult) Grouping(com.yahoo.searchlib.aggregation.Grouping) IOException(java.io.IOException) GroupingListHit(com.yahoo.prelude.fastsearch.GroupingListHit) GroupingListHit(com.yahoo.prelude.fastsearch.GroupingListHit) FastHit(com.yahoo.prelude.fastsearch.FastHit) FastHit(com.yahoo.prelude.fastsearch.FastHit) DocumentSummary(com.yahoo.vdslib.DocumentSummary) ParseException(com.yahoo.document.select.parser.ParseException) DocumentSummary(com.yahoo.vdslib.DocumentSummary)

Example 3 with DocsumPacket

use of com.yahoo.fs4.DocsumPacket in project vespa by vespa-engine.

the class VespaBackEndSearcher method addCachedHits.

private boolean addCachedHits(Result result, PacketWrapper packetWrapper, String summaryClass, List<DocumentInfo> documents) {
    boolean filledAllOfEm = true;
    Query myQuery = result.getQuery();
    for (DocumentInfo document : documents) {
        FastHit hit = new FastHit();
        hit.setQuery(myQuery);
        hit.setUseRowInIndexUri(useRowInIndexUri(result));
        hit.setFillable();
        hit.setCached(true);
        extractDocumentInfo(hit, document);
        DocsumPacket docsum = (DocsumPacket) packetWrapper.getPacket(document.getGlobalId(), document.getPartId(), summaryClass);
        if (docsum != null) {
            byte[] docsumdata = docsum.getData();
            if (docsumdata.length > 0) {
                String error = decodeSummary(summaryClass, hit, docsumdata);
                if (error != null) {
                    filledAllOfEm = false;
                }
            } else {
                filledAllOfEm = false;
            }
        } else {
            filledAllOfEm = false;
        }
        result.hits().add(hit);
    }
    return filledAllOfEm;
}
Also used : DocsumPacket(com.yahoo.fs4.DocsumPacket) Query(com.yahoo.search.Query) DocumentInfo(com.yahoo.fs4.DocumentInfo)

Example 4 with DocsumPacket

use of com.yahoo.fs4.DocsumPacket in project vespa by vespa-engine.

the class VespaBackEndSearcher method fillHits.

/**
 * Fills the hits.
 *
 * @return the number of hits that we did not return data for, and an optional error message.
 *         when things are working normally we return 0.
 */
protected FillHitsResult fillHits(Result result, Packet[] packets, String summaryClass) throws IOException {
    int skippedHits = 0;
    String lastError = null;
    int packetIndex = 0;
    for (Iterator<Hit> i = hitIterator(result); i.hasNext(); ) {
        Hit hit = i.next();
        if (hit instanceof FastHit && !hit.isFilled(summaryClass)) {
            FastHit fastHit = (FastHit) hit;
            ensureInstanceOf(DocsumPacket.class, packets[packetIndex], getName());
            DocsumPacket docsum = (DocsumPacket) packets[packetIndex];
            packetIndex++;
            FillHitResult fr = fillHit(fastHit, docsum, summaryClass);
            if (!fr.ok) {
                skippedHits++;
            }
            if (fr.error != null) {
                result.hits().addError(ErrorMessage.createTimeout(fr.error));
                skippedHits++;
                lastError = fr.error;
            }
        }
    }
    result.hits().setSorted(false);
    return new FillHitsResult(skippedHits, lastError);
}
Also used : ErrorHit(com.yahoo.search.result.ErrorHit) Hit(com.yahoo.search.result.Hit) DocsumPacket(com.yahoo.fs4.DocsumPacket)

Aggregations

DocsumPacket (com.yahoo.fs4.DocsumPacket)4 Query (com.yahoo.search.Query)2 ErrorHit (com.yahoo.search.result.ErrorHit)2 Hit (com.yahoo.search.result.Hit)2 IdString (com.yahoo.document.idstring.IdString)1 ParseException (com.yahoo.document.select.parser.ParseException)1 TokenMgrError (com.yahoo.document.select.parser.TokenMgrError)1 DocumentInfo (com.yahoo.fs4.DocumentInfo)1 Packet (com.yahoo.fs4.Packet)1 QueryPacket (com.yahoo.fs4.QueryPacket)1 FastHit (com.yahoo.prelude.fastsearch.FastHit)1 GroupingListHit (com.yahoo.prelude.fastsearch.GroupingListHit)1 TimeoutException (com.yahoo.prelude.fastsearch.TimeoutException)1 Result (com.yahoo.search.Result)1 Grouping (com.yahoo.searchlib.aggregation.Grouping)1 DocumentSummary (com.yahoo.vdslib.DocumentSummary)1 SearchResult (com.yahoo.vdslib.SearchResult)1 IOException (java.io.IOException)1