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);
}
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);
}
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);
}
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()]);
}
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);
}
Aggregations