Search in sources :

Example 6 with Index

use of net.yacy.grid.io.index.Index in project yacy_grid_mcp by yacy.

the class ExistService method serviceImpl.

@Override
public ServiceResponse serviceImpl(Query call, HttpServletResponse response) {
    // String indexName, String typeName, final String id, JSONObject object
    String indexName = call.get("index", "");
    String typeName = call.get("type", "");
    if (typeName.length() == 0)
        typeName = null;
    String id = call.get("id", "");
    JSONObject json = new JSONObject(true);
    if (indexName.length() > 0 && id.length() > 0) {
        try {
            Index index = Data.gridIndex.getElasticIndex();
            String url = index.checkConnection().getConnectionURL();
            boolean exists = index.exist(indexName, typeName, id);
            json.put(ObjectAPIHandler.SUCCESS_KEY, true);
            json.put("exists", exists);
            if (url != null)
                json.put(ObjectAPIHandler.SERVICE_KEY, url);
        } catch (IOException e) {
            json.put(ObjectAPIHandler.SUCCESS_KEY, false);
            json.put(ObjectAPIHandler.COMMENT_KEY, e.getMessage());
        }
    } else {
        json.put(ObjectAPIHandler.SUCCESS_KEY, false);
        json.put(ObjectAPIHandler.COMMENT_KEY, "the request must contain an index, type, and an id");
    }
    return new ServiceResponse(json);
}
Also used : ServiceResponse(net.yacy.grid.http.ServiceResponse) JSONObject(org.json.JSONObject) Index(net.yacy.grid.io.index.Index) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)6 ServiceResponse (net.yacy.grid.http.ServiceResponse)6 Index (net.yacy.grid.io.index.Index)6 JSONObject (org.json.JSONObject)6 QueryLanguage (net.yacy.grid.io.index.Index.QueryLanguage)3 IndexFactory (net.yacy.grid.io.index.IndexFactory)2 JSONList (net.yacy.grid.tools.JSONList)1 JSONException (org.json.JSONException)1 JSONTokener (org.json.JSONTokener)1