Search in sources :

Example 1 with QueryResultPacket

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

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

the class PacketWrapper method addResultPacket.

public void addResultPacket(QueryResultPacket resultPacket) {
    // This function only keeps the internal list sorted according
    // to offset
    int insertionPoint;
    QueryResultPacket r;
    if (resultPacket.getDocumentCount() == 0) {
        // do not add a packet which does not contain new info
        return;
    }
    insertionPoint = Collections.binarySearch(resultPackets, resultPacket, resultPacketComparator);
    if (insertionPoint < 0) {
        // new offset
        // (insertionPoint + 1) * -1;
        insertionPoint = ~insertionPoint;
        resultPackets.add(insertionPoint, resultPacket);
        cleanResultPackets();
    } else {
        // there exists a packet with same offset
        r = (QueryResultPacket) resultPackets.get(insertionPoint);
        if (resultPacket.getDocumentCount() > r.getDocumentCount()) {
            resultPackets.set(insertionPoint, resultPacket);
            cleanResultPackets();
        }
    }
}
Also used : QueryResultPacket(com.yahoo.fs4.QueryResultPacket)

Example 3 with QueryResultPacket

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

the class PacketWrapper method getPacketsSize.

public int getPacketsSize() {
    int size = 0;
    for (Iterator<BasicPacket> i = resultPackets.iterator(); i.hasNext(); ) {
        QueryResultPacket r = (QueryResultPacket) i.next();
        int l = r.getLength();
        if (l < 0) {
            log.warning("resultpacket length " + l);
            l = 10240;
        }
        size += l;
    }
    for (Iterator<BasicPacket> i = packets.values().iterator(); i.hasNext(); ) {
        BasicPacket packet = i.next();
        int l = packet.getLength();
        if (l < 0) {
            log.warning("BasicPacket length " + l);
            l = 10240;
        }
        size += l;
    }
    size += keySize;
    return size;
}
Also used : QueryResultPacket(com.yahoo.fs4.QueryResultPacket) BasicPacket(com.yahoo.fs4.BasicPacket)

Example 4 with QueryResultPacket

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

the class PacketWrapperTestCase method testPacketTrimming10.

@Test
public void testPacketTrimming10() {
    CacheKey key = new CacheKey(QueryPacket.create(new Query("/?query=key")));
    PacketWrapper w = createResult(key, 0, 10, 100);
    QueryResultPacket q = createQueryResultPacket(0, 11, 100);
    w.addResultPacket(q);
    q = createQueryResultPacket(11, 9, 100);
    w.addResultPacket(q);
    q = createQueryResultPacket(20, 10, 100);
    w.addResultPacket(q);
    assertEquals(3, w.getResultPackets().size());
    List<?> l = w.getResultPackets();
    assertEquals(0, ((QueryResultPacket) l.get(0)).getOffset());
    assertEquals(11, ((QueryResultPacket) l.get(0)).getDocumentCount());
    assertEquals(11, ((QueryResultPacket) l.get(1)).getOffset());
    assertEquals(20, ((QueryResultPacket) l.get(2)).getOffset());
}
Also used : QueryResultPacket(com.yahoo.fs4.QueryResultPacket) Query(com.yahoo.search.Query) PacketWrapper(com.yahoo.prelude.fastsearch.PacketWrapper) CacheKey(com.yahoo.prelude.fastsearch.CacheKey) Test(org.junit.Test)

Example 5 with QueryResultPacket

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

the class PacketWrapperTestCase method testPacketTrimming11.

@Test
public void testPacketTrimming11() {
    CacheKey key = new CacheKey(QueryPacket.create(new Query("/?query=key")));
    PacketWrapper w = createResult(key, 0, 10, 100);
    QueryResultPacket q = createQueryResultPacket(1, 10, 100);
    w.addResultPacket(q);
    q = createQueryResultPacket(9, 10, 100);
    w.addResultPacket(q);
    q = createQueryResultPacket(18, 10, 100);
    w.addResultPacket(q);
    q = createQueryResultPacket(27, 10, 100);
    w.addResultPacket(q);
    q = createQueryResultPacket(36, 10, 100);
    w.addResultPacket(q);
    q = createQueryResultPacket(45, 10, 100);
    w.addResultPacket(q);
    q = createQueryResultPacket(54, 10, 100);
    w.addResultPacket(q);
    q = createQueryResultPacket(63, 10, 100);
    w.addResultPacket(q);
    assertEquals(8, w.getResultPackets().size());
    q = createQueryResultPacket(10, 90, 100);
    w.addResultPacket(q);
    assertEquals(2, w.getResultPackets().size());
}
Also used : QueryResultPacket(com.yahoo.fs4.QueryResultPacket) Query(com.yahoo.search.Query) PacketWrapper(com.yahoo.prelude.fastsearch.PacketWrapper) CacheKey(com.yahoo.prelude.fastsearch.CacheKey) Test(org.junit.Test)

Aggregations

QueryResultPacket (com.yahoo.fs4.QueryResultPacket)28 Test (org.junit.Test)20 CacheKey (com.yahoo.prelude.fastsearch.CacheKey)16 PacketWrapper (com.yahoo.prelude.fastsearch.PacketWrapper)16 Query (com.yahoo.search.Query)16 BasicPacket (com.yahoo.fs4.BasicPacket)7 DocumentInfo (com.yahoo.fs4.DocumentInfo)7 ByteBuffer (java.nio.ByteBuffer)4 GetDocSumsPacket (com.yahoo.fs4.GetDocSumsPacket)2 PacketDecoder (com.yahoo.fs4.PacketDecoder)2 DecodedPacket (com.yahoo.fs4.PacketDecoder.DecodedPacket)2 PingPacket (com.yahoo.fs4.PingPacket)2 PongPacket (com.yahoo.fs4.PongPacket)2 QueryPacket (com.yahoo.fs4.QueryPacket)2 Result (com.yahoo.search.Result)2 ChannelTimeoutException (com.yahoo.fs4.ChannelTimeoutException)1 Packet (com.yahoo.fs4.Packet)1 InvalidChannelException (com.yahoo.fs4.mplex.InvalidChannelException)1