All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.blackbirdai.client.UploadClient Maven / Gradle / Ivy

package com.blackbirdai.client;

import com.blackbirdai.client.model.DeleteRequest;
import com.blackbirdai.client.model.UploadRequest;
import com.blackbirdai.client.model.UploadResponse;
import com.twitter.util.Await;

/**
 * Blocking client for blackbird search.
 */
public class UploadClient {

    private final AsyncUploadClient asyncClient;

    /**
     * Constructor for UploadClient.
     * @param host Address of Blackbird search endpoint.
     * @param user User name for your Blackbird account.
     * @param token Authentication token for upload. Available on admin page.
     * @param instanceId Id of search instance.
     */
    public UploadClient(String host, String user, String token, String instanceId) {
        this.asyncClient = new AsyncUploadClient(host, user, token, instanceId);
    }

    /**
     * Add documents.
     */
    public UploadResponse add(UploadRequest request) {
        try {
            return Await.result(asyncClient.add(request));
        } catch (Throwable t) {
            return new UploadResponse(false, "Request failed: " + t.getMessage());
        }
    }

    /**
     * Update documents.
     */
    public UploadResponse update(UploadRequest request) {
        try {
            return Await.result(asyncClient.update(request));
        } catch (Throwable t) {
            return new UploadResponse(false, "Request failed: " + t.getMessage());
        }
    }

    /**
     * Upsert documents.
     */
    public UploadResponse upsert(UploadRequest request) {
        try {
            return Await.result(asyncClient.upsert(request));
        } catch (Throwable t) {
            return new UploadResponse(false, "Request failed: " + t.getMessage());
        }
    }

    /**
     * Delete documents.
     */
    public UploadResponse delete(DeleteRequest request) {
        try {
            return Await.result(asyncClient.delete(request));
        } catch (Throwable t) {
            return new UploadResponse(false, "Request failed: " + t.getMessage());
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy