use of com.netflix.exhibitor.core.entities.SearchResult in project exhibitor by soabase.
the class IndexResource method getResult.
@Path("get/{index-name}/{doc-id}")
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getResult(@PathParam("index-name") String indexName, @PathParam("doc-id") int docId) throws Exception {
LogSearch logSearch = getLogSearch(indexName);
if (logSearch == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
SearchResult result;
try {
DateFormat dateFormatter = new SimpleDateFormat(DATE_FORMAT_STR);
SearchItem item = logSearch.toResult(docId);
if (item == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
byte[] bytes = logSearch.toData(docId);
if (bytes == null) {
bytes = new byte[0];
}
result = new SearchResult(docId, item.getType(), item.getPath(), dateFormatter.format(item.getDate()), new String(bytes, "UTF-8"), ExplorerResource.bytesToString(bytes));
} finally {
context.getExhibitor().getIndexCache().releaseLogSearch(logSearch.getFile());
}
return Response.ok(result).build();
}
Aggregations