Search in sources :

Example 1 with LogSearch

use of com.netflix.exhibitor.core.index.LogSearch 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)

Example 2 with LogSearch

use of com.netflix.exhibitor.core.index.LogSearch 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)

Example 3 with LogSearch

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

the class IndexResource method cacheSearch.

@Path("cache-search")
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response cacheSearch(SearchRequest request) throws Exception {
    LogSearch logSearch = getLogSearch(request.getIndexName());
    if (logSearch == null) {
        return Response.status(Response.Status.NOT_FOUND).build();
    }
    SearchId searchHandle;
    try {
        boolean hasTerms = false;
        QueryBuilder builder = QueryBuilder.builder();
        if ((request.getPathPrefix() != null) && (request.getPathPrefix().length() > 0)) {
            hasTerms = true;
            builder.pathPrefix(request.getPathPrefix());
        }
        if (request.getOperationType() >= 0) {
            hasTerms = true;
            builder.operationType(request.getOperationType());
        }
        if ((request.getFirstDate() != null) && (request.getSecondDate() != null)) {
            hasTerms = true;
            Date startDate;
            Date endDate;
            if (request.getFirstDate().before(request.getSecondDate())) {
                startDate = request.getFirstDate();
                endDate = request.getSecondDate();
            } else {
                startDate = request.getSecondDate();
                endDate = request.getFirstDate();
            }
            Calendar endOfDayEndDate = Calendar.getInstance();
            endOfDayEndDate.setTime(endDate);
            endOfDayEndDate.set(Calendar.HOUR_OF_DAY, 23);
            endOfDayEndDate.set(Calendar.MINUTE, 59);
            endOfDayEndDate.set(Calendar.SECOND, 59);
            endDate = endOfDayEndDate.getTime();
            builder.dateRange(startDate, endDate);
        }
        Query query = hasTerms ? builder.build(QueryBuilder.Type.AND) : null;
        String id = logSearch.cacheSearch(query, request.getReuseHandle(), request.getMaxResults());
        searchHandle = new SearchId(id);
    } finally {
        context.getExhibitor().getIndexCache().releaseLogSearch(logSearch.getFile());
    }
    return Response.ok(searchHandle).build();
}
Also used : SearchId(com.netflix.exhibitor.core.entities.SearchId) Query(org.apache.lucene.search.Query) Calendar(java.util.Calendar) LogSearch(com.netflix.exhibitor.core.index.LogSearch) QueryBuilder(com.netflix.exhibitor.core.index.QueryBuilder) Date(java.util.Date) NameAndModifiedDate(com.netflix.exhibitor.core.entities.NameAndModifiedDate) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Aggregations

LogSearch (com.netflix.exhibitor.core.index.LogSearch)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 SearchItem (com.netflix.exhibitor.core.index.SearchItem)2 DateFormat (java.text.DateFormat)2 SimpleDateFormat (java.text.SimpleDateFormat)2 GET (javax.ws.rs.GET)2 NameAndModifiedDate (com.netflix.exhibitor.core.entities.NameAndModifiedDate)1 SearchId (com.netflix.exhibitor.core.entities.SearchId)1 SearchResult (com.netflix.exhibitor.core.entities.SearchResult)1 CachedSearch (com.netflix.exhibitor.core.index.CachedSearch)1 QueryBuilder (com.netflix.exhibitor.core.index.QueryBuilder)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Query (org.apache.lucene.search.Query)1 ArrayNode (org.codehaus.jackson.node.ArrayNode)1 ObjectNode (org.codehaus.jackson.node.ObjectNode)1