Search in sources :

Example 1 with DocumentId

use of com.yahoo.document.DocumentId in project vespa by vespa-engine.

the class GroupingExecutorTestCase method requireThatHitsAreFilledWithCorrectSummary.

@Test
public void requireThatHitsAreFilledWithCorrectSummary() {
    Query query = newQuery();
    GroupingRequest req = GroupingRequest.newInstance(query);
    req.setRootOperation(GroupingOperation.fromString("all(group(foo) each(each(output(summary(bar))) as(bar) " + "                    each(output(summary(baz))) as(baz)))"));
    Grouping pass0A = new Grouping(0);
    pass0A.setRoot(new com.yahoo.searchlib.aggregation.Group().addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("foo")).addAggregationResult(new HitsAggregationResult(1, "bar"))));
    Grouping pass0B = new Grouping(1);
    pass0B.setRoot(new com.yahoo.searchlib.aggregation.Group().addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("foo")).addAggregationResult(new HitsAggregationResult(1, "baz"))));
    GlobalId gid1 = new GlobalId((new DocumentId("doc:test:1")).getGlobalId());
    GlobalId gid2 = new GlobalId((new DocumentId("doc:test:2")).getGlobalId());
    Grouping pass1A = new Grouping(0);
    pass1A.setRoot(new com.yahoo.searchlib.aggregation.Group().addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("foo")).addAggregationResult(new HitsAggregationResult(1, "bar").addHit(new com.yahoo.searchlib.aggregation.FS4Hit(1, gid1, 3)))));
    Grouping pass1B = new Grouping(1);
    pass1B.setRoot(new com.yahoo.searchlib.aggregation.Group().addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("foo")).addAggregationResult(new HitsAggregationResult(1, "baz").addHit(new com.yahoo.searchlib.aggregation.FS4Hit(4, gid2, 6)))));
    SummaryMapper sm = new SummaryMapper();
    Execution exec = newExecution(new GroupingExecutor(), new ResultProvider(Arrays.asList(new GroupingListHit(Arrays.asList(pass0A, pass0B), null), new GroupingListHit(Arrays.asList(pass1A, pass1B), null))), sm);
    exec.fill(exec.search(query), "default");
    assertEquals(2, sm.hitsBySummary.size());
    List<Hit> lst = sm.hitsBySummary.get("bar");
    assertNotNull(lst);
    assertEquals(1, lst.size());
    Hit hit = lst.get(0);
    assertTrue(hit instanceof FastHit);
    assertEquals(1, ((FastHit) hit).getPartId());
    assertEquals(gid1, ((FastHit) hit).getGlobalId());
    assertNotNull(lst = sm.hitsBySummary.get("baz"));
    assertNotNull(lst);
    assertEquals(1, lst.size());
    hit = lst.get(0);
    assertTrue(hit instanceof FastHit);
    assertEquals(4, ((FastHit) hit).getPartId());
    assertEquals(gid2, ((FastHit) hit).getGlobalId());
}
Also used : Group(com.yahoo.search.grouping.result.Group) Query(com.yahoo.search.Query) DocumentId(com.yahoo.document.DocumentId) Grouping(com.yahoo.searchlib.aggregation.Grouping) GlobalId(com.yahoo.document.GlobalId) GroupingListHit(com.yahoo.prelude.fastsearch.GroupingListHit) HitsAggregationResult(com.yahoo.searchlib.aggregation.HitsAggregationResult) GroupingListHit(com.yahoo.prelude.fastsearch.GroupingListHit) FastHit(com.yahoo.prelude.fastsearch.FastHit) Hit(com.yahoo.search.result.Hit) Execution(com.yahoo.search.searchchain.Execution) FastHit(com.yahoo.prelude.fastsearch.FastHit) GroupingRequest(com.yahoo.search.grouping.GroupingRequest) StringResultNode(com.yahoo.searchlib.expression.StringResultNode) Test(org.junit.Test)

Example 2 with DocumentId

use of com.yahoo.document.DocumentId in project vespa by vespa-engine.

the class GroupingExecutorTestCase method requireThatHitsAreAttachedToCorrectQuery.

