Search in sources :

Example 1 with SessionId

use of com.yahoo.search.query.SessionId in project vespa by vespa-engine.

the class FastSearcherTestCase method testThatPropertiesAreReencoded.

@Test
public void testThatPropertiesAreReencoded() throws Exception {
    FastSearcher fastSearcher = createFastSearcher();
    // Default cache =100MB
    assertEquals(100, fastSearcher.getCacheControl().capacity());
    Query query = new Query("?query=ignored");
    query.getRanking().setQueryCache(true);
    Result result = doSearch(fastSearcher, query, 0, 10);
    Execution execution = new Execution(chainedAsSearchChain(fastSearcher), Execution.Context.createContextStub());
    assertEquals(2, result.getHitCount());
    execution.fill(result);
    BasicPacket receivedPacket = mockBackend.getChannel().getLastReceived();
    ByteBuffer buf = ByteBuffer.allocate(1000);
    receivedPacket.encode(buf);
    buf.flip();
    byte[] actual = new byte[buf.remaining()];
    buf.get(actual);
    SessionId sessionId = query.getSessionId(false);
    byte IGNORE = 69;
    ByteBuffer answer = ByteBuffer.allocate(1024);
    answer.put(new byte[] { 0, 0, 0, (byte) (145 + sessionId.asUtf8String().getByteLength()), 0, 0, 0, -37, 0, 0, 48, 17, 0, 0, 0, 0, // query timeout
    IGNORE, IGNORE, IGNORE, IGNORE, // "default" - rank profile
    7, 'd', 'e', 'f', 'a', 'u', 'l', 't', 0, 0, 0, 0x03, // 3 property entries (rank, match, caches)
    0, 0, 0, 3, // rank: sessionId => qrserver.0.XXXXXXXXXXXXX.0
    0, 0, 0, 4, 'r', 'a', 'n', 'k', 0, 0, 0, 1, 0, 0, 0, 9, 's', 'e', 's', 's', 'i', 'o', 'n', 'I', 'd' });
    answer.putInt(sessionId.asUtf8String().getBytes().length);
    answer.put(sessionId.asUtf8String().getBytes());
    answer.put(new byte[] { // match: documentdb.searchdoctype => test
    0, 0, 0, 5, 'm', 'a', 't', 'c', 'h', 0, 0, 0, 1, 0, 0, 0, 24, 'd', 'o', 'c', 'u', 'm', 'e', 'n', 't', 'd', 'b', '.', 's', 'e', 'a', 'r', 'c', 'h', 'd', 'o', 'c', 't', 'y', 'p', 'e', 0, 0, 0, 4, 't', 'e', 's', 't', // sessionId => qrserver.0.XXXXXXXXXXXXX.0
    0, 0, 0, 6, 'c', 'a', 'c', 'h', 'e', 's', 0, 0, 0, 1, 0, 0, 0, 5, 'q', 'u', 'e', 'r', 'y', 0, 0, 0, 4, 't', 'r', 'u', 'e', // flags
    0, 0, 0, 2 });
    byte[] expected = new byte[answer.position()];
    answer.flip();
    answer.get(expected);
    assertEquals(expected.length, actual.length);
    for (int i = 0; i < expected.length; ++i) {
        if (expected[i] == IGNORE) {
            actual[i] = IGNORE;
        }
    }
    assertArrayEquals(expected, actual);
}
Also used : Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) ByteBuffer(java.nio.ByteBuffer) SessionId(com.yahoo.search.query.SessionId) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 2 with SessionId

use of com.yahoo.search.query.SessionId in project vespa by vespa-engine.

the class QueryTestCase method testThatSessionIdIsUniquePerQuery.

