Search in sources :

Example 1 with SuggestionsDTO

use of org.graylog.plugins.views.search.rest.suggestions.SuggestionsDTO in project graylog2-server by Graylog2.

the class SuggestionsResource method suggestFieldValue.

@POST
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Suggest field value")
@NoAuditEvent("Only suggesting field value for query, not changing any data")
public SuggestionsDTO suggestFieldValue(@ApiParam(name = "validationRequest") SuggestionsRequestDTO suggestionsRequest, @Context SearchUser searchUser) {
    final SuggestionRequest req = SuggestionRequest.builder().field(suggestionsRequest.field()).input(suggestionsRequest.input()).streams(adaptStreams(suggestionsRequest.streams(), searchUser)).size(Math.min(suggestionsRequest.size(), SUGGESTIONS_COUNT_MAX)).timerange(Optional.ofNullable(suggestionsRequest.timerange()).orElse(defaultTimeRange())).build();
    SuggestionResponse res = querySuggestionsService.suggest(req);
    final List<SuggestionEntryDTO> suggestions = res.suggestions().stream().map(s -> SuggestionEntryDTO.create(s.getValue(), s.getOccurrence())).collect(Collectors.toList());
    final SuggestionsDTO.Builder suggestionsBuilder = SuggestionsDTO.builder(res.field(), res.input()).suggestions(suggestions).sumOtherDocsCount(res.sumOtherDocsCount());
    res.suggestionError().map(e -> SuggestionsErrorDTO.create(e.type(), e.reason())).ifPresent(suggestionsBuilder::error);
    return suggestionsBuilder.build();
}
Also used : InvalidRangeParametersException(org.graylog2.plugin.indexer.searches.timeranges.InvalidRangeParametersException) Produces(javax.ws.rs.Produces) SuggestionEntryDTO(org.graylog.plugins.views.search.rest.suggestions.SuggestionEntryDTO) SuggestionsDTO(org.graylog.plugins.views.search.rest.suggestions.SuggestionsDTO) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) RelativeRange(org.graylog2.plugin.indexer.searches.timeranges.RelativeRange) Inject(javax.inject.Inject) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) SuggestionsErrorDTO(org.graylog.plugins.views.search.rest.suggestions.SuggestionsErrorDTO) SuggestionsRequestDTO(org.graylog.plugins.views.search.rest.suggestions.SuggestionsRequestDTO) PluginRestResource(org.graylog2.plugin.rest.PluginRestResource) Api(io.swagger.annotations.Api) SuggestionResponse(org.graylog.plugins.views.search.engine.suggestions.SuggestionResponse) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent) ImmutableSet(com.google.common.collect.ImmutableSet) POST(javax.ws.rs.POST) Context(javax.ws.rs.core.Context) Set(java.util.Set) RestResource(org.graylog2.shared.rest.resources.RestResource) SuggestionRequest(org.graylog.plugins.views.search.engine.suggestions.SuggestionRequest) Collectors(java.util.stream.Collectors) List(java.util.List) QuerySuggestionsService(org.graylog.plugins.views.search.engine.QuerySuggestionsService) Optional(java.util.Optional) SearchUser(org.graylog.plugins.views.search.permissions.SearchUser) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication) SuggestionsDTO(org.graylog.plugins.views.search.rest.suggestions.SuggestionsDTO) SuggestionResponse(org.graylog.plugins.views.search.engine.suggestions.SuggestionResponse) SuggestionRequest(org.graylog.plugins.views.search.engine.suggestions.SuggestionRequest) SuggestionEntryDTO(org.graylog.plugins.views.search.rest.suggestions.SuggestionEntryDTO) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent)

Aggregations

ImmutableSet (com.google.common.collect.ImmutableSet)1 Api (io.swagger.annotations.Api)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiParam (io.swagger.annotations.ApiParam)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Context (javax.ws.rs.core.Context)1 MediaType (javax.ws.rs.core.MediaType)1 RequiresAuthentication (org.apache.shiro.authz.annotation.RequiresAuthentication)1 QuerySuggestionsService (org.graylog.plugins.views.search.engine.QuerySuggestionsService)1 SuggestionRequest (org.graylog.plugins.views.search.engine.suggestions.SuggestionRequest)1 SuggestionResponse (org.graylog.plugins.views.search.engine.suggestions.SuggestionResponse)1 SearchUser (org.graylog.plugins.views.search.permissions.SearchUser)1 SuggestionEntryDTO (org.graylog.plugins.views.search.rest.suggestions.SuggestionEntryDTO)1