use of com.yahoo.fs4.DocumentInfo in project vespa by vespa-engine.
the class VespaBackEndSearcher method addUnfilledHits.
/**
* Creates unfilled hits from a List of DocumentInfo instances. Do note
* cacheKey should be available if a cache is active, even if the hit is not
* created from a cache in the current call path.
*
* @param queryPacketData binary data from first phase of search, or null
* @param cacheKey the key this hit should match in the packet cache, or null
*/
protected boolean addUnfilledHits(Result result, List<DocumentInfo> documents, boolean fromCache, QueryPacketData queryPacketData, CacheKey cacheKey) {
boolean allHitsOK = true;
Query myQuery = result.getQuery();
for (DocumentInfo document : documents) {
try {
FastHit hit = new FastHit();
hit.setQuery(myQuery);
if (queryPacketData != null)
hit.setQueryPacketData(queryPacketData);
hit.setCacheKey(cacheKey);
hit.setUseRowInIndexUri(useRowInIndexUri(result));
hit.setFillable();
hit.setCached(fromCache);
extractDocumentInfo(hit, document);
result.hits().add(hit);
} catch (ConfigurationException e) {
allHitsOK = false;
getLogger().log(LogLevel.WARNING, "Skipping hit", e);
} catch (Exception e) {
allHitsOK = false;
getLogger().log(LogLevel.ERROR, "Skipping malformed hit", e);
}
}
return allHitsOK;
}
use of com.yahoo.fs4.DocumentInfo 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.DocumentInfo in project vespa by vespa-engine.
the class QueryResultTestCase method testDecodeQueryResultMoreHits.
@Test
public void testDecodeQueryResultMoreHits() {
byte[] packetData = new byte[] { 0, 0, 0, 100, 0, 0, 0, 217 - 256, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 5, 0x40, 0x39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 111, 0, 6, 0, 5, 0, 0, 0, 0, 0, 0, 0, 89, 0, 0, 0, 0, 0, 0, 0, 90, 0, 0, 0, 0, 0, 0, 0, 91, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0x40, 0x37, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 36, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0x40, 0x35, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 37 };
ByteBuffer buffer = ByteBuffer.allocate(200);
buffer.put(packetData);
buffer.flip();
BasicPacket packet = PacketDecoder.decode(buffer);
assertTrue(packet instanceof QueryResultPacket);
QueryResultPacket result = (QueryResultPacket) packet;
assertEquals(2, result.getDocuments().size());
DocumentInfo document1 = result.getDocuments().get(0);
assertEquals(gid1, document1.getGlobalId());
DocumentInfo document2 = result.getDocuments().get(1);
assertEquals(gid2, document2.getGlobalId());
assertEquals(6, result.getNodesQueried());
assertEquals(5, result.getNodesReplied());
}
use of com.yahoo.fs4.DocumentInfo in project vespa by vespa-engine.
the class QueryResultTestCase method testDecodeQueryResultX.
@Test
public void testDecodeQueryResultX() {
byte[] packetData = new byte[] { 0, 0, 0, 100, 0, 0, 0, 217 - 256, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 5, 0x40, 0x39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 111, 0, 0, 0, 0, 0, 0, 0, 89, 0, 0, 0, 0, 0, 0, 0, 90, 0, 0, 0, 0, 0, 0, 0, 91, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0x40, 0x37, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 36, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0x40, 0x35, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 37 };
ByteBuffer buffer = ByteBuffer.allocate(200);
buffer.put(packetData);
buffer.flip();
BasicPacket packet = PacketDecoder.decode(buffer);
assertTrue(packet instanceof QueryResultPacket);
QueryResultPacket result = (QueryResultPacket) packet;
assertTrue(result.getMldFeature());
assertEquals(5, result.getTotalDocumentCount());
assertEquals(25, result.getMaxRank());
assertEquals(111, result.getDocstamp());
assertEquals(89, result.getCoverageDocs());
assertEquals(90, result.getActiveDocs());
assertEquals(91, result.getSoonActiveDocs());
assertEquals(1, result.getDegradedReason());
assertEquals(2, result.getDocuments().size());
DocumentInfo document1 = result.getDocuments().get(0);
assertEquals(gid1, document1.getGlobalId());
assertEquals(23.0, document1.getMetric(), delta);
assertEquals(7, document1.getPartId());
assertEquals(36, document1.getDistributionKey());
DocumentInfo document2 = result.getDocuments().get(1);
assertEquals(gid2, document2.getGlobalId());
assertEquals(21.0, document2.getMetric(), delta);
assertEquals(8, document2.getPartId());
assertEquals(37, document2.getDistributionKey());
}
use of com.yahoo.fs4.DocumentInfo in project vespa by vespa-engine.
the class VespaBackEndSearcher method addCachedHits.
private boolean addCachedHits(Result result, PacketWrapper packetWrapper, String summaryClass, List<DocumentInfo> documents) {
boolean filledAllOfEm = true;
Query myQuery = result.getQuery();
for (DocumentInfo document : documents) {
FastHit hit = new FastHit();
hit.setQuery(myQuery);
hit.setUseRowInIndexUri(useRowInIndexUri(result));
hit.setFillable();
hit.setCached(true);
extractDocumentInfo(hit, document);
DocsumPacket docsum = (DocsumPacket) packetWrapper.getPacket(document.getGlobalId(), document.getPartId(), summaryClass);
if (docsum != null) {
byte[] docsumdata = docsum.getData();
if (docsumdata.length > 0) {
String error = decodeSummary(summaryClass, hit, docsumdata);
if (error != null) {
filledAllOfEm = false;
}
} else {
filledAllOfEm = false;
}
} else {
filledAllOfEm = false;
}
result.hits().add(hit);
}
return filledAllOfEm;
}
Aggregations