use of org.graylog.plugins.views.search.SearchJob in project graylog2-server by Graylog2.
the class ElasticsearchBackend method generateFilterClause.
// TODO make pluggable
public Optional<QueryBuilder> generateFilterClause(Filter filter, SearchJob job, Query query) {
if (filter == null) {
return Optional.empty();
}
switch(filter.type()) {
case AndFilter.NAME:
final BoolQueryBuilder andBuilder = QueryBuilders.boolQuery();
filter.filters().stream().map(filter1 -> generateFilterClause(filter1, job, query)).forEach(optQueryBuilder -> optQueryBuilder.ifPresent(andBuilder::must));
return Optional.of(andBuilder);
case OrFilter.NAME:
final BoolQueryBuilder orBuilder = QueryBuilders.boolQuery();
// TODO for the common case "any of these streams" we can optimize the filter into
// a single "termsQuery" instead of "termQuery OR termQuery" if all direct children are "StreamFilter"
filter.filters().stream().map(filter1 -> generateFilterClause(filter1, job, query)).forEach(optQueryBuilder -> optQueryBuilder.ifPresent(orBuilder::should));
return Optional.of(orBuilder);
case StreamFilter.NAME:
// Skipping stream filter, will be extracted elsewhere
return Optional.empty();
case QueryStringFilter.NAME:
return Optional.of(QueryBuilders.queryStringQuery(this.queryStringDecorators.decorate(((QueryStringFilter) filter).query(), job, query)));
}
return Optional.empty();
}
use of org.graylog.plugins.views.search.SearchJob in project graylog2-server by Graylog2.
the class InMemorySearchJobService method create.
@Override
public SearchJob create(Search query, String owner) {
final String id = new ObjectId().toHexString();
final SearchJob searchJob = new SearchJob(id, query, owner);
cache.put(id, searchJob);
return searchJob;
}
use of org.graylog.plugins.views.search.SearchJob in project graylog2-server by Graylog2.
the class SearchResourceExecutionTest method mockExistingSearch.
private Search mockExistingSearch() {
final Search search = mockNewSearch();
final String searchId = "deadbeef";
when(search.id()).thenReturn(searchId);
when(search.applyExecutionState(any(), any())).thenReturn(search);
when(searchDomain.getForUser(eq(search.id()), any())).thenReturn(Optional.of(search));
final SearchJob searchJob = mocKSearchJob(search);
when(searchJobService.create(any(), any())).thenReturn(searchJob);
when(queryEngine.execute(any())).thenAnswer(invocation -> invocation.getArgument(0));
return search;
}
use of org.graylog.plugins.views.search.SearchJob in project graylog2-server by Graylog2.
the class SearchResourceExecutionTest method executeSyncJobAddsCurrentUserAsOwner.
@Test
public void executeSyncJobAddsCurrentUserAsOwner() {
mockCurrentUserName("peterchen");
final SearchDTO search = mockSearchDTO();
final SearchJob searchJob = mocKSearchJob(search.toSearch());
when(queryEngine.execute(any())).thenReturn(searchJob);
this.searchResource.executeSyncJob(search, 100, searchUser);
final ArgumentCaptor<String> usernameCaptor = ArgumentCaptor.forClass(String.class);
verify(searchJobService, times(1)).create(any(), usernameCaptor.capture());
assertThat(usernameCaptor.getValue()).isEqualTo("peterchen");
}
use of org.graylog.plugins.views.search.SearchJob in project graylog2-server by Graylog2.
the class SearchResourceExecutionTest method mocKSearchJob.
private SearchJob mocKSearchJob(Search search) {
final SearchJob searchJob = new SearchJob("deadbeef", search, "peterchen");
searchJob.addQueryResultFuture("query1", CompletableFuture.completedFuture(QueryResult.emptyResult()));
searchJob.seal();
return searchJob;
}
Aggregations