use of net.yacy.grid.io.index.Index.QueryLanguage in project yacy_grid_mcp by yacy.
the class CountService 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;
QueryLanguage language = QueryLanguage.valueOf(call.get("language", "yacy"));
String query = call.get("query", "");
JSONObject json = new JSONObject(true);
if (indexName.length() > 0 && query.length() > 0) {
try {
Index index = Data.gridIndex.getElasticIndex();
String url = index.checkConnection().getConnectionURL();
long count = index.count(indexName, typeName, language, query);
json.put(ObjectAPIHandler.SUCCESS_KEY, true);
json.put("count", count);
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 a query");
}
return new ServiceResponse(json);
}
use of net.yacy.grid.io.index.Index.QueryLanguage in project yacy_grid_mcp by yacy.
the class QueryService 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", "");
QueryLanguage language = QueryLanguage.valueOf(call.get("language", "yacy"));
String query = call.get("query", "");
int maximumRecords = call.get("maximumRecords", call.get("rows", call.get("num", 10)));
int startRecord = call.get("startRecord", call.get("start", 0));
JSONObject json = new JSONObject(true);
if (indexName.length() > 0 && id.length() > 0) {
try {
Index index = Data.gridIndex.getElasticIndex();
String url = index.checkConnection().getConnectionURL();
JSONObject object = index.query(indexName, typeName, id);
json.put(ObjectAPIHandler.SUCCESS_KEY, true);
JSONList list = new JSONList();
if (object != null)
list.add(object);
json.put("count", list.length());
json.put("list", list.toArray());
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 if (indexName.length() > 0 && query.length() > 0) {
try {
Index index = Data.gridIndex.getElasticIndex();
String url = index.checkConnection().getConnectionURL();
JSONList list = index.query(indexName, typeName, language, query, startRecord, maximumRecords);
json.put(ObjectAPIHandler.SUCCESS_KEY, true);
json.put("count", list.length());
json.put("list", list.toArray());
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 either an id or a query");
}
return new ServiceResponse(json);
}
use of net.yacy.grid.io.index.Index.QueryLanguage in project yacy_grid_mcp by yacy.
the class DeleteService method serviceImpl.
@Override
public ServiceResponse serviceImpl(Query call, HttpServletResponse response) {
// String indexName, String typeName, final String id, JSONObject object
String indexName = call.get("index", "");
// should not be null
String typeName = call.get("type", "");
String id = call.get("id", "");
QueryLanguage language = QueryLanguage.valueOf(call.get("language", "yacy"));
String query = call.get("query", "");
JSONObject json = new JSONObject(true);
if (indexName.length() > 0 && typeName.length() > 0 && id.length() > 0) {
try {
Index index = Data.gridIndex.getElasticIndex();
String url = index.checkConnection().getConnectionURL();
boolean deleted = index.delete(indexName, typeName, id);
json.put(ObjectAPIHandler.SUCCESS_KEY, true);
json.put("deleted", deleted);
json.put("count", deleted ? 1 : 0);
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 if (indexName.length() > 0 && typeName.length() > 0 && query.length() > 0) {
try {
Index index = Data.gridIndex.getElasticIndex();
String url = index.checkConnection().getConnectionURL();
long count = index.delete(indexName, typeName, language, query);
json.put(ObjectAPIHandler.SUCCESS_KEY, true);
json.put("count", count);
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 either an id or a query");
}
return new ServiceResponse(json);
}
Aggregations