Search in sources :

Example 1 with SearchResult

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();
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) LogSearch(com.netflix.exhibitor.core.index.LogSearch) SearchResult(com.netflix.exhibitor.core.entities.SearchResult) SimpleDateFormat(java.text.SimpleDateFormat) SearchItem(com.netflix.exhibitor.core.index.SearchItem) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

SearchResult (com.netflix.exhibitor.core.entities.SearchResult)1 LogSearch (com.netflix.exhibitor.core.index.LogSearch)1 SearchItem (com.netflix.exhibitor.core.index.SearchItem)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1