Search in sources :

Example 1 with FullTextSearchResult

use of org.apache.atlas.v1.model.discovery.FullTextSearchResult in project atlas by apache.

the class MetadataDiscoveryResource method searchUsingFullText.

/**
 * Search using full text search.
 *
 * @param query search query.
 * @param limit number of rows to be returned in the result, used for pagination. maxlimit > limit > 0. -1 maps to atlas.search.defaultlimit property value
 * @param offset offset to the results returned, used for pagination. offset >= 0. -1 maps to offset 0
 * @return JSON representing the type and results.
 */
@GET
@Path("search/fulltext")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response searchUsingFullText(@QueryParam("query") String query, @DefaultValue(LIMIT_OFFSET_DEFAULT) @QueryParam("limit") int limit, @DefaultValue(LIMIT_OFFSET_DEFAULT) @QueryParam("offset") int offset) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> MetadataDiscoveryResource.searchUsingFullText({}, {}, {})", query, limit, offset);
    }
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "MetadataDiscoveryResource.searchUsingFullText(" + query + ", " + limit + ", " + offset + ")");
        }
        query = ParamChecker.notEmpty(query, "query cannot be null or empty");
        QueryParams queryParams = validateQueryParams(limit, offset);
        AtlasSearchResult result = atlasDiscoveryService.searchUsingFullTextQuery(query, false, queryParams.limit(), queryParams.offset());
        FullTextSearchResult fullTextResult = new FullTextSearchResult();
        fullTextResult.setQueryType(QUERY_TYPE_FULLTEXT);
        fullTextResult.setRequestId(Servlets.getRequestId());
        fullTextResult.setDataType(result.getType());
        fullTextResult.setQuery(result.getQueryText());
        fullTextResult.setCount(0);
        if (CollectionUtils.isNotEmpty(result.getFullTextResult())) {
            for (AtlasSearchResult.AtlasFullTextResult entity : result.getFullTextResult()) {
                fullTextResult.addResult(entity);
            }
            fullTextResult.setCount(fullTextResult.getResults().size());
        }
        String response = AtlasJson.toV1SearchJson(fullTextResult);
        return Response.ok(response).build();
    } catch (IllegalArgumentException e) {
        LOG.error("Unable to get entity list for query {}", query, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
    } catch (WebApplicationException e) {
        LOG.error("Unable to get entity list for query {}", query, e);
        throw e;
    } catch (Throwable e) {
        LOG.error("Unable to get entity list for query {}", query, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
    } finally {
        AtlasPerfTracer.log(perf);
        if (LOG.isDebugEnabled()) {
            LOG.debug("<== MetadataDiscoveryResource.searchUsingFullText({}, {}, {})", query, limit, offset);
        }
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) FullTextSearchResult(org.apache.atlas.v1.model.discovery.FullTextSearchResult) QueryParams(org.apache.atlas.query.QueryParams) AtlasSearchResult(org.apache.atlas.model.discovery.AtlasSearchResult) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 AtlasSearchResult (org.apache.atlas.model.discovery.AtlasSearchResult)1 QueryParams (org.apache.atlas.query.QueryParams)1 AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)1 FullTextSearchResult (org.apache.atlas.v1.model.discovery.FullTextSearchResult)1