Search in sources :

Example 16 with CacheKey

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

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

the class CacheKeyTestCase method testSessionKeyIgnored.

@Test
public void testSessionKeyIgnored() {
    Query a = new Query("/?query=abcd");
    QueryPacket ap = QueryPacket.create(a);
    Query b = new Query("/?query=abcd&ranking.queryCache=true");
    QueryPacket bp = QueryPacket.create(b);
    CacheKey ak = new CacheKey(ap);
    CacheKey bk = new CacheKey(bp);
    assertEquals(ak, bk);
    assertEquals(ak.hashCode(), bk.hashCode());
    assertFalse(ap.getQueryPacketData().equals(bp.getQueryPacketData()));
}
Also used : Query(com.yahoo.search.Query) QueryPacket(com.yahoo.fs4.QueryPacket) CacheKey(com.yahoo.prelude.fastsearch.CacheKey) Test(org.junit.Test)

Example 18 with CacheKey

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

the class CacheKeyTestCase method testHitsOffsetEquality.

@Test
public void testHitsOffsetEquality() {
    Query a = new Query("/?query=abcd");
    QueryPacket p1 = QueryPacket.create(a);
    a.setWindow(100, 1000);
    QueryPacket p2 = QueryPacket.create(a);
    CacheKey k1 = new CacheKey(p1);
    CacheKey k2 = new CacheKey(p2);
    assertEquals(k1, k2);
    assertEquals(k1.hashCode(), k2.hashCode());
}
Also used : Query(com.yahoo.search.Query) QueryPacket(com.yahoo.fs4.QueryPacket) CacheKey(com.yahoo.prelude.fastsearch.CacheKey) Test(org.junit.Test)

Aggregations

CacheKey (com.yahoo.prelude.fastsearch.CacheKey)18 Query (com.yahoo.search.Query)18 Test (org.junit.Test)18 QueryResultPacket (com.yahoo.fs4.QueryResultPacket)16 PacketWrapper (com.yahoo.prelude.fastsearch.PacketWrapper)16 QueryPacket (com.yahoo.fs4.QueryPacket)2 DocumentInfo (com.yahoo.fs4.DocumentInfo)1