Search in sources :

Example 1 with ErrorHit

use of com.yahoo.search.result.ErrorHit in project vespa by vespa-engine.

the class ResultBuilderTestCase method testSimpleResult.

public void testSimpleResult() {
    boolean gotErrorDetails = false;
    ResultBuilder r = new ResultBuilder();
    Result res = r.parse("file:src/test/java/com/yahoo/prelude/searcher/test/testhit.xml", new Query("?query=a"));
    assertEquals(3, res.getConcreteHitCount());
    assertEquals(4, res.getHitCount());
    ErrorHit e = (ErrorHit) res.hits().get(0);
    // is no way of nuking an existing error if the details exist.
    for (Iterator<?> i = e.errorIterator(); i.hasNext(); ) {
        ErrorMessage err = (ErrorMessage) i.next();
        assertEquals(5, err.getCode());
        String details = err.getDetailedMessage();
        if (details != null) {
            gotErrorDetails = true;
            assertEquals("An error as ordered", details.trim());
        }
    }
    assertTrue("Error details are missing", gotErrorDetails);
    assertEquals(new URI("http://def"), res.hits().get(1).getId());
    assertEquals("test/stuff\\tsome/other", res.hits().get(2).getField("category"));
    assertEquals("<field>habla</field>" + "<hi>blbl</hi><br />&lt;&gt;&amp;fdlkkgj&lt;/field&gt;;lk<a b=\"1\" c=\"2\" />" + "<x><y><z /></y></x>", res.hits().get(3).getField("annoying").toString());
}
Also used : ResultBuilder(com.yahoo.search.federation.vespa.ResultBuilder) Query(com.yahoo.search.Query) ErrorHit(com.yahoo.search.result.ErrorHit) ErrorMessage(com.yahoo.search.result.ErrorMessage) URI(com.yahoo.net.URI) Result(com.yahoo.search.Result)

Example 2 with ErrorHit

use of com.yahoo.search.result.ErrorHit in project vespa by vespa-engine.

the class PosSearcherTestCase method testInvalidInput.

/**
 * Tests input parameters that should report errors.
 */
@Test
public void testInvalidInput() {
    PosSearcher searcher = new PosSearcher();
    Result result;
    Query q = new Query();
    q.properties().set("pos.ll", "NE74.14;E14.48");
    result = doSearch(searcher, q, 0, 10);
    assertEquals("Error in pos parameters: Unable to parse lat/long string 'NE74.14;E14.48': already set direction once, cannot add direction: E", ((ErrorHit) result.hits().get(0)).errors().iterator().next().getDetailedMessage());
    q = new Query();
    q.properties().set("pos.ll", "NE74.14;E14.48");
    q.properties().set("pos.xy", "82400, 72800");
    result = doSearch(searcher, q, 0, 10);
    assertEquals("Error in pos parameters: Cannot handle both lat/long and xy coords at the same time", ((ErrorHit) result.hits().get(0)).errors().iterator().next().getDetailedMessage());
}
Also used : Query(com.yahoo.search.Query) PosSearcher(com.yahoo.prelude.searcher.PosSearcher) ErrorHit(com.yahoo.search.result.ErrorHit) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 3 with ErrorHit

use of com.yahoo.search.result.ErrorHit in project vespa by vespa-engine.

the class JsonRenderer method renderHitGroupHead.

private void renderHitGroupHead(HitGroup hitGroup) throws IOException {
    generator.writeStartObject();
    renderHitContents(hitGroup);
    if (getRecursionLevel() == 1)
        renderCoverage();
    ErrorHit errorHit = hitGroup.getErrorHit();
    if (errorHit != null)
        renderErrors(errorHit.errors());
// the framework will invoke begin methods as needed from here
}
Also used : ErrorHit(com.yahoo.search.result.ErrorHit) DefaultErrorHit(com.yahoo.search.result.DefaultErrorHit)

Example 4 with ErrorHit

use of com.yahoo.search.result.ErrorHit in project vespa by vespa-engine.

the class StatisticsSearcher method incrementStatePageOnlyErrors.

/**
 * Creates error metric for StateHandler only. These metrics are only exposed on /state/v1/metrics page
 * and not forwarded to the log file.
 *
 * @param result The result to check for errors
 */
private void incrementStatePageOnlyErrors(Result result) {
    if (result == null)
        return;
    ErrorHit error = result.hits().getErrorHit();
    if (error == null)
        return;
    for (ErrorMessage m : error.errors()) {
        int code = m.getCode();
        Metric.Context c = getDimensions(m.getSource());
        if (code == TIMEOUT.code) {
            metric.add("error.timeout", 1, c);
        } else if (code == NO_BACKENDS_IN_SERVICE.code) {
            metric.add("error.backends_oos", 1, c);
        } else if (code == ERROR_IN_PLUGIN.code) {
            metric.add("error.plugin_failure", 1, c);
        } else if (code == BACKEND_COMMUNICATION_ERROR.code) {
            metric.add("error.backend_communication_error", 1, c);
        } else if (code == EMPTY_DOCUMENTS.code) {
            metric.add("error.empty_document_summaries", 1, c);
        } else if (code == ILLEGAL_QUERY.code) {
            metric.add("error.illegal_query", 1, c);
        } else if (code == INVALID_QUERY_PARAMETER.code) {
            metric.add("error.invalid_query_parameter", 1, c);
        } else if (code == INTERNAL_SERVER_ERROR.code) {
            metric.add("error.internal_server_error", 1, c);
        } else if (code == SERVER_IS_MISCONFIGURED.code) {
            metric.add("error.misconfigured_server", 1, c);
        } else if (code == INVALID_QUERY_TRANSFORMATION.code) {
            metric.add("error.invalid_query_transformation", 1, c);
        } else if (code == RESULT_HAS_ERRORS.code) {
            metric.add("error.result_with_errors", 1, c);
        } else if (code == UNSPECIFIED.code) {
            metric.add("error.unspecified", 1, c);
        }
    }
}
Also used : ErrorHit(com.yahoo.search.result.ErrorHit) Metric(com.yahoo.jdisc.Metric) ErrorMessage(com.yahoo.search.result.ErrorMessage)

Example 5 with ErrorHit

use of com.yahoo.search.result.ErrorHit 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

ErrorHit (com.yahoo.search.result.ErrorHit)7 ErrorMessage (com.yahoo.search.result.ErrorMessage)4 Query (com.yahoo.search.Query)3 Result (com.yahoo.search.Result)3 Test (org.junit.Test)3 DefaultErrorHit (com.yahoo.search.result.DefaultErrorHit)2 Metric (com.yahoo.jdisc.Metric)1 URI (com.yahoo.net.URI)1 FastHit (com.yahoo.prelude.fastsearch.FastHit)1 PosSearcher (com.yahoo.prelude.searcher.PosSearcher)1 ResultBuilder (com.yahoo.search.federation.vespa.ResultBuilder)1 XMLWriter (com.yahoo.text.XMLWriter)1 StringWriter (java.io.StringWriter)1