@Test
public void requireThatHitsAreAttachedToCorrectQuery() {
    Query queryA = newQuery();
    GroupingRequest req = GroupingRequest.newInstance(queryA);
    req.setRootOperation(GroupingOperation.fromString("all(group(foo) each(each(output(summary(bar)))))"));
    Grouping grp = new Grouping(0);
    grp.setRoot(new com.yahoo.searchlib.aggregation.Group().addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("foo")).addAggregationResult(new HitsAggregationResult(1, "bar"))));
    GroupingListHit pass0 = new GroupingListHit(Arrays.asList(grp), null);
    GlobalId gid = new GlobalId((new DocumentId("doc:test:1")).getGlobalId());
    grp = new Grouping(0);
    grp.setRoot(new com.yahoo.searchlib.aggregation.Group().addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("foo")).addAggregationResult(new HitsAggregationResult(1, "bar").addHit(new com.yahoo.searchlib.aggregation.FS4Hit(4, gid, 6)))));
    GroupingListHit pass1 = new GroupingListHit(Arrays.asList(grp), null);
    Query queryB = newQuery();
    /**
     * required by {@link GroupingListHit#getSearchQuery()}
     */
    pass1.setQuery(queryB);
    QueryMapper qm = new QueryMapper();
    Execution exec = newExecution(new GroupingExecutor(), new ResultProvider(Arrays.asList(pass0, pass1)), qm);
    exec.fill(exec.search(queryA));
    assertEquals(1, qm.hitsByQuery.size());
    assertTrue(qm.hitsByQuery.containsKey(queryB));
}
Also used : Group(com.yahoo.search.grouping.result.Group) Query(com.yahoo.search.Query) DocumentId(com.yahoo.document.DocumentId) Grouping(com.yahoo.searchlib.aggregation.Grouping) GroupingListHit(com.yahoo.prelude.fastsearch.GroupingListHit) GlobalId(com.yahoo.document.GlobalId) HitsAggregationResult(com.yahoo.searchlib.aggregation.HitsAggregationResult) Execution(com.yahoo.search.searchchain.Execution) GroupingRequest(com.yahoo.search.grouping.GroupingRequest) StringResultNode(com.yahoo.searchlib.expression.StringResultNode) Test(org.junit.Test)

Example 3 with DocumentId

use of com.yahoo.document.DocumentId in project vespa by vespa-engine.

the class OperationHandlerImpl method get.

@Override
public Optional<String> get(RestUri restUri, Optional<String> fieldSet) throws RestApiException {
    SyncSession syncSession = syncSessions.alloc();
    setRoute(syncSession, Optional.empty());
    try {
        DocumentId id = new DocumentId(restUri.generateFullId());
        final Document document = syncSession.get(id, fieldSet.orElse(restUri.getDocumentType() + ":[document]"), DocumentProtocol.Priority.NORMAL_1);
        if (document == null) {
            return Optional.empty();
        }
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        JsonWriter jsonWriter = new JsonWriter(outputStream);
        jsonWriter.write(document);
        return Optional.of(outputStream.toString(StandardCharsets.UTF_8.name()));
    } catch (Exception e) {
        throw new RestApiException(Response.createErrorResponse(500, ExceptionUtils.getStackTrace(e), restUri, RestUri.apiErrorCodes.UNSPECIFIED));
    } finally {
        syncSessions.free(syncSession);
    }
}
Also used : DocumentId(com.yahoo.document.DocumentId) SyncSession(com.yahoo.documentapi.SyncSession) MessageBusSyncSession(com.yahoo.documentapi.messagebus.MessageBusSyncSession) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(com.yahoo.document.Document) JsonWriter(com.yahoo.document.json.JsonWriter) DocumentAccessException(com.yahoo.documentapi.DocumentAccessException)

Example 4 with DocumentId

use of com.yahoo.document.DocumentId in project vespa by vespa-engine.

the class OperationHandlerImpl method delete.

