Search in sources :

Example 6 with DocumentInfo

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

the class PacketWrapper method getDocuments.

/**
 * @return list of documents, null if not all are available
 */
public List<DocumentInfo> getDocuments(int offset, int hits) {
    // speculatively allocate list for the hits
    List<DocumentInfo> docs = new ArrayList<>(hits);
    int currentOffset = 0;
    QueryResultPacket r = getFirstResultPacket();
    if (offset >= r.getTotalDocumentCount()) {
        // offset == 0 && totalDocumentCount == 0
        return docs;
    }
    for (Iterator<BasicPacket> i = resultPackets.iterator(); i.hasNext(); ) {
        QueryResultPacket result = (QueryResultPacket) i.next();
        if (result.getOffset() > offset + currentOffset) {
            // we haven't got all the requested document info objects
            return null;
        }
        if (result.getOffset() + result.getDocumentCount() <= currentOffset + offset) {
            // no new hits available
            continue;
        }
        List<DocumentInfo> documents = result.getDocuments();
        int packetOffset = (offset + currentOffset) - result.getOffset();
        int afterLastDoc = Math.min(documents.size(), packetOffset + hits);
        for (Iterator<DocumentInfo> j = documents.subList(packetOffset, afterLastDoc).iterator(); docs.size() < hits && j.hasNext(); ++currentOffset) {
            docs.add(j.next());
        }
        if (hits == docs.size() || offset + docs.size() >= result.getTotalDocumentCount()) {
            // We have the hits we need, or there are no more hits available
            return docs;
        }
    }
    return null;
}
Also used : QueryResultPacket(com.yahoo.fs4.QueryResultPacket) BasicPacket(com.yahoo.fs4.BasicPacket) DocumentInfo(com.yahoo.fs4.DocumentInfo)

Example 7 with DocumentInfo

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

the class PacketWrapperTestCase method createQueryResultPacket.

private QueryResultPacket createQueryResultPacket(int offset, int hits, int total) {
    QueryResultPacket r = QueryResultPacket.create();
    r.setDocstamp(1);
    r.setChannel(0);
    r.setTotalDocumentCount(total);
    r.setOffset(offset);
    for (int i = 0; i < hits && i < total; ++i) {
        r.addDocument(new DocumentInfo(DocsumDefinitionTestCase.createGlobalId(offset + i), 1000 - offset - i, 1, 1));
    }
    return r;
}
Also used : QueryResultPacket(com.yahoo.fs4.QueryResultPacket) DocumentInfo(com.yahoo.fs4.DocumentInfo)

Example 8 with DocumentInfo

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

the class PacketWrapperTestCase method testPartialOverlap.

@Test
public void testPartialOverlap() {
    CacheKey key = new CacheKey(QueryPacket.create(new Query("/?query=key")));
    PacketWrapper w = createResult(key, 0, 10, 100);
    QueryResultPacket q = createQueryResultPacket(10, 10, 100);
    w.addResultPacket(q);
    // all docs at once
    List<?> l = w.getDocuments(0, 20);
    assertNotNull(l);
    assertEquals(20, l.size());
    int n = 0;
    for (Iterator<?> i = l.iterator(); i.hasNext(); ++n) {
        DocumentInfo d = (DocumentInfo) i.next();
        assertEquals(DocsumDefinitionTestCase.createGlobalId(n), d.getGlobalId());
    }
    // too far out into the result set
    l = w.getDocuments(15, 10);
    assertNull(l);
    // only from first subdivision
    l = w.getDocuments(3, 2);
    assertNotNull(l);
    assertEquals(2, l.size());
    n = 3;
    for (Iterator<?> i = l.iterator(); i.hasNext(); ++n) {
        DocumentInfo d = (DocumentInfo) i.next();
        assertEquals(DocsumDefinitionTestCase.createGlobalId(n), d.getGlobalId());
    }
    // only from second subdivision
    l = w.getDocuments(15, 5);
    assertNotNull(l);
    assertEquals(5, l.size());
    n = 15;
    for (Iterator<?> i = l.iterator(); i.hasNext(); ++n) {
        DocumentInfo d = (DocumentInfo) i.next();
        assertEquals(DocsumDefinitionTestCase.createGlobalId(n), d.getGlobalId());
    }
    // overshoot by 1
    l = w.getDocuments(15, 6);
    assertNull(l);
    // mixed subset
    l = w.getDocuments(3, 12);
    assertNotNull(l);
    assertEquals(12, l.size());
    n = 3;
    for (Iterator<?> i = l.iterator(); i.hasNext(); ++n) {
        DocumentInfo d = (DocumentInfo) i.next();
        assertEquals(DocsumDefinitionTestCase.createGlobalId(n), d.getGlobalId());
    }
}
Also used : QueryResultPacket(com.yahoo.fs4.QueryResultPacket) Query(com.yahoo.search.Query) PacketWrapper(com.yahoo.prelude.fastsearch.PacketWrapper) CacheKey(com.yahoo.prelude.fastsearch.CacheKey) DocumentInfo(com.yahoo.fs4.DocumentInfo) Test(org.junit.Test)

Example 9 with DocumentInfo

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

the class MockFSChannel method receivePackets.

public BasicPacket[] receivePackets(long timeout, int packetCount) {
    List<BasicPacket> packets = new java.util.ArrayList<>();
    if (lastReceived instanceof QueryPacket) {
        lastQueryPacket = (QueryPacket) lastReceived;
        QueryResultPacket result = QueryResultPacket.create();
        result.setDocstamp(docstamp);
        result.setChannel(0);
        result.setTotalDocumentCount(2);
        result.setOffset(lastQueryPacket.getOffset());
        if (lastQueryPacket.getOffset() == 0 && lastQueryPacket.getLastOffset() >= 1) {
            result.addDocument(new DocumentInfo(DocsumDefinitionTestCase.createGlobalId(123), 2003, 234, 1000));
        }
        if (lastQueryPacket.getOffset() <= 1 && lastQueryPacket.getLastOffset() >= 2) {
            result.addDocument(new DocumentInfo(DocsumDefinitionTestCase.createGlobalId(456), 1855, 234, 1001));
        }
        packets.add(result);
    } else if (lastReceived instanceof GetDocSumsPacket) {
        addDocsums(packets, lastQueryPacket);
    } else if (lastReceived instanceof PingPacket) {
        packets.add(new PongPacket(activeDocuments));
    }
    while (packetCount >= 0 && packets.size() > packetCount) {
        packets.remove(packets.size() - 1);
    }
    return packets.toArray(new BasicPacket[packets.size()]);
}
Also used : QueryResultPacket(com.yahoo.fs4.QueryResultPacket) BasicPacket(com.yahoo.fs4.BasicPacket) GetDocSumsPacket(com.yahoo.fs4.GetDocSumsPacket) PingPacket(com.yahoo.fs4.PingPacket) PongPacket(com.yahoo.fs4.PongPacket) QueryPacket(com.yahoo.fs4.QueryPacket) 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