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