use of com.yahoo.search.result.Hit 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.result.Hit in project vespa by vespa-engine.
the class BlendingSearcher method blendResults.
/**
* Produce a single blended result list from a group of hitgroups.
*
* It is assumed that the results are ordered in hitgroups. If not, the blend will not be performed
*/
protected Result blendResults(Result result, Query q, int offset, int hits, Execution execution) {
// Assert that there are more than one hitgroup and that there are only hitgroups on the lowest level
boolean foundNonGroup = false;
Iterator<Hit> hitIterator = result.hits().iterator();
List<HitGroup> groups = new ArrayList<>();
while (hitIterator.hasNext()) {
Hit hit = hitIterator.next();
if (hit instanceof HitGroup) {
groups.add((HitGroup) hit);
hitIterator.remove();
} else if (!hit.isMeta()) {
foundNonGroup = true;
}
}
if (foundNonGroup) {
result.hits().addError(ErrorMessage.createUnspecifiedError("Blendingsearcher could not blend - there are toplevel hits" + " that are not hitgroups"));
return result;
}
if (groups.size() == 0) {
return result;
} else if (groups.size() == 1) {
result.hits().addAll(groups.get(0).asUnorderedHits());
result.hits().setOrderer(groups.get(0).getOrderer());
return result;
} else {
if (documentId != null) {
return blendResultsUniquely(result, q, offset, hits, groups, execution);
} else {
return blendResultsDirectly(result, q, offset, hits, groups, execution);
}
}
}
use of com.yahoo.search.result.Hit 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);
}
use of com.yahoo.search.result.Hit in project vespa by vespa-engine.
the class JuniperSearcher method highlight.
private void highlight(boolean bolding, Iterator<Hit> hitsToHighlight, String summaryClass, IndexFacts.Session indexFacts) {
while (hitsToHighlight.hasNext()) {
Hit sniffHit = hitsToHighlight.next();
if (!(sniffHit instanceof FastHit))
continue;
FastHit hit = (FastHit) sniffHit;
if (summaryClass != null && !hit.isFilled(summaryClass))
continue;
Object searchDefinitionField = hit.getField(MAGIC_FIELD);
if (searchDefinitionField == null)
continue;
String searchDefinitionName = searchDefinitionField.toString();
for (String fieldName : hit.fields().keySet()) {
Index index = indexFacts.getIndex(fieldName, searchDefinitionName);
if (index.getDynamicSummary() || index.getHighlightSummary())
insertTags(hit.buildHitField(fieldName, true, true), bolding, index.getDynamicSummary());
}
}
}
use of com.yahoo.search.result.Hit in project vespa by vespa-engine.
the class JuniperSearcher method fill.
@Override
public void fill(Result result, String summaryClass, Execution execution) {
Result workResult = result;
final int worstCase = workResult.getHitCount();
final List<Hit> hits = new ArrayList<>(worstCase);
for (final Iterator<Hit> i = workResult.hits().deepIterator(); i.hasNext(); ) {
final Hit sniffHit = i.next();
if (!(sniffHit instanceof FastHit))
continue;
final FastHit hit = (FastHit) sniffHit;
if (hit.isFilled(summaryClass))
continue;
hits.add(hit);
}
execution.fill(workResult, summaryClass);
highlight(workResult.getQuery().getPresentation().getBolding(), hits.iterator(), summaryClass, execution.context().getIndexFacts().newSession(result.getQuery()));
}
Aggregations