Search in sources :

Example 16 with QueryPacket

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

the class QueryTestCase method testEncodePacket.

@Test
public void testEncodePacket() {
    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());
    byte[] encoded = packetToBytes(packet);
    byte[] correctBuffer = new byte[] { // Header
    0, // Header
    0, // Header
    0, // Header
    46, // 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, 7, 'd', 'e', 'f', 'a', 'u', 'l', 't', 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 17 with QueryPacket

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

the class QueryTestCase method testEncodeQueryPacketWithLabelsConnectivityAndSignificance.

@Test
public void testEncodeQueryPacketWithLabelsConnectivityAndSignificance() {
    Query query = new Query();
    AndItem and = new AndItem();
    WeightedSetItem taggable1 = new WeightedSetItem("field1");
    taggable1.setLabel("foo");
    WeightedSetItem taggable2 = new WeightedSetItem("field2");
    taggable1.setLabel("bar");
    and.addItem(taggable1);
    and.addItem(taggable2);
    WordItem word1 = new WordItem("word1", "field3");
    word1.setSignificance(0.37);
    WordItem word2 = new WordItem("word1", "field3");
    word2.setSignificance(0.81);
    word2.setConnectivity(word1, 0.15);
    and.addItem(word1);
    and.addItem(word2);
    query.getModel().getQueryTree().setRoot(and);
    query.prepare();
    QueryPacket packet = QueryPacket.create(query);
    byte[] encoded = packetToBytes(packet);
    byte[] correctBuffer = new byte[] { 0, 0, 1, 16, 0, 0, 0, -38, 0, 0, 0, 0, 0, 16, 0, 6, 0, 10, ignored, ignored, ignored, ignored, 0, 0, 0x40, 0x03, 7, 'd', 'e', 'f', 'a', 'u', 'l', 't', 0, 0, 0, 1, 0, 0, 0, 4, 'r', 'a', 'n', 'k', 0, 0, 0, 5, 0, 0, 0, 18, 'v', 'e', 's', 'p', 'a', 46, 'l', 'a', 'b', 'e', 'l', 46, 'b', 'a', 'r', 46, 'i', 'd', 0, 0, 0, 1, '1', 0, 0, 0, 22, 'v', 'e', 's', 'p', 'a', 46, 't', 'e', 'r', 'm', 46, '4', 46, 'c', 'o', 'n', 'n', 'e', 'x', 'i', 't', 'y', 0, 0, 0, 1, '3', 0, 0, 0, 22, 'v', 'e', 's', 'p', 'a', 46, 't', 'e', 'r', 'm', 46, '4', 46, 'c', 'o', 'n', 'n', 'e', 'x', 'i', 't', 'y', 0, 0, 0, 4, '0', 46, '1', '5', 0, 0, 0, 25, 'v', 'e', 's', 'p', 'a', 46, 't', 'e', 'r', 'm', 46, '3', 46, 's', 'i', 'g', 'n', 'i', 'f', 'i', 'c', 'a', 'n', 'c', 'e', 0, 0, 0, 4, '0', 46, '3', '7', 0, 0, 0, 25, 'v', 'e', 's', 'p', 'a', 46, 't', 'e', 'r', 'm', 46, '4', 46, 's', 'i', 'g', 'n', 'i', 'f', 'i', 'c', 'a', 'n', 'c', 'e', 0, 0, 0, 4, '0', 46, '8', '1', 0, 0, 0, 5, 0, 0, 0, '4', 1, 4, 79, 1, 0, 6, 'f', 'i', 'e', 'l', 'd', '1', 79, 2, 0, 6, 'f', 'i', 'e', 'l', 'd', '2', 68, 3, 6, 'f', 'i', 'e', 'l', 'd', '3', 5, 'w', 'o', 'r', 'd', '1', 68, 4, 6, 'f', 'i', 'e', 'l', 'd', '3', 5, 'w', 'o', 'r', 'd', 49 };
    assertEqualArrays(correctBuffer, encoded);
}
Also used : Query(com.yahoo.search.Query) AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) WeightedSetItem(com.yahoo.prelude.query.WeightedSetItem) QueryPacket(com.yahoo.fs4.QueryPacket) Test(org.junit.Test)

Example 18 with QueryPacket

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

the class QueryTestCase method testPhraseEqualsPhraseWithPhraseSegment.

@Test
public void testPhraseEqualsPhraseWithPhraseSegment() throws BufferTooSmallException {
    Query query = new Query();
    PhraseItem p = new PhraseItem();
    PhraseSegmentItem ps = new PhraseSegmentItem("a b", false, false);
    ps.addItem(new WordItem("a"));
    ps.addItem(new WordItem("b"));
    p.addItem(ps);
    query.getModel().getQueryTree().setRoot(p);
    query.setTimeout(0);
    QueryPacket queryPacket = QueryPacket.create(query);
    ByteBuffer buffer1 = ByteBuffer.allocate(1024);
    queryPacket.encode(buffer1, 0);
    query = new Query();
    p = new PhraseItem();
    p.addItem(new WordItem("a"));
    p.addItem(new WordItem("b"));
    query.getModel().getQueryTree().setRoot(p);
    query.setTimeout(0);
    queryPacket = QueryPacket.create(query);
    assertNotNull(queryPacket);
    ByteBuffer buffer2 = ByteBuffer.allocate(1024);
    queryPacket.encode(buffer2, 0);
    byte[] encoded1 = new byte[buffer1.position()];
    buffer1.rewind();
    buffer1.get(encoded1);
    byte[] encoded2 = new byte[buffer2.position()];
    buffer2.rewind();
    buffer2.get(encoded2);
    assertEqualArrays(encoded2, encoded1);
}
Also used : Query(com.yahoo.search.Query) WordItem(com.yahoo.prelude.query.WordItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) ByteBuffer(java.nio.ByteBuffer) PhraseItem(com.yahoo.prelude.query.PhraseItem) QueryPacket(com.yahoo.fs4.QueryPacket) Test(org.junit.Test)

Example 19 with QueryPacket

use of com.yahoo.fs4.QueryPacket 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)

Example 20 with QueryPacket

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

the class VdsStreamingSearcherTestCase method executeQuery.

private static Result executeQuery(VdsStreamingSearcher searcher, Query query) {
    QueryPacket queryPacket = QueryPacket.create(query);
    CacheKey cacheKey = new CacheKey(queryPacket);
    Execution execution = new Execution(new Execution.Context(null, null, null, null, null));
    return searcher.doSearch2(query, queryPacket, cacheKey, execution);
}
Also used : Execution(com.yahoo.search.searchchain.Execution) QueryPacket(com.yahoo.fs4.QueryPacket)

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