Search in sources :

Example 6 with QueryPacket

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

the class PacketTestCase method testSmallQueryOK.

/**
 * Make sure we don't get false negatives for reasonably sized
 * buffers
 */
@Test
public void testSmallQueryOK() {
    Query query = new Query("/?query=foo");
    assertNotNull(query);
    QueryPacket queryPacket = QueryPacket.create(query);
    assertNotNull(queryPacket);
    ByteBuffer buffer = ByteBuffer.allocate(1024);
    int position = buffer.position();
    try {
        queryPacket.encode(buffer, 0);
    } catch (BufferTooSmallException e) {
        fail();
    }
    // make sure state of buffer HAS changed and is according
    // to contract
    assertTrue(position != buffer.position());
    assertTrue(buffer.position() == buffer.limit());
}
Also used : BufferTooSmallException(com.yahoo.fs4.BufferTooSmallException) Query(com.yahoo.search.Query) ByteBuffer(java.nio.ByteBuffer) QueryPacket(com.yahoo.fs4.QueryPacket) Test(org.junit.Test)

Example 7 with QueryPacket

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

the class QueryTestCase method testPatchInChannelId.

@Test
public void testPatchInChannelId() {
    Query query = new Query("/?query=chain&timeout=0");
    query.setWindow(2, 8);
    QueryPacket packet = QueryPacket.create(query);
    assertEquals(2, packet.getOffset());
    assertEquals(8, packet.getHits());
    ByteBuffer buffer = packet.grantEncodingBuffer(0x07070707);
    byte[] correctBuffer = new byte[] { // Header
    0, // Header
    0, // Header
    0, // Header
    46, // Header
    0, // Header
    0, // Header
    0, // Header
    -38, // Header
    7, // Header
    7, // Header
    7, // Header
    7, // Features
    0, // Features
    0, // Features
    0, // Features
    6, 2, 8, // querytimeout
    0, // querytimeout
    0, // querytimeout
    0, // querytimeout
    1, // qflags
    0, // qflags
    0, // qflags
    0x40, // qflags
    0x03, 7, 'd', 'e', 'f', 'a', 'u', 'l', 't', 0, 0, 0, 1, 0, 0, 0, 8, 4, 0, 5, 99, 104, 97, 105, 110 };
    byte[] encoded = new byte[buffer.limit()];
    buffer.get(encoded);
    assertEqualArrays(correctBuffer, encoded);
    packet.allocateAndEncode(0x07070707);
    buffer = packet.grantEncodingBuffer(0x09090909);
    correctBuffer = new byte[] { // Header
    0, // Header
    0, // Header
    0, // Header
    46, // Header
    0, // Header
    0, // Header
    0, // Header
    -38, // Header
    9, // Header
    9, // Header
    9, // Header
    9, // Features
    0, // Features
    0, // Features
    0, // Features
    6, 2, 8, // querytimeout
    0, // querytimeout
    0, // querytimeout
    0, // querytimeout
    1, // qflags
    0, // qflags
    0, // qflags
    0x40, // qflags
    0x03, 7, 'd', 'e', 'f', 'a', 'u', 'l', 't', 0, 0, 0, 1, 0, 0, 0, 8, 4, 0, 5, 99, 104, 97, 105, 110 };
    encoded = new byte[buffer.limit()];
    buffer.get(encoded);
    assertEqualArrays(correctBuffer, encoded);
}
Also used : Query(com.yahoo.search.Query) ByteBuffer(java.nio.ByteBuffer) QueryPacket(com.yahoo.fs4.QueryPacket) Test(org.junit.Test)

Example 8 with QueryPacket

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

the class QueryTestCase method testEncodeQueryPacketWithManyFeatures.

/**
 * This test will tell you if you have screwed up the binary encoding, but it won't tell you how
 */
