use of com.yahoo.search.result.ErrorMessage in project vespa by vespa-engine.
the class FederationSearcher method search.
@Override
public Result search(Query query, Execution execution) {
Result mergedResults = execution.search(query);
Results<SearchChainInvocationSpec, UnresolvedSearchChainException> targets = getTargets(query.getModel().getSources(), query.properties(), execution.context().getIndexFacts());
warnIfUnresolvedSearchChains(targets.errors(), mergedResults.hits());
Collection<SearchChainInvocationSpec> prunedTargets = pruneTargetsWithoutDocumentTypes(query.getModel().getRestrict(), targets.data());
Results<Target, ErrorMessage> regularTargetHandlers = resolveSearchChains(prunedTargets, execution.searchChainRegistry());
query.errors().addAll(regularTargetHandlers.errors());
Set<Target> targetHandlers = new LinkedHashSet<>(regularTargetHandlers.data());
targetHandlers.addAll(getAdditionalTargets(query, execution, targetSelector));
traceTargets(query, targetHandlers);
if (targetHandlers.isEmpty())
return mergedResults;
else if (targetHandlers.size() > 1)
search(query, execution, targetHandlers, mergedResults);
else if (shouldExecuteTargetLongerThanThread(query, targetHandlers.iterator().next()))
// one target, but search in separate thread
search(query, execution, targetHandlers, mergedResults);
else
// search in this thread
search(query, execution, first(targetHandlers), mergedResults);
return mergedResults;
}
use of com.yahoo.search.result.ErrorMessage in project vespa by vespa-engine.
the class FederationSearcher method addSearchChainTimedOutError.
private static void addSearchChainTimedOutError(Query query, ComponentId searchChainId) {
ErrorMessage timeoutMessage = ErrorMessage.createTimeout("The search chain '" + searchChainId + "' timed out.");
timeoutMessage.setSource(searchChainId.stringValue());
query.errors().add(timeoutMessage);
}
use of com.yahoo.search.result.ErrorMessage in project vespa by vespa-engine.
the class ResultBuilder method endElement.
@Override
public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
switch(location.peekFirst()) {
case HITGROUP:
if ("group".equals(qName)) {
hitGroups.removeFirst();
location.removeFirst();
}
break;
case HIT:
if (fieldLevel > 0) {
endElementInHitField(qName);
} else if ("hit".equals(qName)) {
// assert(hitKeys.size() == hitValues.size());
// We try to get either uri or documentID and use that as id
Object docId = extractDocumentID();
Hit newHit = new Hit(docId.toString());
if (hitRelevance != null)
newHit.setRelevance(new Relevance(DoubleParser.parse(hitRelevance)));
if (hitSource != null)
newHit.setSource(hitSource);
if (hitType != null) {
for (String type : hitType.split(" ")) {
newHit.types().add(type);
}
}
for (Map.Entry<String, Object> field : hitFields.entrySet()) {
newHit.setField(field.getKey(), field.getValue());
}
hitGroups.peekFirst().add(newHit);
location.removeFirst();
}
break;
case ERRORDETAILS:
if (fieldLevel == 1 && ERROR.equals(qName)) {
ErrorMessage error = new ErrorMessage(Integer.valueOf(currentErrorCode), currentError, fieldContent.toString());
hitGroups.peekFirst().addError(error);
currentError = null;
currentErrorCode = null;
fieldContent = null;
tagStack = null;
fieldLevel = 0;
} else if (fieldLevel > 0) {
endElementInField(qName, ERROR);
} else if ("errordetails".equals(qName)) {
location.removeFirst();
}
break;
case ROOT:
if (ERROR.equals(qName)) {
ErrorMessage error = new ErrorMessage(Integer.valueOf(currentErrorCode), fieldContent.toString());
hitGroups.peekFirst().addError(error);
currentErrorCode = null;
fieldContent = null;
}
break;
default:
break;
}
++offset;
}
use of com.yahoo.search.result.ErrorMessage in project vespa by vespa-engine.
the class RateLimitingSearcher method search.
@Override
public Result search(Query query, Execution execution) {
String id = query.properties().getString(idKey);
Double rate = query.properties().getDouble(quotaKey);
if (id == null || rate == null) {
query.trace(false, 6, "Skipping rate limiting check. Need both " + idKey + " and " + quotaKey + " set");
return execution.search(query);
}
rate = rate / nodeCount;
if (// new thread
allocatedCapacity.get() == null)
allocatedCapacity.set(new HashMap<>());
if (// new id in this thread
allocatedCapacity.get().get(id) == null)
requestCapacity(id, rate);
// no capacity means we're over rate. Only recheck occasionally to limit synchronization.
if (getAllocatedCapacity(id) <= 0 && ThreadLocalRandom.current().nextDouble() < recheckForCapacityProbability) {
requestCapacity(id, rate);
}
if (rate == 0 || getAllocatedCapacity(id) <= 0) {
// we are still over rate: reject
String idDim = query.properties().getString(idDimensionKey, null);
if (idDim == null) {
overQuotaCounter.add(1);
} else {
overQuotaCounter.add(1, createContext(idDim, id));
}
if (!query.properties().getBoolean(dryRunKey, false))
return new Result(query, new ErrorMessage(429, "Too many requests", "Allowed rate: " + rate + "/s"));
}
Result result = execution.search(query);
addAllocatedCapacity(id, -query.properties().getDouble(costKey, 1.0));
if (// make sure we ask for more with 100% probability when first running out
getAllocatedCapacity(id) <= 0)
requestCapacity(id, rate);
return result;
}
use of com.yahoo.search.result.ErrorMessage in project vespa by vespa-engine.
the class DocumentXMLTemplate method error.
@Override
public void error(Context context, Writer writer) throws IOException {
writer.write("<errors>\n");
// If the error contains no error hits, use a single error with the main
// code and description. Otherwise, use the error hits explicitly
ErrorHit errorHit = ((Result) context.get("result")).hits().getErrorHit();
if (errorHit == null || errorHit.errors().isEmpty()) {
ErrorMessage message = ((Result) context.get("result")).hits().getError();
writeGenericErrorMessage(writer, message);
} else {
for (ErrorMessage message : errorHit.errors()) {
writeGenericErrorMessage(writer, message);
}
}
writer.write("</errors>\n");
}
Aggregations