Search in sources :

Example 1 with FetchRequest

use of io.zulia.message.ZuliaServiceOuterClass.FetchRequest in project zuliasearch by zuliaio.

the class FetchController method get.

@Get
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
public HttpResponse<?> get(@QueryValue(ZuliaConstants.ID) final String uniqueId, @QueryValue(ZuliaConstants.INDEX) final String indexName, @QueryValue(value = ZuliaConstants.PRETTY, defaultValue = "true") Boolean pretty) {
    ZuliaIndexManager indexManager = ZuliaNodeProvider.getZuliaNode().getIndexManager();
    FetchRequest.Builder fetchRequest = FetchRequest.newBuilder();
    fetchRequest.setIndexName(indexName);
    fetchRequest.setUniqueId(uniqueId);
    FetchResponse fetchResponse;
    try {
        fetchResponse = indexManager.fetch(fetchRequest.build());
        if (fetchResponse.hasResultDocument()) {
            Document document = ResultHelper.getDocumentFromResultDocument(fetchResponse.getResultDocument());
            if (document != null) {
                String docString;
                if (pretty) {
                    docString = document.toJson(JsonWriterSettings.builder().indent(true).build());
                } else {
                    docString = document.toJson();
                }
                if (pretty) {
                    docString = JsonWriter.formatJson(docString);
                }
                return HttpResponse.ok(docString).status(ZuliaConstants.SUCCESS);
            }
            return HttpResponse.ok("Failed to fetch uniqueId <" + uniqueId + "> for index <" + indexName + ">").status(ZuliaConstants.NOT_FOUND);
        } else {
            return HttpResponse.ok("Failed to fetch uniqueId <" + uniqueId + "> for index <" + indexName + ">").status(ZuliaConstants.NOT_FOUND);
        }
    } catch (Exception e) {
        return HttpResponse.serverError("Failed to fetch uniqueId <" + uniqueId + "> for index <" + indexName + ">: " + e.getMessage()).status(ZuliaConstants.INTERNAL_ERROR);
    }
}
Also used : ZuliaIndexManager(io.zulia.server.index.ZuliaIndexManager) FetchRequest(io.zulia.message.ZuliaServiceOuterClass.FetchRequest) FetchResponse(io.zulia.message.ZuliaServiceOuterClass.FetchResponse) Document(org.bson.Document) Produces(io.micronaut.http.annotation.Produces) Get(io.micronaut.http.annotation.Get)

Example 2 with FetchRequest

use of io.zulia.message.ZuliaServiceOuterClass.FetchRequest in project zuliasearch by zuliaio.

the class BatchFetchServerRequest method handleRequest.

public void handleRequest(BatchFetchRequest request, StreamObserver<FetchResponse> responseObserver) {
    try {
        for (FetchRequest fetchRequest : request.getFetchRequestList()) {
            FetchResponse fetchResponse = indexManager.fetch(fetchRequest);
            responseObserver.onNext(fetchResponse);
        }
        responseObserver.onCompleted();
    } catch (Exception e) {
        responseObserver.onError(e);
        onError(e);
    }
}
Also used : BatchFetchRequest(io.zulia.message.ZuliaServiceOuterClass.BatchFetchRequest) FetchRequest(io.zulia.message.ZuliaServiceOuterClass.FetchRequest) FetchResponse(io.zulia.message.ZuliaServiceOuterClass.FetchResponse)

Aggregations

FetchRequest (io.zulia.message.ZuliaServiceOuterClass.FetchRequest)2 FetchResponse (io.zulia.message.ZuliaServiceOuterClass.FetchResponse)2 Get (io.micronaut.http.annotation.Get)1 Produces (io.micronaut.http.annotation.Produces)1 BatchFetchRequest (io.zulia.message.ZuliaServiceOuterClass.BatchFetchRequest)1 ZuliaIndexManager (io.zulia.server.index.ZuliaIndexManager)1 Document (org.bson.Document)1