use of com.yahoo.search.Query 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.search.Query in project vespa by vespa-engine.
the class VespaBackEndSearcher method cacheLookupTwoPhase.
protected PacketWrapper cacheLookupTwoPhase(CacheKey cacheKey, Result result, String summaryClass) {
Query query = result.getQuery();
PacketWrapper packetWrapper = cacheControl.lookup(cacheKey, query);
if (packetWrapper == null) {
return null;
}
if (packetWrapper.getNumPackets() != 0) {
for (Iterator<Hit> i = hitIterator(result); i.hasNext(); ) {
Hit hit = i.next();
if (hit instanceof FastHit) {
FastHit fastHit = (FastHit) hit;
DocsumPacketKey key = new DocsumPacketKey(fastHit.getGlobalId(), fastHit.getPartId(), summaryClass);
if (fillHit(fastHit, (DocsumPacket) packetWrapper.getPacket(key), summaryClass).ok) {
fastHit.setCached(true);
}
}
}
result.hits().setSorted(false);
result.analyzeHits();
}
return packetWrapper;
}
use of com.yahoo.search.Query in project vespa by vespa-engine.
the class FastSearcher method doPartialFill.
/**
* Perform a partial docsum fill for a temporary result
* representing a partition of the complete fill request.
*
* @param result result containing a partition of the unfilled hits
* @param summaryClass the summary class we want to fill with
*/
protected void doPartialFill(Result result, String summaryClass) {
if (result.isFilled(summaryClass))
return;
Query query = result.getQuery();
traceQuery(getName(), "fill", query, query.getOffset(), query.getHits(), 2, quotedSummaryClass(summaryClass));
if (wantsRPCSummaryFill(query)) {
CompressionType compression = CompressionType.valueOf(query.properties().getString(dispatchCompression, "LZ4").toUpperCase());
fillSDDocName(result);
dispatcher.fill(result, summaryClass, compression);
return;
}
CacheKey cacheKey = null;
PacketWrapper packetWrapper = null;
if (getCacheControl().useCache(query)) {
cacheKey = fetchCacheKeyFromHits(result.hits(), summaryClass);
if (cacheKey == null) {
QueryPacket queryPacket = QueryPacket.create(query);
cacheKey = new CacheKey(queryPacket);
}
packetWrapper = cacheLookupTwoPhase(cacheKey, result, summaryClass);
}
FS4Channel channel = chooseBackend(query).openChannel();
channel.setQuery(query);
Packet[] receivedPackets;
try {
DocsumPacketKey[] packetKeys;
if (countFastHits(result) > 0) {
packetKeys = getPacketKeys(result, summaryClass, false);
if (packetKeys.length == 0) {
receivedPackets = new Packet[0];
} else {
try {
receivedPackets = fetchSummaries(channel, result, summaryClass);
} catch (InvalidChannelException e) {
result.hits().addError(ErrorMessage.createBackendCommunicationError("Invalid channel " + getName() + " (summary fetch)"));
return;
} catch (ChannelTimeoutException e) {
result.hits().addError(ErrorMessage.createTimeout("timeout waiting for summaries from " + getName()));
return;
} catch (IOException e) {
result.hits().addError(ErrorMessage.createBackendCommunicationError("IO error while talking on channel " + getName() + " (summary fetch): " + e.getMessage()));
return;
}
if (receivedPackets.length == 0) {
result.hits().addError(ErrorMessage.createBackendCommunicationError(getName() + " got no packets back (summary fetch)"));
return;
}
}
} else {
packetKeys = new DocsumPacketKey[0];
receivedPackets = new Packet[0];
}
int skippedHits;
try {
FillHitsResult fillHitsResult = fillHits(result, receivedPackets, summaryClass);
skippedHits = fillHitsResult.skippedHits;
if (fillHitsResult.error != null) {
result.hits().addError(ErrorMessage.createTimeout(fillHitsResult.error));
return;
}
} catch (TimeoutException e) {
result.hits().addError(ErrorMessage.createTimeout(e.getMessage()));
return;
} catch (IOException e) {
result.hits().addError(ErrorMessage.createBackendCommunicationError("Error filling hits with summary fields, source: " + getName() + " Exception thrown: " + e.getMessage()));
return;
}
if (skippedHits == 0 && packetWrapper != null) {
cacheControl.updateCacheEntry(cacheKey, query, packetKeys, receivedPackets);
}
if (skippedHits > 0)
result.hits().addError(com.yahoo.search.result.ErrorMessage.createEmptyDocsums("Missing hit data for summary '" + summaryClass + "' for " + skippedHits + " hits"));
result.analyzeHits();
if (query.getTraceLevel() >= 3) {
int hitNumber = 0;
for (Iterator<com.yahoo.search.result.Hit> i = hitIterator(result); i.hasNext(); ) {
com.yahoo.search.result.Hit hit = i.next();
if (!(hit instanceof FastHit))
continue;
FastHit fastHit = (FastHit) hit;
String traceMsg = "Hit: " + (hitNumber++) + " from " + (fastHit.isCached() ? "cache" : "backend");
if (!fastHit.isFilled(summaryClass))
traceMsg += ". Error, hit, not filled";
query.trace(traceMsg, false, 3);
}
}
} finally {
channel.close();
}
}
use of com.yahoo.search.Query in project vespa by vespa-engine.
the class PacketDumper method handlePacket.
private void handlePacket(FS4Channel channel, BasicPacket packet, ByteBuffer serializedForm, String direction) {
// minimize overhead when disabled:
if (disabled)
return;
try {
DataOutputStream stream = getOutputStream(packet);
if (stream != null) {
synchronized (stream) {
stream.writeChars(packet.getTimestamp() + " " + direction + " packet on channel " + channel.getChannelId());
String indent = " ";
Query query = channel.getQuery();
if (query != null)
stream.writeChars('\n' + indent + "Query: '" + query.getModel().getQueryString());
hexDump(indent, stream, serializedForm);
stream.writeChar('\n');
stream.flush();
}
}
} catch (IOException e) {
log.log(LogLevel.WARNING, "Could not log packet.", e);
}
}
use of com.yahoo.search.Query in project vespa by vespa-engine.
the class DocumentSourceSearcher method addDefaultResults.
private void addDefaultResults() {
Query q = new Query("?query=default");
Result r = new Result(q);
r.hits().add(new Hit("http://default-1.html"));
r.hits().add(new Hit("http://default-2.html"));
r.hits().add(new Hit("http://default-3.html"));
r.hits().add(new Hit("http://default-4.html"));
defaultFilledResult = r;
addResultSet(q, r);
}
Aggregations