Search in sources :

Example 1 with CachedSearch

use of com.netflix.exhibitor.core.index.CachedSearch in project exhibitor by soabase.

the class IndexResource method getDataTableData.

@Path("dataTable/{index-name}/{search-handle}")
@GET
@Produces(MediaType.APPLICATION_JSON)
public String getDataTableData(@PathParam("index-name") String indexName, @PathParam("search-handle") String searchHandle, @QueryParam("iDisplayStart") int iDisplayStart, @QueryParam("iDisplayLength") int iDisplayLength, @QueryParam("sEcho") String sEcho) throws Exception {
    LogSearch logSearch = getLogSearch(indexName);
    if (logSearch == null) {
        return "{}";
    }
    ObjectNode node;
    try {
        CachedSearch cachedSearch = logSearch.getCachedSearch(searchHandle);
        DateFormat dateFormatter = new SimpleDateFormat(DATE_FORMAT_STR);
        ArrayNode dataTab = JsonNodeFactory.instance.arrayNode();
        for (int i = iDisplayStart; i < (iDisplayStart + iDisplayLength); ++i) {
            if (i < cachedSearch.getTotalHits()) {
                ObjectNode data = JsonNodeFactory.instance.objectNode();
                int docId = cachedSearch.getNthDocId(i);
                SearchItem item = logSearch.toResult(docId);
                data.put("DT_RowId", "index-query-result-" + docId);
                data.put("0", getTypeName(EntryTypes.getFromId(item.getType())));
                data.put("1", dateFormatter.format(item.getDate()));
                data.put("2", trimPath(item.getPath()));
                dataTab.add(data);
            }
        }
        node = JsonNodeFactory.instance.objectNode();
        node.put("sEcho", sEcho);
        node.put("iTotalRecords", logSearch.getDocQty());
        node.put("iTotalDisplayRecords", cachedSearch.getTotalHits());
        node.put("aaData", dataTab);
    } finally {
        context.getExhibitor().getIndexCache().releaseLogSearch(logSearch.getFile());
    }
    return node.toString();
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) CachedSearch(com.netflix.exhibitor.core.index.CachedSearch) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) LogSearch(com.netflix.exhibitor.core.index.LogSearch) ArrayNode(org.codehaus.jackson.node.ArrayNode) 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

CachedSearch (com.netflix.exhibitor.core.index.CachedSearch)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 ArrayNode (org.codehaus.jackson.node.ArrayNode)1 ObjectNode (org.codehaus.jackson.node.ObjectNode)1