use of com.yahoo.search.result.Hit in project vespa by vespa-engine.
the class GroupingExecutor method fill.
@Override
public void fill(Result result, String summaryClass, Execution execution) {
Map<String, Result> summaryMap = new HashMap<>();
for (Iterator<Hit> it = result.hits().unorderedDeepIterator(); it.hasNext(); ) {
Hit hit = it.next();
Object metaData = hit.getSearcherSpecificMetaData(this);
if (metaData != null && metaData instanceof String) {
// Use the summary class specified by grouping, set in HitConverter, for the first fill request
// after grouping. This assumes the first fill request is using the default summary class,
// which may be a fragile assumption. But currently we cannot do better because the difference
// between explicit and implicit summary class in fill is erased by the Execution.
//
// We reset the summary class here such that following fill calls will execute with the
// summary class they specify
summaryClass = (String) metaData;
hit.setSearcherSpecificMetaData(this, null);
}
Result summaryResult = summaryMap.get(summaryClass);
if (summaryResult == null) {
summaryResult = new Result(result.getQuery());
summaryMap.put(summaryClass, summaryResult);
}
summaryResult.hits().add(hit);
}
for (Map.Entry<String, Result> entry : summaryMap.entrySet()) {
Result res = entry.getValue();
execution.fill(res, entry.getKey());
ErrorMessage err = res.hits().getError();
if (err != null) {
result.hits().addError(err);
}
}
Result defaultResult = summaryMap.get(ExpressionConverter.DEFAULT_SUMMARY_NAME);
if (defaultResult != null) {
// "default" to signal the same
for (Hit hit : defaultResult.hits()) {
hit.setFilled(null);
}
}
}
use of com.yahoo.search.result.Hit in project vespa by vespa-engine.
the class HitConverter method convertFs4Hit.
private Hit convertFs4Hit(String summaryClass, FS4Hit groupHit) {
FastHit hit = new FastHit();
hit.setRelevance(groupHit.getRank());
hit.setGlobalId(groupHit.getGlobalId());
hit.setPartId(groupHit.getPath(), 0);
hit.setDistributionKey(groupHit.getDistributionKey());
hit.setFillable();
hit.setSearcherSpecificMetaData(searcher, summaryClass);
Hit ctxHit = (Hit) groupHit.getContext();
if (ctxHit == null) {
throw new NullPointerException("Hit has no context.");
}
hit.setSource(ctxHit.getSource());
hit.setSourceNumber(ctxHit.getSourceNumber());
hit.setQuery(ctxHit.getQuery());
if (ctxHit instanceof GroupingListHit) {
// in a live system the ctxHit can only by GroupingListHit, but because the code used Hit prior to version
// 5.10 we need to check to avoid breaking existing unit tests -- both internally and with customers
QueryPacketData queryPacketData = ((GroupingListHit) ctxHit).getQueryPacketData();
if (queryPacketData != null) {
hit.setQueryPacketData(queryPacketData);
}
}
return hit;
}
use of com.yahoo.search.result.Hit in project vespa by vespa-engine.
the class MockResultSearcher method search.
@Override
public Result search(Query query, Execution execution) {
Result result = new Result(query);
result.hits().add(new Hit("hasQuery", query));
return result;
}
use of com.yahoo.search.result.Hit in project vespa by vespa-engine.
the class FederationSearcher method mergeResult.
private void mergeResult(Query query, Target target, Result mergedResults, Result result) {
target.modifyTargetResult(result);
ComponentId searchChainId = target.getId();
Chain<Searcher> searchChain = target.getChain();
mergedResults.mergeWith(result);
HitGroup group = result.hits();
group.setId("source:" + searchChainId.getName());
group.setSearcherSpecificMetaData(this, searchChain);
// Set hit groups as non-meta as a default
group.setMeta(false);
// Set hit group as auxiliary so that it doesn't contribute to count
group.setAuxiliary(true);
group.setSource(searchChainId.getName());
group.setQuery(result.getQuery());
for (Iterator<Hit> it = group.unorderedDeepIterator(); it.hasNext(); ) {
Hit hit = it.next();
hit.setSearcherSpecificMetaData(this, searchChain);
hit.setSource(searchChainId.stringValue());
// See HTTPBackendSearcher, where this hit is created
if (hit.isMeta() && hit.types().contains("logging")) {
// Augment this hit with count fields
hit.setField(LOG_COUNT_PREFIX + "deep", result.getDeepHitCount());
hit.setField(LOG_COUNT_PREFIX + "total", result.getTotalHitCount());
int offset = result.getQuery().getOffset();
hit.setField(LOG_COUNT_PREFIX + "first", offset + 1);
hit.setField(LOG_COUNT_PREFIX + "last", result.getConcreteHitCount() + offset);
}
}
if (query.getTraceLevel() >= 4)
query.trace("Got " + group.getConcreteSize() + " hits from " + group.getId(), false, 4);
mergedResults.hits().add(group);
}
use of com.yahoo.search.result.Hit in project vespa by vespa-engine.
the class HTTPClientSearcher method search.
/**
* Implements a search towards the connection chosen by the cluster searcher for this query
*/
@Override
public Result search(Query query, Execution execution, Connection connection) {
Hit requestMeta = doHttpRequest(query, connection);
Result result = execution.search(query);
result.hits().add(requestMeta);
return result;
}
Aggregations