Search in sources :

Example 1 with ParameterProvider

use of org.graylog.plugins.views.search.ParameterProvider in project graylog2-server by Graylog2.

the class QueryValidationServiceImpl method decoratedQuery.

private String decoratedQuery(ValidationRequest req) {
    ParameterProvider parameterProvider = (name) -> req.parameters().stream().filter(p -> Objects.equals(p.name(), name)).findFirst();
    final Query query = Query.builder().query(req.query()).timerange(req.timerange()).build();
    return this.queryStringDecorators.decorate(req.getCombinedQueryWithFilter(), parameterProvider, query);
}
Also used : ParseException(org.apache.lucene.queryparser.classic.ParseException) Query(org.graylog.plugins.views.search.Query) Set(java.util.Set) ParameterProvider(org.graylog.plugins.views.search.ParameterProvider) MappedFieldTypesService(org.graylog2.indexer.fieldtypes.MappedFieldTypesService) Streams(com.google.common.collect.Streams) Singleton(javax.inject.Singleton) StringUtils(org.apache.commons.lang3.StringUtils) SearchException(org.graylog.plugins.views.search.errors.SearchException) Collectors(java.util.stream.Collectors) UnboundParameterError(org.graylog.plugins.views.search.errors.UnboundParameterError) Inject(javax.inject.Inject) Objects(java.util.Objects) List(java.util.List) QueryStringDecorators(org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators) Stream(java.util.stream.Stream) MappedFieldTypeDTO(org.graylog.plugins.views.search.rest.MappedFieldTypeDTO) Locale(java.util.Locale) Collections(java.util.Collections) ParameterProvider(org.graylog.plugins.views.search.ParameterProvider) Query(org.graylog.plugins.views.search.Query)

Example 2 with ParameterProvider

use of org.graylog.plugins.views.search.ParameterProvider in project graylog2-server by Graylog2.

the class ESMessageListTest method appliesDecoratorsToQueryStringIfHighlightingActivated.

@Test
public void appliesDecoratorsToQueryStringIfHighlightingActivated() {
    final QueryStringDecorator queryStringDecorator = (String queryString, ParameterProvider job, Query query) -> "Foobar!";
    final MessageList messageList = someMessageList();
    ESGeneratedQueryContext queryContext = generateQueryPartWithHighlighting(messageList, Collections.singleton(queryStringDecorator));
    final DocumentContext doc = JsonPath.parse(queryContext.searchSourceBuilder(messageList).toString());
    JsonPathAssert.assertThat(doc).jsonPathAsString("$.highlight.highlight_query.query_string.query").isEqualTo("Foobar!");
}
Also used : ParameterProvider(org.graylog.plugins.views.search.ParameterProvider) Query(org.graylog.plugins.views.search.Query) ElasticsearchQueryString(org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString) ESGeneratedQueryContext(org.graylog.storage.elasticsearch6.views.ESGeneratedQueryContext) DocumentContext(com.jayway.jsonpath.DocumentContext) MessageList(org.graylog.plugins.views.search.searchtypes.MessageList) QueryStringDecorator(org.graylog.plugins.views.search.engine.QueryStringDecorator) Test(org.junit.Test)

Example 3 with ParameterProvider

use of org.graylog.plugins.views.search.ParameterProvider in project graylog2-server by Graylog2.

the class ESMessageListTest method appliesDecoratorsToQueryStringIfHighlightingActivated.

@Test
public void appliesDecoratorsToQueryStringIfHighlightingActivated() {
    final QueryStringDecorator queryStringDecorator = (String queryString, ParameterProvider job, Query query) -> "Foobar!";
    final MessageList messageList = someMessageList();
    ESGeneratedQueryContext queryContext = generateQueryPartWithHighlighting(messageList, Collections.singleton(queryStringDecorator));
    final DocumentContext doc = JsonPath.parse(queryContext.searchSourceBuilder(messageList).toString());
    JsonPathAssert.assertThat(doc).jsonPathAsString("$.highlight.highlight_query.query_string.query").isEqualTo("Foobar!");
}
Also used : ParameterProvider(org.graylog.plugins.views.search.ParameterProvider) Query(org.graylog.plugins.views.search.Query) ElasticsearchQueryString(org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString) ESGeneratedQueryContext(org.graylog.storage.elasticsearch7.views.ESGeneratedQueryContext) DocumentContext(com.jayway.jsonpath.DocumentContext) MessageList(org.graylog.plugins.views.search.searchtypes.MessageList) QueryStringDecorator(org.graylog.plugins.views.search.engine.QueryStringDecorator) Test(org.junit.Test)

Aggregations

ParameterProvider (org.graylog.plugins.views.search.ParameterProvider)3 Query (org.graylog.plugins.views.search.Query)3 DocumentContext (com.jayway.jsonpath.DocumentContext)2 ElasticsearchQueryString (org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString)2 QueryStringDecorator (org.graylog.plugins.views.search.engine.QueryStringDecorator)2 MessageList (org.graylog.plugins.views.search.searchtypes.MessageList)2 Test (org.junit.Test)2 Streams (com.google.common.collect.Streams)1 Collections (java.util.Collections)1 List (java.util.List)1 Locale (java.util.Locale)1 Objects (java.util.Objects)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Inject (javax.inject.Inject)1 Singleton (javax.inject.Singleton)1 StringUtils (org.apache.commons.lang3.StringUtils)1 ParseException (org.apache.lucene.queryparser.classic.ParseException)1 QueryStringDecorators (org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators)1