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();
}
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();
}
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);
}
}
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;
}
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();
}
Aggregations