use of com.yahoo.search.Result in project vespa by vespa-engine.
the class TiledTemplateSet method header.
@Override
public void header(Context context, XMLWriter writer) throws IOException {
Result result = (Result) context.get("result");
writer.xmlHeader(getRequestedEncoding(result.getQuery()));
writer.openTag("result").attribute("version", "1.0");
writer.attribute("layout", result.hits().getField("layout"));
renderCoverageAttributes(result.getCoverage(false), writer);
writer.closeStartTag();
renderSectionContent(result.hits(), writer);
}
use of com.yahoo.search.Result in project vespa by vespa-engine.
the class ClusterSearcher method search.
@Override
public final Result search(Query query, Execution execution) {
int tries = 0;
Hasher.NodeList<T> nodes = getHasher().getNodes();
if (nodes.getNodeCount() == 0)
return search(query, execution, ErrorMessage.createNoBackendsInService("No nodes in service in " + this + " (" + monitor.nodeMonitors().size() + " was configured, none is responding)"));
int code = query.hashCode();
Result result;
T connection = getFirstConnection(nodes, code, tries, query);
do {
// The loop is in case there are other searchers available able to produce results
if (connection == null)
return search(query, execution, ErrorMessage.createNoBackendsInService("No in node could handle " + query + " according to " + hasher + " in " + this));
if (timedOut(query))
return new Result(query, ErrorMessage.createTimeout("No time left for searching"));
if (query.getTraceLevel() >= 8)
query.trace("Trying " + connection, false, 8);
result = robustSearch(query, execution, connection);
if (!shouldRetry(query, result))
return result;
if (query.getTraceLevel() >= 6)
query.trace("Error from connection " + connection + " : " + result.hits().getError(), false, 6);
if (result.hits().getError().getCode() == Error.TIMEOUT.code)
// Retry is unlikely to help
return result;
log(LogLevel.FINER, "No result, checking for timeout.");
tries++;
connection = nodes.select(code, tries);
} while (tries < nodes.getNodeCount());
// only error result gets returned here.
return result;
}
use of com.yahoo.search.Result in project vespa by vespa-engine.
the class ResultBuilder method startDocument.
@Override
public void startDocument() throws SAXException {
reset();
result = new Result(query);
hitGroups.addFirst(result.hits());
location.addFirst(ResultPart.ROOT);
return;
}
use of com.yahoo.search.Result in project vespa by vespa-engine.
the class UniqueGroupingSearcher method dedupe.
/**
* Until we can use the grouping pagination features in 5.1, we'll have to support offset
* by simply requesting and discarding hit #0 up to hit #offset.
*/
private static Result dedupe(Query query, Execution execution, String dedupField) {
Sorting sorting = query.getRanking().getSorting();
if (sorting != null && sorting.fieldOrders().size() > 1) {
query.trace("Can not use grouping for deduping with multi-level sorting.", 3);
// we'd ever want to actually use it (and a bit harder to implement as well).
return execution.search(query);
}
int hits = query.getHits();
int offset = query.getOffset();
int groupingHits = hits + offset;
GroupingRequest groupingRequest = GroupingRequest.newInstance(query);
groupingRequest.setRootOperation(buildGroupingExpression(dedupField, groupingHits, query.getPresentation().getSummary(), sorting));
query.setHits(0);
query.setOffset(0);
Result result = execution.search(query);
// query could have changed further down in the chain
query = result.getQuery();
query.setHits(hits);
query.setOffset(offset);
Group root = groupingRequest.getResultGroup(result);
if (null == root) {
String msg = "Result group not found for deduping grouping request, returning empty result.";
query.trace(msg, 3);
log.log(LogLevel.WARNING, msg);
throw new IllegalStateException("Failed to produce deduped result set.");
}
// hide our tracks
result.hits().remove(root.getId().toString());
GroupList resultGroups = root.getGroupList(dedupField);
if (resultGroups == null) {
query.trace("Deduping grouping request returned no hits, returning empty result.", 3);
return result;
}
// Make sure that .addAll() doesn't re-order the hits we copy from the grouping
// framework. The groups are already in the order they should be.
result.hits().setOrderer(NOP_ORDERER);
result.hits().addAll(getRequestedHits(resultGroups, offset, hits));
Long countField = (Long) root.getField(LABEL_COUNT);
long count = countField != null ? countField : 0;
result.setTotalHitCount(count);
return result;
}
use of com.yahoo.search.Result in project vespa by vespa-engine.
the class PageTemplateSet method header.
@Override
public void header(Context context, XMLWriter writer) throws IOException {
Result result = (Result) context.get("result");
writer.xmlHeader(getRequestedEncoding(result.getQuery()));
writer.openTag("page").attribute("version", "1.0").attribute("layout", result.hits().getField("layout"));
renderCoverageAttributes(result.getCoverage(false), writer);
writer.closeStartTag();
renderSectionContent(result.hits(), writer);
}
Aggregations