@Test
public void testThatSessionIdIsUniquePerQuery() {
    Query q = new Query();
    assertNull(q.getSessionId(false));
    assertNull(q.getSessionId(false));
    SessionId s1 = q.getSessionId(true);
    assertNotNull(s1);
    SessionId s2 = q.getSessionId(true);
    assertNotSame(s1, s2);
    assertEquals(s1, s2);
    assertEquals(s1.toString(), s2.toString());
    Query q2 = new Query();
    assertNotEquals(q.getSessionId(false), q2.getSessionId(true));
    assertNotEquals(q.getSessionId(false).toString(), q2.getSessionId(true).toString());
}
Also used : Query(com.yahoo.search.Query) SessionId(com.yahoo.search.query.SessionId) Test(org.junit.Test)

Example 3 with SessionId

use of com.yahoo.search.query.SessionId in project vespa by vespa-engine.

the class GetDocSumsPacketTestCase method requireThatSessionIdIsEncodedAsPropertyWhenUsingSearchSession.

@Test
public void requireThatSessionIdIsEncodedAsPropertyWhenUsingSearchSession() throws BufferTooSmallException {
    Result result = new Result(new Query("?query=foo"));
    // create session id.
    SessionId sessionId = result.getQuery().getSessionId(true);
    result.getQuery().getRanking().setQueryCache(true);
    FastHit hit = new FastHit();
    result.hits().add(hit);
    ByteBuffer answer = ByteBuffer.allocate(1024);
    // assertEquals(0, sessionId.asUtf8String().getByteLength());
    answer.put(new byte[] { 0, 0, 0, (byte) (107 + sessionId.asUtf8String().getByteLength()), 0, 0, 0, -37, 0, 0, 56, 17, 0, 0, 0, 0, // query timeout
    IGNORE, IGNORE, IGNORE, IGNORE, // "default" - rank profile
    7, 'd', 'e', 'f', 'a', 'u', 'l', 't', 0, 0, 0, 0x03, // "default" - summaryclass
    0, 0, 0, 7, 'd', 'e', 'f', 'a', 'u', 'l', 't', // 2 property entries
    0, 0, 0, 2, // rank: sessionId => qrserver.0.XXXXXXXXXXXXX.0
    0, 0, 0, 4, 'r', 'a', 'n', 'k', 0, 0, 0, 1, 0, 0, 0, 9, 's', 'e', 's', 's', 'i', 'o', 'n', 'I', 'd' });
    answer.putInt(sessionId.asUtf8String().getByteLength());
    answer.put(sessionId.asUtf8String().getBytes());
    answer.put(new byte[] { // caches: features => true
    0, 0, 0, 6, 'c', 'a', 'c', 'h', 'e', 's', 0, 0, 0, 1, 0, 0, 0, 5, 'q', 'u', 'e', 'r', 'y', 0, 0, 0, 4, 't', 'r', 'u', 'e', // flags
    0, 0, 0, 2 });
    byte[] expected = new byte[answer.position()];
    answer.flip();
    answer.get(expected);
    assertPacket(false, result, expected);
}
Also used : FastHit(com.yahoo.prelude.fastsearch.FastHit) Query(com.yahoo.search.Query) SessionId(com.yahoo.search.query.SessionId) ByteBuffer(java.nio.ByteBuffer) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 4 with SessionId

use of com.yahoo.search.query.SessionId in project vespa by vespa-engine.

the class QueryTestCase method testThatSessionIdIsUniquePerRankProfilePerQuery.

@Test
public void testThatSessionIdIsUniquePerRankProfilePerQuery() {
    Query q = new Query();
    SessionId s1 = q.getSessionId(true);
    q.getRanking().setProfile("my-profile");
    SessionId s2 = q.getSessionId(false);
    assertNotEquals(s1, s2);
}
Also used : Query(com.yahoo.search.Query) SessionId(com.yahoo.search.query.SessionId) Test(org.junit.Test)

Aggregations

Query (com.yahoo.search.Query)4 SessionId (com.yahoo.search.query.SessionId)4 Test (org.junit.Test)4 Result (com.yahoo.search.Result)2 ByteBuffer (java.nio.ByteBuffer)2 FastHit (com.yahoo.prelude.fastsearch.FastHit)1 Execution (com.yahoo.search.searchchain.Execution)1