Search in sources :

Example 1 with PacketWrapper

use of com.yahoo.prelude.fastsearch.PacketWrapper 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 2 with PacketWrapper

use of com.yahoo.prelude.fastsearch.PacketWrapper 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)

Example 3 with PacketWrapper

use of com.yahoo.prelude.fastsearch.PacketWrapper in project vespa by vespa-engine.

the class PacketWrapperTestCase method testPacketTrimming4.

@Test
public void testPacketTrimming4() {
    CacheKey key = new CacheKey(QueryPacket.create(new Query("/?query=key")));
    PacketWrapper w = createResult(key, 0, 10, 100);
    QueryResultPacket q = createQueryResultPacket(5, 10, 100);
    w.addResultPacket(q);
    q = createQueryResultPacket(10, 10, 100);
    w.addResultPacket(q);
    q = createQueryResultPacket(15, 10, 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(10, ((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 4 with PacketWrapper

use of com.yahoo.prelude.fastsearch.PacketWrapper in project vespa by vespa-engine.

the class PacketWrapperTestCase method testZeroHits.

@Test
public void testZeroHits() {
    CacheKey key = new CacheKey(QueryPacket.create(new Query("/?query=key")));
    PacketWrapper w = createResult(key, 0, 10, 0);
    final Query query = new Query("/?query=key");
    query.setWindow(5, 10);
    key = new CacheKey(QueryPacket.create(query));
    QueryResultPacket q = createQueryResultPacket(5, 10, 0);
    w.addResultPacket(q);
    assertEquals(1, w.getResultPackets().size());
    List<?> l = w.getDocuments(3, 12);
    assertNotNull(l);
    assertEquals(0, l.size());
    l = w.getDocuments(0, 12);
    assertNotNull(l);
    assertEquals(0, l.size());
    l = w.getDocuments(0, 0);
    assertNotNull(l);
    assertEquals(0, l.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)

Example 5 with PacketWrapper

use of com.yahoo.prelude.fastsearch.PacketWrapper in project vespa by vespa-engine.

the class PacketWrapperTestCase method testPacketTrimming2.

@Test
public void testPacketTrimming2() {
    CacheKey key = new CacheKey(QueryPacket.create(new Query("/?query=key")));
    PacketWrapper w = createResult(key, 0, 10, 100);
    QueryResultPacket q = createQueryResultPacket(5, 10, 100);
    w.addResultPacket(q);
    q = createQueryResultPacket(50, 10, 100);
    w.addResultPacket(q);
    assertEquals(3, w.getResultPackets().size());
    List<?> l = w.getResultPackets();
    assertEquals(0, ((QueryResultPacket) l.get(0)).getOffset());
    assertEquals(5, ((QueryResultPacket) l.get(1)).getOffset());
    assertEquals(50, ((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)

Aggregations

PacketWrapper (com.yahoo.prelude.fastsearch.PacketWrapper)17 QueryResultPacket (com.yahoo.fs4.QueryResultPacket)16 CacheKey (com.yahoo.prelude.fastsearch.CacheKey)16 Query (com.yahoo.search.Query)16 Test (org.junit.Test)16 BasicPacket (com.yahoo.fs4.BasicPacket)1 DocumentInfo (com.yahoo.fs4.DocumentInfo)1 ByteBuffer (java.nio.ByteBuffer)1