Search in sources :

Example 1 with QueryParser

use of org.opennms.newts.api.search.query.QueryParser in project newts by OpenNMS.

the class SearchResource method search.

@GET
@Timed
public Collection<SearchResultDTO> search(@QueryParam("q") Optional<String> query, @QueryParam("context") Optional<String> contextId) {
    checkArgument(query.isPresent(), "missing required query parameter (q=<argument>)");
    QueryParser qp = new QueryParser();
    Query parsedQuery;
    try {
        parsedQuery = qp.parse(query.get());
    } catch (ParseException e) {
        throw new WebApplicationException(e, Response.status(Status.BAD_REQUEST).entity("Invalid query " + query.get()).build());
    }
    Context context = contextId.isPresent() ? new Context(contextId.get()) : Context.DEFAULT_CONTEXT;
    return Transform.searchResultDTOs(m_searcher.search(context, parsedQuery));
}
Also used : Context(org.opennms.newts.api.Context) QueryParser(org.opennms.newts.api.search.query.QueryParser) Query(org.opennms.newts.api.search.Query) WebApplicationException(javax.ws.rs.WebApplicationException) ParseException(org.opennms.newts.api.search.query.ParseException) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Aggregations

Timed (com.codahale.metrics.annotation.Timed)1 GET (javax.ws.rs.GET)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Context (org.opennms.newts.api.Context)1 Query (org.opennms.newts.api.search.Query)1 ParseException (org.opennms.newts.api.search.query.ParseException)1 QueryParser (org.opennms.newts.api.search.query.QueryParser)1