@Test
public void testEncodeQueryPacketWithManyFeatures() {
    Query query = new Query("/?query=chain" + "&ranking.features.query(foo)=30.3&ranking.features.query(bar)=0" + "&ranking.properties.property.p1=v1&ranking.properties.property.p2=v2" + "&pos.ll=S22.4532;W123.9887&pos.radius=3&pos.attribute=place&ranking.freshness=37" + "&model.searchPath=7/3");
    query.getRanking().setFreshness(new Freshness("123456"));
    query.getRanking().setSorting("+field1 -field2");
    query.getRanking().setProfile("two");
    Highlight highlight = new Highlight();
    highlight.addHighlightTerm("field1", "term1");
    highlight.addHighlightTerm("field1", "term2");
    query.getPresentation().setHighlight(highlight);
    query.prepare();
    QueryPacket packet = QueryPacket.create(query);
    byte[] encoded = packetToBytes(packet);
    byte[] correctBuffer = new byte[] { 0, 0, 1, 23, 0, 0, 0, -38, 0, 0, 0, 0, 0, 16, 0, -122, 0, 10, ignored, ignored, ignored, ignored, 0, 0, 0x40, 0x03, 3, 't', 'w', 'o', 0, 0, 0, 3, 0, 0, 0, 4, 'r', 'a', 'n', 'k', 0, 0, 0, 5, 0, 0, 0, 11, 'p', 'r', 'o', 'p', 'e', 'r', 't', 'y', 46, 'p', '2', 0, 0, 0, 2, 'v', '2', 0, 0, 0, 11, 'p', 'r', 'o', 'p', 'e', 'r', 't', 'y', 46, 'p', '1', 0, 0, 0, 2, 'v', '1', 0, 0, 0, 3, 'f', 'o', 'o', 0, 0, 0, 4, '3', '0', 46, '3', 0, 0, 0, 3, 'b', 'a', 'r', 0, 0, 0, 1, '0', 0, 0, 0, 9, 'v', 'e', 's', 'p', 'a', 46, 'n', 'o', 'w', 0, 0, 0, 6, '1', '2', '3', '4', '5', '6', 0, 0, 0, 14, 'h', 'i', 'g', 'h', 'l', 'i', 'g', 'h', 't', 't', 'e', 'r', 'm', 's', 0, 0, 0, 3, 0, 0, 0, 6, 'f', 'i', 'e', 'l', 'd', '1', 0, 0, 0, 1, '2', 0, 0, 0, 6, 'f', 'i', 'e', 'l', 'd', '1', 0, 0, 0, 5, 't', 'e', 'r', 'm', '1', 0, 0, 0, 6, 'f', 'i', 'e', 'l', 'd', '1', 0, 0, 0, 5, 't', 'e', 'r', 'm', '2', 0, 0, 0, 5, 'm', 'o', 'd', 'e', 'l', 0, 0, 0, 1, 0, 0, 0, 10, 's', 'e', 'a', 'r', 'c', 'h', 'p', 'a', 't', 'h', 0, 0, 0, 3, '7', 47, '3', 0, 0, 0, 15, 43, 'f', 'i', 'e', 'l', 'd', '1', 32, 45, 'f', 'i', 'e', 'l', 'd', '2', 0, 0, 0, 1, 0, 0, 0, 9, 68, 1, 0, 5, 'c', 'h', 'a', 'i', 'n' };
    assertEqualArrays(correctBuffer, encoded);
}
Also used : Highlight(com.yahoo.prelude.query.Highlight) Query(com.yahoo.search.Query) Freshness(com.yahoo.prelude.Freshness) QueryPacket(com.yahoo.fs4.QueryPacket) Test(org.junit.Test)

Example 9 with QueryPacket

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

the class QueryTestCase method testEncodeQueryPacketWithSomeAdditionalFeatures.

