Search in sources :

Example 1 with AssociatedDocument

use of io.zulia.message.ZuliaBase.AssociatedDocument in project zuliasearch by zuliaio.

the class ZuliaIndex method internalStore.

public StoreResponse internalStore(StoreRequest storeRequest) throws Exception {
    long timestamp = System.currentTimeMillis();
    String uniqueId = storeRequest.getUniqueId();
    if (storeRequest.hasResultDocument()) {
        ResultDocument resultDocument = storeRequest.getResultDocument();
        Document document;
        if (!resultDocument.getDocument().isEmpty()) {
            document = ZuliaUtil.byteArrayToMongoDocument(resultDocument.getDocument().toByteArray());
        } else {
            document = new Document();
        }
        Document metadata;
        if (!resultDocument.getMetadata().isEmpty()) {
            metadata = ZuliaUtil.byteArrayToMongoDocument(resultDocument.getMetadata().toByteArray());
        } else {
            metadata = new Document();
        }
        ZuliaShard s = findShardFromUniqueId(uniqueId);
        s.index(uniqueId, timestamp, document, metadata);
    }
    if (storeRequest.getClearExistingAssociated()) {
        documentStorage.deleteAssociatedDocuments(uniqueId);
    }
    for (AssociatedDocument ad : storeRequest.getAssociatedDocumentList()) {
        ad = AssociatedDocument.newBuilder(ad).setTimestamp(timestamp).build();
        documentStorage.storeAssociatedDocument(ad);
    }
    return StoreResponse.newBuilder().build();
}
Also used : AssociatedDocument(io.zulia.message.ZuliaBase.AssociatedDocument) ResultDocument(io.zulia.message.ZuliaBase.ResultDocument) Document(org.bson.Document) AssociatedDocument(io.zulia.message.ZuliaBase.AssociatedDocument) ResultDocument(io.zulia.message.ZuliaBase.ResultDocument)

Example 2 with AssociatedDocument

use of io.zulia.message.ZuliaBase.AssociatedDocument in project zuliasearch by zuliaio.

the class ZuliaIndex method fetch.

public ZuliaServiceOuterClass.FetchResponse fetch(ZuliaServiceOuterClass.FetchRequest fetchRequest) throws Exception {
    ZuliaServiceOuterClass.FetchResponse.Builder frBuilder = ZuliaServiceOuterClass.FetchResponse.newBuilder();
    String uniqueId = fetchRequest.getUniqueId();
    FetchType resultFetchType = fetchRequest.getResultFetchType();
    if (!FetchType.NONE.equals(resultFetchType)) {
        ZuliaBase.ResultDocument resultDoc = getSourceDocument(uniqueId, resultFetchType, fetchRequest.getDocumentFieldsList(), fetchRequest.getDocumentMaskedFieldsList());
        if (null != resultDoc) {
            frBuilder.setResultDocument(resultDoc);
        }
    }
    FetchType associatedFetchType = fetchRequest.getAssociatedFetchType();
    if (!FetchType.NONE.equals(associatedFetchType)) {
        if (!fetchRequest.getFilename().isEmpty()) {
            AssociatedDocument ad = getAssociatedDocument(uniqueId, fetchRequest.getFilename(), associatedFetchType);
            if (ad != null) {
                frBuilder.addAssociatedDocument(ad);
            }
        } else {
            for (AssociatedDocument ad : getAssociatedDocuments(uniqueId, associatedFetchType)) {
                frBuilder.addAssociatedDocument(ad);
            }
        }
    }
    return frBuilder.build();
}
Also used : AssociatedDocument(io.zulia.message.ZuliaBase.AssociatedDocument) FetchType(io.zulia.message.ZuliaQuery.FetchType) ZuliaBase(io.zulia.message.ZuliaBase) ResultDocument(io.zulia.message.ZuliaBase.ResultDocument)

Example 3 with AssociatedDocument

use of io.zulia.message.ZuliaBase.AssociatedDocument in project zuliasearch by zuliaio.

the class MongoDocumentStorage method storeAssociatedDocument.

