Search in sources :

Example 6 with Query

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

the class VespaBackEndSearcher method addUnfilledHits.

/**
 * Creates unfilled hits from a List of DocumentInfo instances. Do note
 * cacheKey should be available if a cache is active, even if the hit is not
 * created from a cache in the current call path.
 *
 * @param queryPacketData binary data from first phase of search, or null
 * @param cacheKey the key this hit should match in the packet cache, or null
 */
protected boolean addUnfilledHits(Result result, List<DocumentInfo> documents, boolean fromCache, QueryPacketData queryPacketData, CacheKey cacheKey) {
    boolean allHitsOK = true;
    Query myQuery = result.getQuery();
    for (DocumentInfo document : documents) {
        try {
            FastHit hit = new FastHit();
            hit.setQuery(myQuery);
            if (queryPacketData != null)
                hit.setQueryPacketData(queryPacketData);
            hit.setCacheKey(cacheKey);
            hit.setUseRowInIndexUri(useRowInIndexUri(result));
            hit.setFillable();
            hit.setCached(fromCache);
            extractDocumentInfo(hit, document);
            result.hits().add(hit);
        } catch (ConfigurationException e) {
            allHitsOK = false;
            getLogger().log(LogLevel.WARNING, "Skipping hit", e);
        } catch (Exception e) {
            allHitsOK = false;
            getLogger().log(LogLevel.ERROR, "Skipping malformed hit", e);
        }
    }
    return allHitsOK;
}
Also used : Query(com.yahoo.search.Query) ConfigurationException(com.yahoo.prelude.ConfigurationException) ConfigurationException(com.yahoo.prelude.ConfigurationException) IOException(java.io.IOException) DocumentInfo(com.yahoo.fs4.DocumentInfo)

Example 7 with Query

use of com.yahoo.search.Query 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 8 with Query

use of com.yahoo.search.Query 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 9 with Query

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

the class PacketDumper method handlePacket.

private void handlePacket(FS4Channel channel, BasicPacket packet, ByteBuffer serializedForm, String direction) {
    // minimize overhead when disabled:
    if (disabled)
        return;
    try {
        DataOutputStream stream = getOutputStream(packet);
        if (stream != null) {
            synchronized (stream) {
                stream.writeChars(packet.getTimestamp() + " " + direction + " packet on channel " + channel.getChannelId());
                String indent = "    ";
                Query query = channel.getQuery();
                if (query != null)
                    stream.writeChars('\n' + indent + "Query: '" + query.getModel().getQueryString());
                hexDump(indent, stream, serializedForm);
                stream.writeChar('\n');
                stream.flush();
            }
        }
    } catch (IOException e) {
        log.log(LogLevel.WARNING, "Could not log packet.", e);
    }
}
Also used : Query(com.yahoo.search.Query) DataOutputStream(java.io.DataOutputStream) IOException(java.io.IOException)

Example 10 with Query

use of com.yahoo.search.Query 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)

Aggregations

Query (com.yahoo.search.Query)689 Test (org.junit.Test)415 Result (com.yahoo.search.Result)229 Execution (com.yahoo.search.searchchain.Execution)184 Searcher (com.yahoo.search.Searcher)82 QueryProfile (com.yahoo.search.query.profile.QueryProfile)63 Hit (com.yahoo.search.result.Hit)52 Chain (com.yahoo.component.chain.Chain)47 IndexFacts (com.yahoo.prelude.IndexFacts)44 CompiledQueryProfileRegistry (com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry)37 AndItem (com.yahoo.prelude.query.AndItem)33 WordItem (com.yahoo.prelude.query.WordItem)33 FastHit (com.yahoo.prelude.fastsearch.FastHit)31 CompiledQueryProfile (com.yahoo.search.query.profile.compiled.CompiledQueryProfile)27 HitGroup (com.yahoo.search.result.HitGroup)24 Item (com.yahoo.prelude.query.Item)21 HashMap (java.util.HashMap)20 CacheKey (com.yahoo.prelude.fastsearch.CacheKey)18 GroupingRequest (com.yahoo.search.grouping.GroupingRequest)18 ArrayList (java.util.ArrayList)18