Search in sources :

Example 1 with GetFieldNamesResponse

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

the class FieldsController method get.

@Get
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
public HttpResponse<?> get(@QueryValue(ZuliaConstants.INDEX) final String indexName, @QueryValue(value = ZuliaConstants.PRETTY, defaultValue = "true") Boolean pretty) {
    ZuliaIndexManager indexManager = ZuliaNodeProvider.getZuliaNode().getIndexManager();
    GetFieldNamesRequest fieldNamesRequest = GetFieldNamesRequest.newBuilder().setIndexName(indexName).build();
    GetFieldNamesResponse fieldNamesResponse;
    try {
        fieldNamesResponse = indexManager.getFieldNames(fieldNamesRequest);
        Document mongoDocument = new Document();
        mongoDocument.put("index", indexName);
        mongoDocument.put("fields", fieldNamesResponse.getFieldNameList());
        String docString = mongoDocument.toJson();
        if (pretty) {
            docString = JsonWriter.formatJson(docString);
        }
        return HttpResponse.ok(docString).status(ZuliaConstants.SUCCESS);
    } catch (Exception e) {
        return HttpResponse.ok("Failed to fetch fields for index <" + indexName + ">: " + e.getMessage()).status(ZuliaConstants.INTERNAL_ERROR);
    }
}
Also used : GetFieldNamesRequest(io.zulia.message.ZuliaServiceOuterClass.GetFieldNamesRequest) ZuliaIndexManager(io.zulia.server.index.ZuliaIndexManager) GetFieldNamesResponse(io.zulia.message.ZuliaServiceOuterClass.GetFieldNamesResponse) Document(org.bson.Document) Produces(io.micronaut.http.annotation.Produces) Get(io.micronaut.http.annotation.Get)

Example 2 with GetFieldNamesResponse

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

the class GetFieldNamesRequestFederator method getResponse.

public GetFieldNamesResponse getResponse(GetFieldNamesRequest request) throws Exception {
    Set<String> fieldNames = new TreeSet<>();
    List<GetFieldNamesResponse> responses = send(request);
    for (GetFieldNamesResponse response : responses) {
        fieldNames.addAll(response.getFieldNameList());
    }
    GetFieldNamesResponse.Builder responseBuilder = GetFieldNamesResponse.newBuilder();
    responseBuilder.addAllFieldName(fieldNames);
    return responseBuilder.build();
}
Also used : TreeSet(java.util.TreeSet) GetFieldNamesResponse(io.zulia.message.ZuliaServiceOuterClass.GetFieldNamesResponse)

Aggregations

GetFieldNamesResponse (io.zulia.message.ZuliaServiceOuterClass.GetFieldNamesResponse)2 Get (io.micronaut.http.annotation.Get)1 Produces (io.micronaut.http.annotation.Produces)1 GetFieldNamesRequest (io.zulia.message.ZuliaServiceOuterClass.GetFieldNamesRequest)1 ZuliaIndexManager (io.zulia.server.index.ZuliaIndexManager)1 TreeSet (java.util.TreeSet)1 Document (org.bson.Document)1