use of com.yahoo.fs4.QueryResultPacket in project vespa by vespa-engine.
the class VespaBackEndSearcher method cacheLookupFirstPhase.
private Result cacheLookupFirstPhase(CacheKey key, QueryPacketData queryPacketData, Query query, int offset, int hits, String summaryClass) {
PacketWrapper packetWrapper = cacheControl.lookup(key, query);
if (packetWrapper == null)
return null;
// Check if the cache entry contains the requested hits
List<DocumentInfo> documents = packetWrapper.getDocuments(offset, hits);
if (documents == null)
return null;
if (query.getPresentation().getSummary() == null)
query.getPresentation().setSummary(getDefaultDocsumClass());
Result result = new Result(query);
QueryResultPacket resultPacket = packetWrapper.getFirstResultPacket();
addMetaInfo(query, queryPacketData, resultPacket, result, true);
if (packetWrapper.getNumPackets() == 0)
addUnfilledHits(result, documents, true, queryPacketData, key);
else
addCachedHits(result, packetWrapper, summaryClass, documents);
return result;
}
use of com.yahoo.fs4.QueryResultPacket in project vespa by vespa-engine.
the class PacketWrapper method addResultPacket.
public void addResultPacket(QueryResultPacket resultPacket) {
// This function only keeps the internal list sorted according
// to offset
int insertionPoint;
QueryResultPacket r;
if (resultPacket.getDocumentCount() == 0) {
// do not add a packet which does not contain new info
return;
}
insertionPoint = Collections.binarySearch(resultPackets, resultPacket, resultPacketComparator);
if (insertionPoint < 0) {
// new offset
// (insertionPoint + 1) * -1;
insertionPoint = ~insertionPoint;
resultPackets.add(insertionPoint, resultPacket);
cleanResultPackets();
} else {
// there exists a packet with same offset
r = (QueryResultPacket) resultPackets.get(insertionPoint);
if (resultPacket.getDocumentCount() > r.getDocumentCount()) {
resultPackets.set(insertionPoint, resultPacket);
cleanResultPackets();
}
}
}
use of com.yahoo.fs4.QueryResultPacket in project vespa by vespa-engine.
the class PacketWrapper method getPacketsSize.
public int getPacketsSize() {
int size = 0;
for (Iterator<BasicPacket> i = resultPackets.iterator(); i.hasNext(); ) {
QueryResultPacket r = (QueryResultPacket) i.next();
int l = r.getLength();
if (l < 0) {
log.warning("resultpacket length " + l);
l = 10240;
}
size += l;
}
for (Iterator<BasicPacket> i = packets.values().iterator(); i.hasNext(); ) {
BasicPacket packet = i.next();
int l = packet.getLength();
if (l < 0) {
log.warning("BasicPacket length " + l);
l = 10240;
}
size += l;
}
size += keySize;
return size;
}
use of com.yahoo.fs4.QueryResultPacket in project vespa by vespa-engine.
the class PacketWrapperTestCase method testPacketTrimming10.
@Test
public void testPacketTrimming10() {
CacheKey key = new CacheKey(QueryPacket.create(new Query("/?query=key")));
PacketWrapper w = createResult(key, 0, 10, 100);
QueryResultPacket q = createQueryResultPacket(0, 11, 100);
w.addResultPacket(q);
q = createQueryResultPacket(11, 9, 100);
w.addResultPacket(q);
q = createQueryResultPacket(20, 10, 100);
w.addResultPacket(q);
assertEquals(3, w.getResultPackets().size());
List<?> l = w.getResultPackets();
assertEquals(0, ((QueryResultPacket) l.get(0)).getOffset());
assertEquals(11, ((QueryResultPacket) l.get(0)).getDocumentCount());
assertEquals(11, ((QueryResultPacket) l.get(1)).getOffset());
assertEquals(20, ((QueryResultPacket) l.get(2)).getOffset());
}
use of com.yahoo.fs4.QueryResultPacket in project vespa by vespa-engine.
the class PacketWrapperTestCase method testPacketTrimming11.
@Test
public void testPacketTrimming11() {
CacheKey key = new CacheKey(QueryPacket.create(new Query("/?query=key")));
PacketWrapper w = createResult(key, 0, 10, 100);
QueryResultPacket q = createQueryResultPacket(1, 10, 100);
w.addResultPacket(q);
q = createQueryResultPacket(9, 10, 100);
w.addResultPacket(q);
q = createQueryResultPacket(18, 10, 100);
w.addResultPacket(q);
q = createQueryResultPacket(27, 10, 100);
w.addResultPacket(q);
q = createQueryResultPacket(36, 10, 100);
w.addResultPacket(q);
q = createQueryResultPacket(45, 10, 100);
w.addResultPacket(q);
q = createQueryResultPacket(54, 10, 100);
w.addResultPacket(q);
q = createQueryResultPacket(63, 10, 100);
w.addResultPacket(q);
assertEquals(8, w.getResultPackets().size());
q = createQueryResultPacket(10, 90, 100);
w.addResultPacket(q);
assertEquals(2, w.getResultPackets().size());
}
Aggregations