@Override
public void storeAssociatedDocument(AssociatedDocument doc) throws Exception {
    byte[] bytes = doc.getDocument().toByteArray();
    Document metadata;
    if (!doc.getMetadata().isEmpty()) {
        metadata = ZuliaUtil.byteArrayToMongoDocument(doc.getMetadata().toByteArray());
    } else {
        metadata = new Document();
    }
    try (OutputStream outputStream = getAssociatedDocumentOutputStream(doc.getDocumentUniqueId(), doc.getFilename(), doc.getTimestamp(), metadata)) {
        outputStream.write(bytes);
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) Document(org.bson.Document) AssociatedDocument(io.zulia.message.ZuliaBase.AssociatedDocument)

Example 4 with AssociatedDocument

use of io.zulia.message.ZuliaBase.AssociatedDocument in project zuliasearch by zuliaio.

the class S3DocumentStorage method parseAssociated.

private Document parseAssociated(AssociatedDocument doc, Long length) {
    Document metadata;
    if (!doc.getMetadata().isEmpty()) {
        metadata = ZuliaUtil.byteArrayToMongoDocument(doc.getMetadata().toByteArray());
    } else {
        metadata = new Document();
    }
    metadata.put(TIMESTAMP, doc.getTimestamp());
    metadata.put(FILE_UNIQUE_ID_KEY, String.join("-", doc.getDocumentUniqueId(), doc.getFilename()));
    metadata.put(DOCUMENT_UNIQUE_ID_KEY, doc.getDocumentUniqueId());
    Document TOC = new Document();
    TOC.put("metadata", metadata);
    TOC.put(FILENAME, doc.getFilename());
    TOC.put("length", length);
    TOC.put("uploadDate", Instant.now());
    return TOC;
}
Also used : Document(org.bson.Document) AssociatedDocument(io.zulia.message.ZuliaBase.AssociatedDocument)

Example 5 with AssociatedDocument

use of io.zulia.message.ZuliaBase.AssociatedDocument in project zuliasearch by zuliaio.

the class S3DocumentStorage method parseTOC.

private AssociatedDocument parseTOC(Document doc) throws IOException {
    AssociatedDocument.Builder aBuilder = AssociatedDocument.newBuilder();
    aBuilder.setFilename(doc.getString(FILENAME));
    Document meta = doc.get("metadata", Document.class);
    aBuilder.setDocumentUniqueId(meta.getString(DOCUMENT_UNIQUE_ID_KEY));
    aBuilder.setTimestamp(meta.getLong(TIMESTAMP));
    aBuilder.setIndexName(indexName);
    meta.remove(TIMESTAMP);
    meta.remove(DOCUMENT_UNIQUE_ID_KEY);
    meta.remove(FILE_UNIQUE_ID_KEY);
    aBuilder.setMetadata(ZuliaUtil.mongoDocumentToByteString(meta));
    Document s3Info = doc.get("s3", Document.class);
    GetObjectRequest gor = GetObjectRequest.builder().bucket(s3Info.getString("bucket")).key(s3Info.getString("key")).build();
    ResponseInputStream<GetObjectResponse> results = s3.getObject(gor);
    aBuilder.setDocument(ByteString.readFrom(results));
    return aBuilder.build();
}
Also used : AssociatedDocument(io.zulia.message.ZuliaBase.AssociatedDocument) GetObjectResponse(software.amazon.awssdk.services.s3.model.GetObjectResponse) Document(org.bson.Document) AssociatedDocument(io.zulia.message.ZuliaBase.AssociatedDocument) GetObjectRequest(software.amazon.awssdk.services.s3.model.GetObjectRequest)

Aggregations

AssociatedDocument (io.zulia.message.ZuliaBase.AssociatedDocument)13 Document (org.bson.Document)11 ByteString (com.google.protobuf.ByteString)5 ArrayList (java.util.ArrayList)3 ResultDocument (io.zulia.message.ZuliaBase.ResultDocument)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 GridFSBucket (com.mongodb.client.gridfs.GridFSBucket)1 GridFSFindIterable (com.mongodb.client.gridfs.GridFSFindIterable)1 GridFSFile (com.mongodb.client.gridfs.model.GridFSFile)1 ZuliaBase (io.zulia.message.ZuliaBase)1 FetchType (io.zulia.message.ZuliaQuery.FetchType)1 OutputStream (java.io.OutputStream)1 Path (java.nio.file.Path)1 GetObjectRequest (software.amazon.awssdk.services.s3.model.GetObjectRequest)1 GetObjectResponse (software.amazon.awssdk.services.s3.model.GetObjectResponse)1 PutObjectRequest (software.amazon.awssdk.services.s3.model.PutObjectRequest)1