Search in sources :

Example 1 with VisitorSession

use of com.yahoo.documentapi.VisitorSession in project vespa by vespa-engine.

the class OperationHandlerImpl method visit.

@Override
public VisitResult visit(RestUri restUri, String documentSelection, VisitOptions options) throws RestApiException {
    VisitorParameters visitorParameters = createVisitorParameters(restUri, documentSelection, options);
    VisitorControlHandler visitorControlHandler = new VisitorControlHandler();
    visitorParameters.setControlHandler(visitorControlHandler);
    LocalDataVisitorHandler localDataVisitorHandler = new LocalDataVisitorHandler();
    visitorParameters.setLocalDataHandler(localDataVisitorHandler);
    final VisitorSession visitorSession;
    try {
        visitorSession = documentAccess.createVisitorSession(visitorParameters);
        // Not sure if this line is required
        visitorControlHandler.setSession(visitorSession);
    } catch (Exception e) {
        throw new RestApiException(Response.createErrorResponse(500, "Failed during parsing of arguments for visiting: " + ExceptionUtils.getStackTrace(e), restUri, RestUri.apiErrorCodes.VISITOR_ERROR));
    }
    try {
        return doVisit(visitorControlHandler, localDataVisitorHandler, restUri);
    } finally {
        visitorSession.destroy();
    }
}
Also used : VisitorSession(com.yahoo.documentapi.VisitorSession) VisitorParameters(com.yahoo.documentapi.VisitorParameters) VisitorControlHandler(com.yahoo.documentapi.VisitorControlHandler) DocumentAccessException(com.yahoo.documentapi.DocumentAccessException)

Example 2 with VisitorSession

use of com.yahoo.documentapi.VisitorSession in project vespa by vespa-engine.

the class VdsVisitor method doSearch.

@Override
public void doSearch() throws InterruptedException, ParseException, TimeoutException {
    VisitorSession session = visitorSessionFactory.createVisitorSession(params);
    try {
        if (!session.waitUntilDone(query.getTimeout())) {
            log.log(LogLevel.DEBUG, "Visitor returned from waitUntilDone without being completed for " + query + " with selection " + params.getDocumentSelection());
            session.abort();
            throw new TimeoutException("Query timed out in " + VdsStreamingSearcher.class.getName());
        }
    } finally {
        session.destroy();
        log.log(LogLevel.DEBUG, () -> session.getTrace().toString());
    }
    query.trace(session.getTrace().toString(), false, 9);
    if (params.getControlHandler().getResult().code == VisitorControlHandler.CompletionCode.SUCCESS) {
        if (log.isLoggable(LogLevel.DEBUG)) {
            log.log(LogLevel.DEBUG, "VdsVisitor completed successfully for " + query + " with selection " + params.getDocumentSelection());
        }
    } else {
        throw new IllegalArgumentException(// TODO: Is it necessary to use a runtime exception?
        "Query failed: " + params.getControlHandler().getResult().code + ": " + params.getControlHandler().getResult().message);
    }
}
Also used : VisitorSession(com.yahoo.documentapi.VisitorSession) TimeoutException(com.yahoo.prelude.fastsearch.TimeoutException)

Example 3 with VisitorSession

use of com.yahoo.documentapi.VisitorSession in project vespa by vespa-engine.

the class VisitorSearcherTestCase method waitUntilDoneFailureReturnsTimeoutErrorHit.

@Test
public void waitUntilDoneFailureReturnsTimeoutErrorHit() throws Exception {
    VisitorSession session = mock(VisitorSession.class);
    when(session.waitUntilDone(anyLong())).thenReturn(false);
    factory = mock(DocumentSessionFactory.class);
    when(factory.createVisitorSession(any(VisitorParameters.class))).thenReturn(session);
    Result result = invokeSearcherWithUserQuery();
    assertNotNull(result.hits().getErrorHit());
    assertEquals(Error.TIMEOUT.code, result.hits().getErrorHit().errors().iterator().next().getCode());
}
Also used : VisitorSession(com.yahoo.documentapi.VisitorSession) VisitorParameters(com.yahoo.documentapi.VisitorParameters) Result(com.yahoo.search.Result) Test(org.junit.Test)

Aggregations

VisitorSession (com.yahoo.documentapi.VisitorSession)3 VisitorParameters (com.yahoo.documentapi.VisitorParameters)2 DocumentAccessException (com.yahoo.documentapi.DocumentAccessException)1 VisitorControlHandler (com.yahoo.documentapi.VisitorControlHandler)1 TimeoutException (com.yahoo.prelude.fastsearch.TimeoutException)1 Result (com.yahoo.search.Result)1 Test (org.junit.Test)1