use of com.yahoo.search.Result in project vespa by vespa-engine.
the class FastSearcherTestCase method testSinglePhaseCachedSupersets.
@Ignore
public void testSinglePhaseCachedSupersets() {
Logger.getLogger(FastSearcher.class.getName()).setLevel(Level.ALL);
MockFSChannel.resetDocstamp();
FastSearcher fastSearcher = new FastSearcher(new MockBackend(), new FS4ResourcePool(1), new MockDispatcher(Collections.emptyList()), new SummaryParameters(null), new ClusterParams("testhittype"), new CacheParams(100, 1e64), documentdbInfoConfig);
CacheControl c = fastSearcher.getCacheControl();
Result result = doSearch(fastSearcher, new Query("?query=ignored"), 0, 2);
Query q = new Query("?query=ignored");
((WordItem) q.getModel().getQueryTree().getRoot()).setUniqueID(1);
QueryPacket queryPacket = QueryPacket.create(q);
CacheKey k = new CacheKey(queryPacket);
PacketWrapper p = c.lookup(k, q);
assertEquals(1, p.getResultPackets().size());
result = doSearch(fastSearcher, new Query("?query=ignored"), 1, 1);
p = c.lookup(k, q);
// ensure we don't get redundant QueryResultPacket instances
// in the cache
assertEquals(1, p.getResultPackets().size());
assertEquals(1, result.getConcreteHitCount());
for (int i = 0; i < result.getHitCount(); i++) {
assertTrue(result.hits().get(i).isCached());
}
result = doSearch(fastSearcher, new Query("?query=ignored"), 0, 1);
p = c.lookup(k, q);
assertEquals(1, p.getResultPackets().size());
assertEquals(1, result.getConcreteHitCount());
for (int i = 0; i < result.getHitCount(); i++) {
assertTrue(result.hits().get(i).isCached());
}
}
use of com.yahoo.search.Result in project vespa by vespa-engine.
the class FastSearcherTestCase method testSearch.
@Test
public void testSearch() {
FastSearcher fastSearcher = createFastSearcher();
// Default cache =100MB
assertEquals(100, fastSearcher.getCacheControl().capacity());
Result result = doSearch(fastSearcher, new Query("?query=ignored"), 0, 10);
Execution execution = new Execution(chainedAsSearchChain(fastSearcher), Execution.Context.createContextStub());
assertEquals(2, result.getHitCount());
execution.fill(result);
assertCorrectHit1((FastHit) result.hits().get(0));
assertCorrectTypes1((FastHit) result.hits().get(0));
for (int idx = 0; idx < result.getHitCount(); idx++) {
assertTrue(!result.hits().get(idx).isCached());
}
// Repeat the request a couple of times, to verify whether the packet cache works
result = doSearch(fastSearcher, new Query("?query=ignored"), 0, 10);
assertEquals(2, result.getHitCount());
execution.fill(result);
assertCorrectHit1((FastHit) result.hits().get(0));
for (int i = 0; i < result.getHitCount(); i++) {
assertTrue(result.hits().get(i) + " should be cached", result.hits().get(i).isCached());
}
// outside-range cache hit
result = doSearch(fastSearcher, new Query("?query=ignored"), 6, 3);
// fill should still work (nop)
execution.fill(result);
result = doSearch(fastSearcher, new Query("?query=ignored"), 0, 10);
assertEquals(2, result.getHitCount());
assertCorrectHit1((FastHit) result.hits().get(0));
assertTrue("All hits are cached and the result knows it", result.isCached());
for (int i = 0; i < result.getHitCount(); i++) {
assertTrue(result.hits().get(i) + " should be cached", result.hits().get(i).isCached());
}
clearCache(fastSearcher);
result = doSearch(fastSearcher, new Query("?query=ignored"), 0, 10);
assertEquals(2, result.getHitCount());
execution.fill(result);
assertCorrectHit1((FastHit) result.hits().get(0));
assertTrue("All hits are not cached", !result.isCached());
for (int i = 0; i < result.getHitCount(); i++) {
assertTrue(!result.hits().get(i).isCached());
}
// Test that partial result sets can be retrieved from the cache
clearCache(fastSearcher);
result = doSearch(fastSearcher, new Query("?query=ignored"), 0, 1);
assertEquals(1, result.getConcreteHitCount());
execution.fill(result);
result = doSearch(fastSearcher, new Query("?query=ignored"), 0, 2);
assertEquals(2, result.getConcreteHitCount());
execution.fill(result);
// First hit should be cached but not second hit
assertTrue(result.hits().get(0).isCached());
assertFalse(result.hits().get(1).isCached());
// Check that the entire result set is returned from cache now
result = doSearch(fastSearcher, new Query("?query=ignored"), 0, 2);
assertEquals(2, result.getConcreteHitCount());
execution.fill(result);
// both first and second should now be cached
assertTrue(result.hits().get(0).isCached());
assertTrue(result.hits().get(1).isCached());
// Tests that the cache _hit_ is not returned if _another_
// hit is requested
clearCache(fastSearcher);
result = doSearch(fastSearcher, new Query("?query=ignored"), 0, 1);
assertEquals(1, result.getConcreteHitCount());
result = doSearch(fastSearcher, new Query("?query=ignored"), 1, 1);
assertEquals(1, result.getConcreteHitCount());
for (int i = 0; i < result.getHitCount(); i++) {
assertFalse("Hit " + i + " should not be cached.", result.hits().get(i).isCached());
}
}
use of com.yahoo.search.Result 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);
}
use of com.yahoo.search.Result in project vespa by vespa-engine.
the class FastSearcherTestCase method testQueryWithRestrict.
@Test
public void testQueryWithRestrict() {
mockBackend = new MockBackend();
DocumentdbInfoConfig documentdbConfigWithOneDb = new DocumentdbInfoConfig(new DocumentdbInfoConfig.Builder().documentdb(new DocumentdbInfoConfig.Documentdb.Builder().name("testDb")));
FastSearcher fastSearcher = new FastSearcher(mockBackend, new FS4ResourcePool(1), new MockDispatcher(Collections.emptyList()), new SummaryParameters(null), new ClusterParams("testhittype"), new CacheParams(100, 1e64), documentdbConfigWithOneDb);
Query query = new Query("?query=foo&model.restrict=testDb");
query.prepare();
Result result = doSearch(fastSearcher, query, 0, 10);
Packet receivedPacket = mockBackend.getChannel().getLastQueryPacket();
byte[] encoded = QueryTestCase.packetToBytes(receivedPacket);
byte[] correct = new byte[] { 0, 0, 0, 100, 0, 0, 0, -38, 0, 0, 0, 0, 0, 16, 0, 6, 0, 10, // time left
QueryTestCase.ignored, // time left
QueryTestCase.ignored, // time left
QueryTestCase.ignored, // time left
QueryTestCase.ignored, 0, 0, 0x40, 0x03, 7, 100, 101, 102, 97, 117, 108, 116, 0, 0, 0, 1, 0, 0, 0, 5, 109, 97, 116, 99, 104, 0, 0, 0, 1, 0, 0, 0, 24, 100, 111, 99, 117, 109, 101, 110, 116, 100, 98, 46, 115, 101, 97, 114, 99, 104, 100, 111, 99, 116, 121, 112, 101, 0, 0, 0, 6, 116, 101, 115, 116, 68, 98, 0, 0, 0, 1, 0, 0, 0, 7, 68, 1, 0, 3, 102, 111, 111 };
QueryTestCase.assertEqualArrays(correct, encoded);
}
use of com.yahoo.search.Result in project vespa by vespa-engine.
the class FastSearcherTestCase method getTraceString.
private String getTraceString(String summary) {
FastSearcher fastSearcher = createFastSearcher();
Query query = new Query("?query=ignored");
query.getPresentation().setSummary(summary);
query.setTraceLevel(2);
Result result = doSearch(fastSearcher, query, 0, 10);
doFill(fastSearcher, result);
Trace trace = query.getContext(false).getTrace();
final AtomicReference<String> fillTraceString = new AtomicReference<>();
trace.traceNode().accept(new TraceVisitor() {
@Override
public void visit(TraceNode traceNode) {
if (traceNode.payload() instanceof String && traceNode.payload().toString().contains("fill to dispatch"))
fillTraceString.set((String) traceNode.payload());
}
});
return fillTraceString.get();
}
Aggregations