Search in sources :

Example 1 with DocumentInfo

use of com.yahoo.fs4.DocumentInfo 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 2 with DocumentInfo

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

the class VespaBackEndSearcher method cacheLookupFirstPhase.

private Result cacheLookupFirstPhase(CacheKey key, QueryPacketData queryPacketData, Query query, int offset, int hits, String summaryClass) {
    PacketWrapper packetWrapper = cacheControl.lookup(key, query);
    if (packetWrapper == null)
        return null;
    // Check if the cache entry contains the requested hits
    List<DocumentInfo> documents = packetWrapper.getDocuments(offset, hits);
    if (documents == null)
        return null;
    if (query.getPresentation().getSummary() == null)
        query.getPresentation().setSummary(getDefaultDocsumClass());
    Result result = new Result(query);
    QueryResultPacket resultPacket = packetWrapper.getFirstResultPacket();
    addMetaInfo(query, queryPacketData, resultPacket, result, true);
    if (packetWrapper.getNumPackets() == 0)
        addUnfilledHits(result, documents, true, queryPacketData, key);
    else
        addCachedHits(result, packetWrapper, summaryClass, documents);
    return result;
}
Also used : QueryResultPacket(com.yahoo.fs4.QueryResultPacket) DocumentInfo(com.yahoo.fs4.DocumentInfo) Result(com.yahoo.search.Result)

Example 3 with DocumentInfo

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

the class QueryResultTestCase method testDecodeQueryResultMoreHits.

@Test
public void testDecodeQueryResultMoreHits() {
    byte[] packetData = new byte[] { 0, 0, 0, 100, 0, 0, 0, 217 - 256, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 5, 0x40, 0x39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 111, 0, 6, 0, 5, 0, 0, 0, 0, 0, 0, 0, 89, 0, 0, 0, 0, 0, 0, 0, 90, 0, 0, 0, 0, 0, 0, 0, 91, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0x40, 0x37, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 36, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0x40, 0x35, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 37 };
    ByteBuffer buffer = ByteBuffer.allocate(200);
    buffer.put(packetData);
    buffer.flip();
    BasicPacket packet = PacketDecoder.decode(buffer);
    assertTrue(packet instanceof QueryResultPacket);
    QueryResultPacket result = (QueryResultPacket) packet;
    assertEquals(2, result.getDocuments().size());
    DocumentInfo document1 = result.getDocuments().get(0);
    assertEquals(gid1, document1.getGlobalId());
    DocumentInfo document2 = result.getDocuments().get(1);
    assertEquals(gid2, document2.getGlobalId());
    assertEquals(6, result.getNodesQueried());
    assertEquals(5, result.getNodesReplied());
}
Also used : QueryResultPacket(com.yahoo.fs4.QueryResultPacket) BasicPacket(com.yahoo.fs4.BasicPacket) ByteBuffer(java.nio.ByteBuffer) DocumentInfo(com.yahoo.fs4.DocumentInfo) Test(org.junit.Test)

Example 4 with DocumentInfo

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

the class QueryResultTestCase method testDecodeQueryResultX.

@Test
public void testDecodeQueryResultX() {
    byte[] packetData = new byte[] { 0, 0, 0, 100, 0, 0, 0, 217 - 256, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 5, 0x40, 0x39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 111, 0, 0, 0, 0, 0, 0, 0, 89, 0, 0, 0, 0, 0, 0, 0, 90, 0, 0, 0, 0, 0, 0, 0, 91, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0x40, 0x37, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 36, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0x40, 0x35, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 37 };
    ByteBuffer buffer = ByteBuffer.allocate(200);
    buffer.put(packetData);
    buffer.flip();
    BasicPacket packet = PacketDecoder.decode(buffer);
    assertTrue(packet instanceof QueryResultPacket);
    QueryResultPacket result = (QueryResultPacket) packet;
    assertTrue(result.getMldFeature());
    assertEquals(5, result.getTotalDocumentCount());
    assertEquals(25, result.getMaxRank());
    assertEquals(111, result.getDocstamp());
    assertEquals(89, result.getCoverageDocs());
    assertEquals(90, result.getActiveDocs());
    assertEquals(91, result.getSoonActiveDocs());
    assertEquals(1, result.getDegradedReason());
    assertEquals(2, result.getDocuments().size());
    DocumentInfo document1 = result.getDocuments().get(0);
    assertEquals(gid1, document1.getGlobalId());
    assertEquals(23.0, document1.getMetric(), delta);
    assertEquals(7, document1.getPartId());
    assertEquals(36, document1.getDistributionKey());
    DocumentInfo document2 = result.getDocuments().get(1);
    assertEquals(gid2, document2.getGlobalId());
    assertEquals(21.0, document2.getMetric(), delta);
    assertEquals(8, document2.getPartId());
    assertEquals(37, document2.getDistributionKey());
}
Also used : QueryResultPacket(com.yahoo.fs4.QueryResultPacket) BasicPacket(com.yahoo.fs4.BasicPacket) ByteBuffer(java.nio.ByteBuffer) DocumentInfo(com.yahoo.fs4.DocumentInfo) Test(org.junit.Test)

Example 5 with DocumentInfo

use of com.yahoo.fs4.DocumentInfo 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)

Aggregations

DocumentInfo (com.yahoo.fs4.DocumentInfo)9 QueryResultPacket (com.yahoo.fs4.QueryResultPacket)7 BasicPacket (com.yahoo.fs4.BasicPacket)4 Query (com.yahoo.search.Query)3 Test (org.junit.Test)3 ByteBuffer (java.nio.ByteBuffer)2 DocsumPacket (com.yahoo.fs4.DocsumPacket)1 GetDocSumsPacket (com.yahoo.fs4.GetDocSumsPacket)1 PingPacket (com.yahoo.fs4.PingPacket)1 PongPacket (com.yahoo.fs4.PongPacket)1 QueryPacket (com.yahoo.fs4.QueryPacket)1 ConfigurationException (com.yahoo.prelude.ConfigurationException)1 CacheKey (com.yahoo.prelude.fastsearch.CacheKey)1 PacketWrapper (com.yahoo.prelude.fastsearch.PacketWrapper)1 Result (com.yahoo.search.Result)1 IOException (java.io.IOException)1