Search in sources :

Example 1 with QueryStringDecorator

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

the class ElasticsearchBackendQueryStringDecoratorsTest method setUp.

@BeforeEach
void setUp() {
    final QueryStringDecorator decorator = (queryString, job, query) -> "decorated";
    final Set<QueryStringDecorator> decorators = Collections.singleton(decorator);
    final FieldTypesLookup fieldTypesLookup = mock(FieldTypesLookup.class);
    this.backend = new ElasticsearchBackend(Collections.emptyMap(), mock(ElasticsearchClient.class), mock(IndexLookup.class), new QueryStringDecorators(decorators), (elasticsearchBackend, ssb, job, query) -> new ESGeneratedQueryContext(elasticsearchBackend, ssb, job, query, fieldTypesLookup), true);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) ElasticsearchClient(org.graylog.storage.elasticsearch7.ElasticsearchClient) InvalidRangeParametersException(org.graylog2.plugin.indexer.searches.timeranges.InvalidRangeParametersException) Query(org.graylog.plugins.views.search.Query) RelativeRange(org.graylog2.plugin.indexer.searches.timeranges.RelativeRange) ElasticsearchQueryString(org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString) QueryStringDecorator(org.graylog.plugins.views.search.engine.QueryStringDecorator) SearchType(org.graylog.plugins.views.search.SearchType) FieldTypesLookup(org.graylog.plugins.views.search.elasticsearch.FieldTypesLookup) Search(org.graylog.plugins.views.search.Search) Nonnull(javax.annotation.Nonnull) JsonPathAssert.assertThat(com.revinate.assertj.json.JsonPathAssert.assertThat) Period(org.joda.time.Period) SearchJob(org.graylog.plugins.views.search.SearchJob) ImmutableSet(com.google.common.collect.ImmutableSet) SearchConfig(org.graylog.plugins.views.search.engine.SearchConfig) Set(java.util.Set) Mockito.when(org.mockito.Mockito.when) JsonPath(com.jayway.jsonpath.JsonPath) Test(org.junit.jupiter.api.Test) QueryStringDecorators(org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators) DocumentContext(com.jayway.jsonpath.DocumentContext) Optional(java.util.Optional) IndexLookup(org.graylog.plugins.views.search.elasticsearch.IndexLookup) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) QueryStringDecorators(org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators) FieldTypesLookup(org.graylog.plugins.views.search.elasticsearch.FieldTypesLookup) QueryStringDecorator(org.graylog.plugins.views.search.engine.QueryStringDecorator) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with QueryStringDecorator

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

the class ElasticsearchBackendQueryStringDecoratorsTest method setUp.

@BeforeEach
void setUp() {
    final QueryStringDecorator decorator = (queryString, job, query) -> "decorated";
    final Set<QueryStringDecorator> decorators = Collections.singleton(decorator);
    final FieldTypesLookup fieldTypesLookup = mock(FieldTypesLookup.class);
    this.backend = new ElasticsearchBackend(Collections.emptyMap(), mock(JestClient.class), mock(IndexLookup.class), new QueryStringDecorators(decorators), (elasticsearchBackend, ssb, job, query) -> new ESGeneratedQueryContext(elasticsearchBackend, ssb, job, query, fieldTypesLookup), true, new ObjectMapperProvider().get());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) InvalidRangeParametersException(org.graylog2.plugin.indexer.searches.timeranges.InvalidRangeParametersException) Query(org.graylog.plugins.views.search.Query) RelativeRange(org.graylog2.plugin.indexer.searches.timeranges.RelativeRange) JestClient(io.searchbox.client.JestClient) ElasticsearchQueryString(org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString) QueryStringDecorator(org.graylog.plugins.views.search.engine.QueryStringDecorator) SearchType(org.graylog.plugins.views.search.SearchType) FieldTypesLookup(org.graylog.plugins.views.search.elasticsearch.FieldTypesLookup) Search(org.graylog.plugins.views.search.Search) Nonnull(javax.annotation.Nonnull) JsonPathAssert.assertThat(com.revinate.assertj.json.JsonPathAssert.assertThat) Period(org.joda.time.Period) SearchJob(org.graylog.plugins.views.search.SearchJob) ImmutableSet(com.google.common.collect.ImmutableSet) SearchConfig(org.graylog.plugins.views.search.engine.SearchConfig) ObjectMapperProvider(org.graylog2.shared.bindings.providers.ObjectMapperProvider) Set(java.util.Set) Mockito.when(org.mockito.Mockito.when) JsonPath(com.jayway.jsonpath.JsonPath) Test(org.junit.jupiter.api.Test) QueryStringDecorators(org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators) DocumentContext(com.jayway.jsonpath.DocumentContext) Optional(java.util.Optional) IndexLookup(org.graylog.plugins.views.search.elasticsearch.IndexLookup) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) QueryStringDecorators(org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators) FieldTypesLookup(org.graylog.plugins.views.search.elasticsearch.FieldTypesLookup) QueryStringDecorator(org.graylog.plugins.views.search.engine.QueryStringDecorator) ObjectMapperProvider(org.graylog2.shared.bindings.providers.ObjectMapperProvider) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with QueryStringDecorator

use of org.graylog.plugins.views.search.engine.QueryStringDecorator 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 4 with QueryStringDecorator

use of org.graylog.plugins.views.search.engine.QueryStringDecorator 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

DocumentContext (com.jayway.jsonpath.DocumentContext)4 Query (org.graylog.plugins.views.search.Query)4 ElasticsearchQueryString (org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString)4 QueryStringDecorator (org.graylog.plugins.views.search.engine.QueryStringDecorator)4 ImmutableSet (com.google.common.collect.ImmutableSet)2 JsonPath (com.jayway.jsonpath.JsonPath)2 JsonPathAssert.assertThat (com.revinate.assertj.json.JsonPathAssert.assertThat)2 Collections (java.util.Collections)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Nonnull (javax.annotation.Nonnull)2 ParameterProvider (org.graylog.plugins.views.search.ParameterProvider)2 Search (org.graylog.plugins.views.search.Search)2 SearchJob (org.graylog.plugins.views.search.SearchJob)2 SearchType (org.graylog.plugins.views.search.SearchType)2 FieldTypesLookup (org.graylog.plugins.views.search.elasticsearch.FieldTypesLookup)2 IndexLookup (org.graylog.plugins.views.search.elasticsearch.IndexLookup)2 QueryStringDecorators (org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators)2 SearchConfig (org.graylog.plugins.views.search.engine.SearchConfig)2 MessageList (org.graylog.plugins.views.search.searchtypes.MessageList)2