@Override
public void delete(RestUri restUri, String condition, Optional<String> route) throws RestApiException {
    SyncSession syncSession = syncSessions.alloc();
    Response response;
    try {
        Instant startTime = Instant.now();
        DocumentId id = new DocumentId(restUri.generateFullId());
        DocumentRemove documentRemove = new DocumentRemove(id);
        setRoute(syncSession, route);
        if (condition != null && !condition.isEmpty()) {
            documentRemove.setCondition(new TestAndSetCondition(condition));
        }
        syncSession.remove(documentRemove);
        metricsHelper.reportSuccessful(DocumentOperationType.REMOVE, startTime);
        return;
    } catch (DocumentAccessException documentException) {
        if (documentException.hasConditionNotMetError()) {
            response = Response.createErrorResponse(412, "Condition not met: " + documentException.getMessage(), restUri, RestUri.apiErrorCodes.DOCUMENT_CONDITION_NOT_MET);
        } else {
            response = Response.createErrorResponse(400, documentException.getMessage(), restUri, RestUri.apiErrorCodes.DOCUMENT_EXCPETION);
        }
    } catch (Exception e) {
        response = Response.createErrorResponse(500, ExceptionUtils.getStackTrace(e), restUri, RestUri.apiErrorCodes.UNSPECIFIED);
    } finally {
        syncSessions.free(syncSession);
    }
    metricsHelper.reportFailure(DocumentOperationType.REMOVE, DocumentOperationStatus.fromHttpStatusCode(response.getStatus()));
    throw new RestApiException(response);
}
Also used : DocumentRemove(com.yahoo.document.DocumentRemove) Instant(java.time.Instant) DocumentId(com.yahoo.document.DocumentId) SyncSession(com.yahoo.documentapi.SyncSession) MessageBusSyncSession(com.yahoo.documentapi.messagebus.MessageBusSyncSession) TestAndSetCondition(com.yahoo.document.TestAndSetCondition) DocumentAccessException(com.yahoo.documentapi.DocumentAccessException) DocumentAccessException(com.yahoo.documentapi.DocumentAccessException)

Example 5 with DocumentId

use of com.yahoo.document.DocumentId in project vespa by vespa-engine.

the class MockReader method read.

@Override
public void read(Operation operation) throws Exception {
    if (finished) {
        return;
    }
    byte whatToDo = stream.getNextOperation();
    DocumentId id = new DocumentId("id:banana:banana::doc1");
    DocumentType docType = new DocumentType("banana");
    switch(whatToDo) {
        case 0:
            finished = true;
            break;
        case 1:
            Document doc = new Document(docType, id);
            operation.setDocument(doc);
            break;
        case 2:
            operation.setRemove(id);
            break;
        case 3:
            operation.setDocumentUpdate(new DocumentUpdate(docType, id));
            break;
        case 4:
            throw new RuntimeException("boom");
    }
}
Also used : DocumentUpdate(com.yahoo.document.DocumentUpdate) DocumentId(com.yahoo.document.DocumentId) DocumentType(com.yahoo.document.DocumentType) Document(com.yahoo.document.Document)

Aggregations

DocumentId (com.yahoo.document.DocumentId)61 Test (org.junit.Test)28 DocumentType (com.yahoo.document.DocumentType)20 Document (com.yahoo.document.Document)16 DocumentPut (com.yahoo.document.DocumentPut)12 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)9 BucketId (com.yahoo.document.BucketId)7 DocumentRemove (com.yahoo.document.DocumentRemove)5 DocumentUpdate (com.yahoo.document.DocumentUpdate)5 BucketIdFactory (com.yahoo.document.BucketIdFactory)4 FieldUpdate (com.yahoo.document.update.FieldUpdate)4 DocumentOperation (com.yahoo.document.DocumentOperation)3 FastHit (com.yahoo.prelude.fastsearch.FastHit)3 Hit (com.yahoo.search.result.Hit)3 HashMap (java.util.HashMap)3 TestDocumentProcessor1 (com.yahoo.docproc.DocumentProcessingAbstractTestCase.TestDocumentProcessor1)2 Field (com.yahoo.document.Field)2 GlobalId (com.yahoo.document.GlobalId)2 StructDataType (com.yahoo.document.StructDataType)2 Struct (com.yahoo.document.datatypes.Struct)2