Search in sources :

Example 11 with ErrorMessage

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) SourcesTarget(com.yahoo.search.federation.sourceref.SourcesTarget) FederationTarget(com.yahoo.search.federation.selection.FederationTarget) SingleTarget(com.yahoo.search.federation.sourceref.SingleTarget) UnresolvedSearchChainException(com.yahoo.search.federation.sourceref.UnresolvedSearchChainException) ErrorMessage(com.yahoo.search.result.ErrorMessage) SearchChainInvocationSpec(com.yahoo.search.federation.sourceref.SearchChainInvocationSpec) Result(com.yahoo.search.Result) FutureResult(com.yahoo.search.searchchain.FutureResult)

Example 12 with ErrorMessage

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);
}
Also used : ErrorMessage(com.yahoo.search.result.ErrorMessage)

Example 13 with ErrorMessage

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;
}
Also used : Relevance(com.yahoo.search.result.Relevance) Hit(com.yahoo.search.result.Hit) XMLString(com.yahoo.prelude.hitfield.XMLString) ErrorMessage(com.yahoo.search.result.ErrorMessage)

Example 14 with ErrorMessage

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;
}
Also used : HashMap(java.util.HashMap) ErrorMessage(com.yahoo.search.result.ErrorMessage) Result(com.yahoo.search.Result)

Example 15 with ErrorMessage

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");
}
Also used : ErrorHit(com.yahoo.search.result.ErrorHit) ErrorMessage(com.yahoo.search.result.ErrorMessage)

Aggregations

ErrorMessage (com.yahoo.search.result.ErrorMessage)23 Result (com.yahoo.search.Result)16 Query (com.yahoo.search.Query)10 Test (org.junit.Test)9 ErrorHit (com.yahoo.search.result.ErrorHit)4 IndexFacts (com.yahoo.prelude.IndexFacts)3 Execution (com.yahoo.search.searchchain.Execution)3 MockBackend (com.yahoo.prelude.fastsearch.test.fs4mock.MockBackend)2 Hit (com.yahoo.search.result.Hit)2 StringWriter (java.io.StringWriter)2 HashMap (java.util.HashMap)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 Metric (com.yahoo.jdisc.Metric)1 URI (com.yahoo.net.URI)1 DocumentdbInfoConfig (com.yahoo.prelude.fastsearch.DocumentdbInfoConfig)1 FastHit (com.yahoo.prelude.fastsearch.FastHit)1 GroupingListHit (com.yahoo.prelude.fastsearch.GroupingListHit)1 JSONString (com.yahoo.prelude.hitfield.JSONString)1 XMLString (com.yahoo.prelude.hitfield.XMLString)1 FederationTarget (com.yahoo.search.federation.selection.FederationTarget)1