@Test
public void testEncodeQueryPacketWithSomeAdditionalFeatures() {
    Query query = new Query("/?query=chain&dataset=10&type=phrase&timeout=0");
    // Because the rank mapping now needs config and a searcher,
    // we do the sledgehammer dance:
    query.getRanking().setProfile("two");
    query.setWindow(2, 8);
    QueryPacket packet = QueryPacket.create(query);
    byte[] encoded = packetToBytes(packet);
    byte[] correctBuffer = new byte[] { // Header
    0, // Header
    0, // Header
    0, // Header
    42, // Header
    0, // Header
    0, // Header
    0, // Header
    -38, // Header
    0, // Header
    0, // Header
    0, // Header
    0, // Features
    0, // Features
    0, // Features
    0, // Features
    6, 2, 8, // querytimeout
    0, // querytimeout
    0, // querytimeout
    0, // querytimeout
    1, // QFlags
    0, // QFlags
    0, // QFlags
    0x40, // QFlags
    0x03, 3, // Ranking
    't', // Ranking
    'w', // Ranking
    'o', 0, 0, 0, 1, 0, 0, 0, 8, 4, 0, 5, 99, 104, 97, 105, 110 };
    assertEqualArrays(correctBuffer, encoded);
}
Also used : Query(com.yahoo.search.Query) QueryPacket(com.yahoo.fs4.QueryPacket) Test(org.junit.Test)

Example 10 with QueryPacket

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

the class QueryTestCase method testEncodeSortSpec.

@Test
public void testEncodeSortSpec() throws BufferTooSmallException {
    Query query = new Query("/?query=chain&sortspec=%2Ba+-b&timeout=0");
    query.setWindow(2, 8);
    QueryPacket packet = QueryPacket.create(query);
    ByteBuffer buffer = ByteBuffer.allocate(500);
    buffer.limit(0);
    packet.encode(buffer, 0);
    byte[] encoded = new byte[buffer.position()];
    buffer.rewind();
    buffer.get(encoded);
    byte[] correctBuffer = new byte[] { // Header
    0, // Header
    0, // Header
    0, // Header
    55, // Header
    0, // Header
    0, // Header
    0, // Header
    -38, // Header
    0, // Header
    0, // Header
    0, // Header
    0, // Features
    0, // Features
    0, // Features
    0, // Features
    -122, // offset
    2, // maxhits
    8, // querytimeout
    0, // querytimeout
    0, // querytimeout
    0, // querytimeout
    1, // qflags
    0, // qflags
    0, // qflags
    0x40, // qflags
    0x03, 7, 'd', 'e', 'f', 'a', 'u', 'l', 't', // sortspec length
    0, // sortspec length
    0, // sortspec length
    0, // sortspec length
    5, // sortspec
    43, // sortspec
    97, // sortspec
    32, // sortspec
    45, // sortspec
    98, // num stackitems
    0, // num stackitems
    0, // num stackitems
    0, // num stackitems
    1, 0, 0, 0, 8, 4, 0, 5, 99, 104, 97, 105, 110 };
    assertEqualArrays(correctBuffer, encoded);
    // Encode again to test grantEncodingBuffer
    buffer = packet.grantEncodingBuffer(0);
    encoded = new byte[buffer.limit()];
    buffer.get(encoded);
    assertEqualArrays(correctBuffer, encoded);
}
Also used : Query(com.yahoo.search.Query) ByteBuffer(java.nio.ByteBuffer) QueryPacket(com.yahoo.fs4.QueryPacket) Test(org.junit.Test)

Aggregations

QueryPacket (com.yahoo.fs4.QueryPacket)20 Query (com.yahoo.search.Query)15 Test (org.junit.Test)14 ByteBuffer (java.nio.ByteBuffer)8 GetDocSumsPacket (com.yahoo.fs4.GetDocSumsPacket)4 Result (com.yahoo.search.Result)4 BasicPacket (com.yahoo.fs4.BasicPacket)3 ChannelTimeoutException (com.yahoo.fs4.ChannelTimeoutException)3 Packet (com.yahoo.fs4.Packet)3 PingPacket (com.yahoo.fs4.PingPacket)3 PongPacket (com.yahoo.fs4.PongPacket)3 QueryResultPacket (com.yahoo.fs4.QueryResultPacket)3 IOException (java.io.IOException)3 BufferTooSmallException (com.yahoo.fs4.BufferTooSmallException)2 FS4Channel (com.yahoo.fs4.mplex.FS4Channel)2 InvalidChannelException (com.yahoo.fs4.mplex.InvalidChannelException)2 CacheKey (com.yahoo.prelude.fastsearch.CacheKey)2 Highlight (com.yahoo.prelude.query.Highlight)2 WordItem (com.yahoo.prelude.query.WordItem)2 CompressionType (com.yahoo.compress.CompressionType)1