Search in sources :

Example 1 with ErrorMessage

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

the class QueryValidatingSearcher method search.

public Result search(Query query, Execution execution) {
    if (query.getHits() > 1000) {
        Result result = new Result(query);
        ErrorMessage error = ErrorMessage.createInvalidQueryParameter("Too many hits (more than 1000) requested.");
        result.hits().addError(error);
        return result;
    }
    if (query.getOffset() > 1000) {
        Result result = new Result(query);
        ErrorMessage error = ErrorMessage.createInvalidQueryParameter("Offset too high (above 1000).");
        result.hits().addError(error);
        return result;
    }
    return execution.search(query);
}
Also used : ErrorMessage(com.yahoo.search.result.ErrorMessage) Result(com.yahoo.search.Result)

Example 2 with ErrorMessage

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

the class ValidatePredicateSearcher method search.

@Override
public Result search(Query query, Execution execution) {
    Optional<ErrorMessage> e = validate(query, execution.context().getIndexFacts().newSession(query));
    if (e.isPresent()) {
        Result r = new Result(query);
        r.hits().addError(e.get());
        return r;
    }
    return execution.search(query);
}
Also used : ErrorMessage(com.yahoo.search.result.ErrorMessage) Result(com.yahoo.search.Result)

Example 3 with ErrorMessage

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

the class ValidateSortingSearcher method search.

@Override
public Result search(Query query, Execution execution) {
    if (indexingMode != QrSearchersConfig.Searchcluster.Indexingmode.STREAMING) {
        ErrorMessage e = validate(query);
        if (e != null) {
            Result r = new Result(query);
            r.hits().addError(e);
            return r;
        }
    }
    return execution.search(query);
}
Also used : ErrorMessage(com.yahoo.search.result.ErrorMessage) Result(com.yahoo.search.Result)

Example 4 with ErrorMessage

use of com.yahoo.search.result.ErrorMessage 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 5 with ErrorMessage

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

the class BlendingSearcherTestCase method testExistingAndNonExistingBackendCausesBothErrorAndResult.

@Test
public void testExistingAndNonExistingBackendCausesBothErrorAndResult() {
    BlendingSearcherWrapper searcher = setupFirstAndSecond();
    Query query = new Query("/search?query=banana&search=first,nonesuch,second");
    Result result = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())).search(query);
    assertEquals(3, result.getConcreteHitCount());
    assertEquals(300.0, result.hits().get(1).getRelevance().getScore(), delta);
    assertEquals(200.0, result.hits().get(2).getRelevance().getScore(), delta);
    assertEquals(100.0, result.hits().get(3).getRelevance().getScore(), delta);
    assertNotNull(result.hits().getError());
    ErrorMessage e = result.hits().getError();
    // TODO: Do not depend on sources order
    assertEquals("Could not resolve source ref 'nonesuch'. Valid source refs are first, second.", e.getDetailedMessage());
}
Also used : Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) IndexFacts(com.yahoo.prelude.IndexFacts) ErrorMessage(com.yahoo.search.result.ErrorMessage) Result(com.yahoo.search.Result) Test(org.junit.Test)

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